View previous topic :: View next topic |
Author |
Message |
blueprint
Joined: 21 Jun 2011 Posts: 12
|
Strange Problem with 16F877A Led Blink Demo! |
Posted: Wed Jun 29, 2011 4:33 am |
|
|
Hello Dear All,
I had some problems with 16f877a, therefore, I decided to try a simple led blink demo on it.
Unfortunately, the led does not blink or blinks very quickly. I tried some different 20Mhz crystals and 4Mhz crystals. Moreover I tried some different pins; A0, C0, D0, D1... However it couldn't solve the problem. I created a new project for 16f690, pasted the same code into it then, it worked properly on 16f690.
I know that Proteus ISIS simulator is not so reliable but I want to say that, I don't get such a problem on ISIS.
I will be very glad if you can help me.
I use PCWHD 4.120.
main.c:
Code: | #include <main.h>
void main()
{
//Example blinking LED program
while(true){
output_toggle(pin_a0);
delay_ms(500);
}
} |
main.h:
Code: | #include <16F877A.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=4000000) |
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed Jun 29, 2011 7:35 am |
|
|
1) You have got a series resistor between the PIC and the LED?.
2) How are you building this (PCB, breadboard, stripboard etc.)?.
3) Give a part number for the crystals - must be parallel cut type, or may run wildly off frequency. What loading capacitors are you using.
Best Wishes |
|
|
blueprint
Joined: 21 Jun 2011 Posts: 12
|
|
Posted: Wed Jun 29, 2011 10:09 am |
|
|
Thanks for your reply Ttelmah.
1. I have a 330 ohm resistor between the pic and the led.
2. I try the circuit on a breadboard. I am sure that connections are ok. I checked them with a multimeter. Moreover, I tried another breadboard.
3.I can give part numbers of them in a short time, but, these crystals work with 16f690 and 18f2550. I tried 15pF and 33pF capacitors. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed Jun 29, 2011 10:24 am |
|
|
Ok.
Pullup on MCLR?.
In the code:
Change oscillator to XT for the 4MHz crystal.
Look at what else is on pin A0:
add:
SETUP_PSP(PSP_DISABLED);
SETUP_ADC_PORTS(NO_ANALOGS);
at the start of main.
Some chips wake up with some pins defaulting to analog. Might be your problem.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 29, 2011 12:39 pm |
|
|
I made your code into a test program, and compiled it with vs. 4.120
and ran it on a PicDem2-Plus board (red vs.) and it works. I had to
jumper from pin A0 to pin B0, because PicDem2-Plus has an LED on
pin B0. But it works, the LED blinks at a 1 Hz rate, 50% duty cycle. |
|
|
blueprint
Joined: 21 Jun 2011 Posts: 12
|
|
Posted: Thu Jun 30, 2011 1:20 am |
|
|
Ttelmah wrote: | Ok.
In the code:
Change oscillator to XT for the 4MHz crystal. |
Dear Ttelmah, thanks for your help. It worked for 4Mhz crystal. However, HS or XT did not work for 20Mhz crystal.
Dear PCM programmer, thanks for your help. It also works on Proteus ISIS but I get these problems in real life unfortunately. |
|
|
|