PDA

View Full Version : Welcome into PIC world



shafi008
- 24th April 2009, 04:40
Hello This is my first time in PIC's world.

I am using 16f84a with Melabs programmer.
I am trying to flash a led at PortB.0 and here is the code and
circuit diagram is at http://www.trendztechnologies.net/good.jpg

loop:
High PORTB.0 ' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Low PORTB.0 ' Turn off LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

At all the ports i have 0.74 reading.
LED is constant but it is not blinking.

Could you please suggest me what's wrong with this.

Syed

ScaleRobotics
- 24th April 2009, 05:02
Its a little hard for me to follow your "diagram", but it doesn't look like your resonator is grounded to me..... The center pin should go to ground, no?

Also try trisb command.

Check out:
http://www.picbasic.co.uk/forum/showthread.php?t=7906

Walter

Archangel
- 24th April 2009, 05:08
Its a little hard for me to follow your "diagram", but it doesn't look like your resonator is grounded to me..... The center pin should go to ground, no?

Also try trisb command.

Check out:
http://www.picbasic.co.uk/forum/showthread.php?t=7906

WalterLooks like the PIC is not hooked up to ground at all, notice the center pin of the resonator goes to the PICs ground leg but I see no ground wire there.

shafi008
- 24th April 2009, 15:12
Hi one of the document says the VSS should be connected to the middle pin of resonator, thats why it was connected to Vss and the pullup resistor i have used for MCLR is 4.7K. the other end of pullup resistor the voltage was around 2+_ volts.

As you said today let me try by connecting the resonator middle pin to Ground , i will post you the output later.

Archangel
- 24th April 2009, 18:25
Hello Syed,
I am looking at the picture you posted, you have a wire going from the center of the resonator to pin 5 of the PIC but no wire from Pin 5 to ground. It must be grounded to the 5v supply, otherwise the PIC receives no power.

Archangel
- 24th April 2009, 18:39
Hello Syed,
I am looking at the picture you posted, you have a wire going from the center of the resonator to pin 5 of the PIC but no wire from Pin 5 to ground. It must be grounded to the 5v supply, otherwise the PIC receives no power.See Attachment:
<img src=>http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3355&stc=1&d=1240594618

shafi008
- 26th April 2009, 07:02
Hi Guys,

Bad luck i tried changing another Pic16f84a
no work, i tried with multiple resonators and 4mhs with 47 / 10 pf that also doesnt' work.

here is the code file in two formats, probably i will update my cirucit picture tomorrow.
Code :

@ DEVICE pic16F84A
define OSC 4
TrisB = %00000000

loop:
High PORTB.0 ' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Low PORTB.0 ' Turn off LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

and in Hex:
0000- 2828 018f 008e 30ff 078e 1c03 078f 1c03
0008- 2823 3003 008d 30df 200f 2803 018d 3ee8
0010- 008c 098d 30fc 1c03 2818 078c 1803 2815
0018- 078c 0064 0f8d 2815 180c 281e 1c8c 2822
0020- 0000 2822 0008 1383 1303 1283 0064 0008
0028- 1683 0186 1283 1406 1683 1006 1283 3003
0030- 008f 30e8 2002 1006 1683 1006 1283 3003
0038- 008f 30e8 2002 282b 0063 283c


I noticed when i take off the Vss pin then the led is constantly lighting up.
if i connect Vss then nothing comes up. no power in the pins . with the multimeter i checked the pullup capacitor
is giving me 1.24 reading and no power on the pins,

what would be the problem. Is there any way of tracing this where it is going wrong?

Archangel
- 26th April 2009, 10:22
Hi Syed,
Try this code:


@ DEVICE pic16F84A
define OSC 4
PortB = 0 ' set port latches low
TrisB = %00000000 ' set portb as outputs

loop:
PORTB.0 = 1' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

PORTB.0 = 0 ' Turn off LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

I have had the high low operators fail to work for me and I do not know why.
EDIT: Make sure to hook up that ground wire to vss pin 5

shafi008
- 27th April 2009, 04:36
I tried with the code which you gave joe. still i have the same issue.
i appreciate your patience, i am just wondering about the diagram, please check the attachement. i have tried with 2 microcontrollers. is there any way of checking the microcode programming / fault pic .

Archangel
- 27th April 2009, 07:35
Hi shafi008,
Ok this picture looks much better, I HAVE FOUND, on some low cost breadboards, the power bus strips have gaps that must be bridged. I have some like that which needed 3 jumpers to make the strips have continuity all the way across, so just for practice, please use a meter or led and check yours, just to make sure.

shafi008
- 28th April 2009, 05:30
Hi

