Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help very very badly

Status
Not open for further replies.

ASKP 11916

New Member
Hi

I am a beginner at this pic programming thing but unfortunately I have to do a project on this and I would be most grateful if you could help me out here.

What I have to make is an A/d converter from the 16f877A pic. But I thought of going through first things first, specially cause this is my first time in programming a pic. So I thought of writing out this simple programme to switch an led on and off, but after realizing that a pic switching an LED on/off will happen so fast I might not be able to see a difference I thought of writing a programme with an interrupt.

So as it is, it is powered off a crystal oscillator of 2.5 MHz and is made to switch the port D on and the goto sleep. Whenever there is an input at the interrupt pin (pin 33) the pic will wake up turn the LED on / off (depending on the previous state) and go back to sleep.

But when I run, it according to the circuit in the schematic diagram attached hereto, it doesn’t work. Nothing happens to the LED.

I have attached both the schematic diagram and the code. Please have a look at it and correct it as necessary.

Thanking you for your early response.

AP
 

Attachments

  • PicTest.asm
    555 bytes · Views: 140
  • Schematic.zip
    3.3 KB · Views: 117
hi askp,

Looking at the listing, there are number of errors and omissions.

Near the 'header' of your program I dont see a CONFIG statement?.

If you are using MPLAB assembler, look at the 16F877 templates in the directory, this is a good starting point when writing a program.

If you dont have the MPALB IDE 7.x you can get a free download from www.microchip.com

PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
 
ASKP 11916 said:
Hi

I am a beginner at this pic programming thing but unfortunately I have to do a project on this and I would be most grateful if you could help me out here.

I would suggest you check my tutorials, which gives examples of what you're looking to do.
 
I'm not sure what value would be assigned to the variable ba. Try changing the beginning of your code to,
Code:
	LIST P=16f877a
	#include <P16f877a.inc>

ba	equ 0x20

	org 	0x00
	goto	Start

	org		0x04
	goto	ISRoutine

	org 0x10
Start
	movlw 	0x02

BTW, that is an interesting way to use the sleep instruction.

Mike.
 
There are several problems with your code, a few that I noticed with a quick look at it were:

ba res 1
You need to define variables before the org statement specifying where in the user memory.
eg.
ba equ 0x20 ; this sets the variable ba to user memory location 0x20

You have implemented an interrupt routine that has no RETFIE command at the end of it, so it will never return.

There are calls to the "off" and "on" subroutines with no return.

Using the RB0/int external interrupt you really need to study section 14.11 of the manual (interrupts) as you need to set intcon bit INTE to enable wake-up from sleep and must clear flag bit INTF in the interrupt routine before re-enabling it.


I think you would probably get much better results at this stage by not trying to use interrupts.
Just flash the led using a simple delay routine for now to prove your code and then try adding interrupts and sleep options etc. later when you are confident that the main part of your program is fully working.
 
He uses the sleep instruction and so doesn't need a retfie. Same with the "off" and "on" subroutines.
He writes 0xd0 to INTCON and so does enable set INT0IE and clears INT0IF.

As I said, it's an interesting way to use the sleep instruction.

Mike.
 
RB0 is not configured as input. Personally I'd use a pull-up resitor (either internal or external) to assure that RB0 is in a known state when the switch is open.
Is that a button or a switch? interrupts on RB0 are "edge-sensitive".
 
Last edited:
Pommie said:
He uses the sleep instruction and so doesn't need a retfie. Same with the "off" and "on" subroutines.
He writes 0xd0 to INTCON and so does enable set INT0IE and clears INT0IF.

As I said, it's an interesting way to use the sleep instruction.

Mike.

Yes, you are quite right, I had not completely studied it.
In that case although it makes no difference to the actual program, I think it would be easier to understand if goto instructions were used instead of the call instructions to the off and on sections.
 
eng1 said:
RB0 is not configured as input. Personally I'd use a pull-up resitor (either internal or external) to assure that RB0 is in a known state when the switch is open.
Is that a button or a switch? interrupts on RB0 are "edge-sensitive".

Looks like you found the reason why it isn't working. The OP should set RB0 to input and see if that fixes the problem. He should also, as you suggest, turn the internal pullups on.

Mike.
 
Thanks for all the replys guys. I can understand the RB0 input thing!! don't know how I forgot that. Let me try it and get back to you.

But apart from the pull-up resistor does the schematic look ok? (By the way the interrupt was given off a button not a switch. Wanted it to work as a pulse). Also running the pic using a 2.5 MHz crystal is ok?

Thanks again will keep you posted on the outcome.

AP
 
Ok Ok!! So I tried turning port B to inputs, tried a pull-up resistor at the interrupt pin, added the config command and in order to put my code to the test I even visited the site given above read all the tutorials (which I have to admit taught me quite a lot of things that I didnt know) and used one of those programmes to run on my pic and tried it but there is still nothing.


However some thing very strange happened today when I plugged it in and in order to check the voltage difference at the crystal, kept the two wires at the ends of the crystal and the LEDs lit up. That I thought was strange, but at the moment the coding is written to switch on and off within one second. (which I think is visible to the eye) but it doesn't seem to go off.

Please help with this wired contraption.

Tks
 
If you use the pull-up resistor connected to the switch and RB0, the other terminal of the switch must be grounded.

A couple of questions...
1- Have you considered the switch bounce problem?

2- Suppose that the "ON" routine is called and then the PIC goes in SLEEP mode. I wonder which instruction is executed when the PIC wakes.
 
Last edited:
It works :) It works!! Yepee!!!

I can't believe it but itworks, and I'm now trying out small projects, just started on making a clock!!

Thanks a million for all the help you guys gave.

Will keep you informed if anything else comes up.

Thanks again.

Adios Amigos
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top