View previous topic :: View next topic |
Author |
Message |
wailoon86
Joined: 13 Sep 2007 Posts: 2
|
Need Help on PIC16F877A |
Posted: Thu Sep 13, 2007 7:42 pm |
|
|
Hello..
I am new to PIC programming. I'm currently trying to program PIC16F877A to light up an LED. Below is my code. Can someone try to advise me regarding this. Much appreciated.
#include <16F877A>
#use delay(clock=20000000)
#fuses hs,nowdt,noprotect
void main()
{
set_tris_d(0b00000000);
for(;;)
{
output_high(PIN_B0);
delay_ms(1000);
output_low(PIN_B0);
delay_ms(1000);
}
}
Is there any else that i miss? |
|
|
misaeldv
Joined: 10 Nov 2005 Posts: 11
|
|
Posted: Thu Sep 13, 2007 8:49 pm |
|
|
What kind of problems are you facing? |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Fri Sep 14, 2007 4:31 am |
|
|
Hello,
you don not need 'set_tris_d(0b00000000); '.
It is only necessary with #use fast_io (port).
dro. _________________ in médio virtus |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Fri Sep 14, 2007 5:59 am |
|
|
Hmm two posters with the same problem - must be homework time!
delay_ms(1000), will not work as you have found out.
You can only use delay_ms() with a 'variable' with a value of upto 255. I suggest you go and read the manual.
You can extend this value to 65535 by using a 'constant' - this is what I think you want to do.
Or you can call delay_ms(250) four times. |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Fri Sep 14, 2007 6:29 am |
|
|
As inservi? said, you don't need the set_tris_d. But if you do want to use fast_io, use set_tris_b if you're using pins on port b
Ken |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Fri Sep 14, 2007 7:02 am |
|
|
Hello,
Quote: | delay_ms(1000), will not work as you have found out.
You can only use delay_ms() with a 'variable' with a value of upto 255. I suggest you go and read the manual.
You can extend this value to 65535 by using a 'constant' - this is what I think you want to do.
Or you can call delay_ms(250) four times. |
I'm sorry but i often use delay_ms(1000) and it work perfectly with my PCWH as well with v3.xxx than 4.xxx.
dro. _________________ in médio virtus |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Fri Sep 14, 2007 7:31 am |
|
|
I am not entirely ure but I think the line
Code: | #use delay(clock=20000000) |
must be after the fuses, so:
Code: | #fuses hs,nowdt,noprotect
#use delay(clock=20000000) |
further I don't think the compiler should have any problems with the set_tris_d(0b00000000); line, but it's better to delete it, if only for human understanding ;)
Hope this helps,
Jos |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Fri Sep 14, 2007 10:27 am |
|
|
Hello,
My last program with 16f876 (about same as 16f877) have these lines and working right:
Code: | #use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG |
Foppie, Quote: | further I don't think the compiler should have any problems with the set_tris_d(0b00000000); line, but it's better to delete it, if only for human understanding ;)
| I agree with you.
This code is working !
Code: | void main() {
for(;;){
output_high(PIN_A2);
delay_ms(1000);
output_low(PIN_A2);
delay_ms(1000);
}
}
|
wailoon86,
What kind of problems are you facing ?
Are you sure that your programmer is working right ?
Are you already programed other pic ?
dro. _________________ in médio virtus |
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Sat Sep 15, 2007 4:01 am |
|
|
in the main routine does one not need a while(1) loop?
so use
Code: | void main()
{
while(1)
{
output_high(PIN_A2);
delay_ms(1000);
output_low(PIN_A2);
delay_ms(1000);
}
} |
|
|
|
Vodka
Joined: 13 Sep 2007 Posts: 14
|
|
Posted: Sat Sep 15, 2007 6:41 am |
|
|
everything goes well till delay_ms() apear..i have the same problem....pls tell me why??? |
|
|
wailoon86
Joined: 13 Sep 2007 Posts: 2
|
Reply... |
Posted: Sat Sep 15, 2007 9:19 am |
|
|
Dear Inversi,
I also not sure whats happening with the PIC. I'm using the Cytron Programmer WINPIC800 UP00A to program it. Using the CCS C compiler, i took the .hex file and program it to the PIC.
Also, one of my colleague told me to check whether is the hardware or software problem.
Here's how I did.
output_high(PIN_B0)
output_low(PIN_B1)
:
output_high(PIN_B7)
and so on.
when i connect my multimeter, output of B5 to B3 are low.
1.And I would like to ask, must I connect pin 1 (which is Master Clear Inverted) to Vss everytime I connect the circuit?
2.I noticed certain pins have two functions. I was wondering is there a way that I can I access it?
I been reading the datasheet and CCS C Manual over and over again.
Thanks for your guys help.
Much appreciate it. |
|
|
|