I tried with a new bread board from radioshack. same issue.
i checked with multimeter the power from the pullup resistor to ground is giving 1.24 volts and from VDD it is 5.08. is there any way to blame this 16f84A but i am wondering if i take off the VSS then the led is constantly ligting up and the power is 0.79. i am planning to order another pic16f84a and try. i already tried with 2 pics. Is there any known institutes in Newjersey. brother if you are residing in USA, i can send it to you by post. i am trying this for the past 4 weeks to fix this... any suggestions...........Hmmmmmm

ScaleRobotics
- 28th April 2009, 06:11
When you program it with your melabs programmer, can you check the fuse settings that are shown in the programmer. I believe there is a window you can open that shows you fuse settings. Can you make sure these are set correctly. The default settings that are in picbasic should do just fine. The file it is picking these up from is in c:/pbp/16f84a.inc

You could post a screen shot of these fuse settings from your melabs programmer. What we are looking for is this window:
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3373&d=1240895275

The meat of the 16f84a.inc file should read something like:


__config _XT_OSC & _WDT_ON & _CP_OFF

xt osc should be right, but you might want to turn your watch dog timer off.

I would have to see if I even have a 16f84a, but you might post your hex file and I am sure someone will load it to a 16f84a and see if they get life from it.

shafi008
- 28th April 2009, 16:11
Hi Here is the code what i am using and the attachment has the configuration.

@ DEVICE pic16F84A
define OSC 4
TrisB = %00000000

loop:
High PORTB.0 ' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Low PORTB.0 ' Turn off LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

and the hex

0000- 2828 018f 008e 30ff 078e 1c03 078f 1c03
0008- 2823 3003 008d 30df 200f 2803 018d 3ee8
0010- 008c 098d 30fc 1c03 2818 078c 1803 2815
0018- 078c 0064 0f8d 2815 180c 281e 1c8c 2822
0020- 0000 2822 0008 1383 1303 1283 0064 0008
0028- 1683 0186 1283 1406 1683 1006 1283 3003
0030- 008f 30e8 2002 1006 1683 1006 1283 3003
0038- 008f 30e8 2002 282b 0063 283c

shafi008
- 28th April 2009, 19:13
Hi for your reference here is the code listed in C:\pbp\PBP244\16F84A.INC file,

NOLIST
ifdef PM_USED
LIST
include 'M16F8x.INC' ; PM header
device pic16F84A, xt_osc, wdt_on, pwrt_on, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F84A, r = dec, w = -302
INCLUDE "P16F84A.INC" ; MPASM Header
__config _XT_OSC & _WDT_ON & _PWRTE_ON & _CP_OFF
NOLIST
endif
LIST

Archangel
- 29th April 2009, 02:03
Hi Syed,
Your code works. I compiled with MPASM assembler and got this hex:
:020000040000FA
:1000000028288F018E00FF308E07031C8F07031CEA
:10001000232803308D00DF300F2003288D01E83EB8
:100020008C008D09FC30031C18288C070318152838
:100030008C0764008D0F15280C181E288C1C222894
:1000400000002228080083130313831264000800B1
:10005000831686018312061483160610831203305A
:100060008F00E8300220061083160610831203303A
:0C0070008F00E83002202B2863003C28A1
:02400E00FD3F74
:00000001FF

You are NOT using ICD compile are you? Cause it won't work for you, To compile just press the F9 key.

Archangel
- 29th April 2009, 03:18
Ok I think you have not selected the correct chip in Micro Code Studio, and that is why your hex is different. Look at the tool bar and find the selection box and select the PIC you are using, then press F9 to compile. You will need to inspect this box before you compile each time because sometimes it changes without your help.
EDIT: Well . . .I just looked at the attachment and you do have the correct chip selected . . .hmmmm interesting.
<br>EDIT2: Had a second look at the attachment and saw it was MEPROG not MCS, so what I said before the edit stands, In MCS make sure the appropriate PIC is selected and recompile.

shafi008
- 29th April 2009, 04:28
Here is how i did it

I selected 16F84A from the drop down in MCS and F9 to compile one it is compiled without any errors then i press F11 to program it , once pressing F11 it compiles again and opens up Melabs Programmer window, here i made disabled WatchDog and Powe up time disabled.

One selected the Pic16F84A from the drop down i click on "Program".

Thats how i did.................


If you guys have VNC i can share my desktop Joe.

ScaleRobotics
- 29th April 2009, 04:51
The hex files seem to be the same. After compliling, I get one like post #13 if I look at the format my MeLabs programmer displays, but the hex file it uses looks just like post #15. So we must all be compiling the same thing. At least that's something! I have not been able to find my pic16f84a. I have not used those for a long time. The 16f84a has so few settings to begin with, that there isn't a lot to get wrong in the config fuses.

I saw that you have your osc set to 4 mhz. Can you confirm that your resonator is really 4 mhz? If it was 8 to 10 mhz, you should be setting it for HS and not XT.

By the way, do you have any other resonators, or crystals you could try?

shafi008
- 29th April 2009, 05:11
Hi I have the following
a). 4.00 GR
b). F0x040A 4.000 (with this i tried 4.7 / 220 / 10 PF's)

i tried with both , may i will try with a new Pic16f84a.
I dont get it when i take off the VSS then the led is constantly lighted up.

if i keep the multimeter to the pin RB0 then the light comes up steadily.
power at that time would be 0.79 and at MCLR to VSS it is 1.24 volts.

should i change the watchdog / powerup timer ON. and try...?
how much power should i get at the pin?

shafi008
- 29th April 2009, 05:25
Here is the code in MCS

@ DEVICE pic16F84A
define OSC 4
TrisB = %00000000

loop:
High PORTB.0 ' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Low PORTB.0 ' Turn off LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End


when the MeProg popsup the hex values are as follows,

0000- 2828 018f 008e 30ff 078e 1c03 078f 1c03
0008- 2823 3003 008d 30df 200f 2803 018d 3ee8
0010- 008c 098d 30fc 1c03 2818 078c 1803 2815
0018- 078c 0064 0f8d 2815 180c 281e 1c8c 2822
0020- 0000 2822 0008 1383 1303 1283 0064 0008
0028- 1683 0186 1283 1406 1683 1006 1283 3003
0030- 008f 30e8 2002 1006 1683 1006 1283 3003
0038- 008f 30e8 2002 282b 0063 283c

but when i program it then the values changes and displays like this.

0000- 003c 018f 008e 30ff 078e 1c03 078f 1c03
0008- 2823 3003 008d 30df 200f 2803 018d 3ee8
0010- 008c 098d 30fc 1c03 2818 078c 1803 2815
0018- 078c 0064 0f8d 2815 180c 281e 1c8c 2822
0020- 0000 2822 0008 1383 1303 1283 0064 0008
0028- 1683 0186 1283 1406 1683 1006 1283 3003
0030- 008f 30e8 2002 1006 1683 1006 1283 3003
0038- 008f 30e8 2002 282b 0063 283c


is it right?

ScaleRobotics
- 29th April 2009, 05:35
Your resonator probably has 15 pf, which is within what the data sheet says it should be. The 10 pf caps you have do not quite meet the data sheet specs for the other crystal you have. I do not know whether this would mean it won't work, or if it just would not be ideal (probably not ideal).

I think that mclr should be very close to vdd. So if it is just 1.24v or so, something is wrong. What is your vdd voltage? Is it also 1.24v?

Sounds like the voltage is the problem.

shafi008
- 29th April 2009, 05:52
VDD is 5.08 volts.
at mclr one side it is giving 5.08volts and the other side where the pin 4 is connected it is 1.24 volts.

ScaleRobotics
- 29th April 2009, 06:17
Well, not sure what is causing it, but on an healthy chip, you should be seeing between 4 and 5 v on the mclr pin. If you seem to be having enough voltage everywhere else, with no outputs from the chip accidentally going directly to ground, etc, then it seems like you have an unhappy PIC.

Archangel
- 29th April 2009, 06:33
Hi I have the following
a). 4.00 GR
b). F0x040A 4.000 (with this i tried 4.7 / 220 / 10 PF's)

i tried with both , may i will try with a new Pic16f84a.
I dont get it when i take off the VSS then the led is constantly lighted up.

if i keep the multimeter to the pin RB0 then the light comes up steadily.
power at that time would be 0.79 and at MCLR to VSS it is 1.24 volts.

should i change the watchdog / powerup timer ON. and try...?
how much power should i get at the pin?If you disconnect VSS the power flows through the PIC as though it were a resistor. I compiled with default configs, powerup timer enabled and WDT on. Have you tried reading back your hex from the PIC ? Maybe it is not programming at all. That could happen if the wrong COM port is selected, or programmer is jumpered wrong.
EDIT: try copy paste the hex I posted into your programmer and see if it blinks. BTW WDT and Power up timer are actually good things unless they somehow interfere (like when using sleep) Powerup allows PIC to wait for power to get stable B4 booting up and WTD resets a stalled out PIC.

Archangel
- 29th April 2009, 06:51
OK I just downloaded ME PROG and set it up . . and that is where the hex you are using came from, it is a default sample hex, not your hex.
When you click File . . . Open . . . The window that opens will list a directory tree and file name. You have to direct it to YOUR hex file located in Your PBP directory in whichever subdirectory you chose to save YOUR code in. That is why it is not working for you . . . Damn, it is the same . . . Hmmmm . . . OK again maybe the programmer isn't programming due to incorrect port.