View previous topic :: View next topic |
Author |
Message |
microccd
Joined: 08 Aug 2006 Posts: 10
|
question about 16F876 |
Posted: Mon Aug 14, 2006 3:26 pm |
|
|
I am learning to program the microcontrollers, the following test code works fine on the 16F877 development kit, but it doesn't work on 16F876. why? I appreciate any help.
Code: |
#include <16f876.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
#define PUSH_BUTTON PIN_A4
#define cutoff 128 //2.5 volts
#define neutral_zone 100 //2.0 volts
main() {
int reading;
int i;
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
output_high(PIN_B4);
output_high(PIN_B5);
while(true){
reading = read_adc();
if(reading>(cutoff-neutral_zone/2) && reading<(cutoff+neutral_zone/2))
{
output_high(PIN_B5);
output_low(PIN_B4);
i=1;
}
else
{
output_low(PIN_B5);
output_high(PIN_B4);
i=2;
}
if(i==2)
{
while(input(PUSH_BUTTON));
delay_ms(50);
while(!input(PUSH_BUTTON));
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 14, 2006 3:47 pm |
|
|
The two chips are in different packages. Assuming you're using DIPs,
the 16F877 is 40 pins and the 16F876 is 28 pins. So it's possible that
you made a mistake when you designed or built the board with the
16F876. It may not be connected in the same way as the 16F877.
Also, you're running at 20 MHz. The PICs are available in different
speeds. Your 16F877 is probably a "-20" chip. It can run at 20 MHz.
Your 16F876 may be a "-04" chip, which is rated for only 4 MHz maximum
frequency. |
|
|
microccd
Joined: 08 Aug 2006 Posts: 10
|
|
Posted: Mon Aug 14, 2006 3:59 pm |
|
|
Thanks a lot for the response. Both chips are -20. I tested another program, works fine on both chip. but this one only works on 16F877. and I dont know why |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
microccd
Joined: 08 Aug 2006 Posts: 10
|
|
Posted: Mon Aug 14, 2006 4:24 pm |
|
|
Yes, if I take the following code out, it works on 16F876. with the following, works fine on 16F877, but not on 16F876.
Code: |
if(i==2)
{
while(input(PUSH_BUTTON));
delay_ms(50);
while(!input(PUSH_BUTTON));
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 14, 2006 4:27 pm |
|
|
Post your compiler version. It's a number such as 3.191, 3.236, or
3.249, etc. It's at the top of the .LST file, which is in your project folder. |
|
|
microccd
Joined: 08 Aug 2006 Posts: 10
|
|
Posted: Mon Aug 14, 2006 4:29 pm |
|
|
CCS PCM C Compiler, Version 3.181, 23043 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 14, 2006 5:00 pm |
|
|
I installed PCM vs. 3.181 and compiled for both PICs. I used ExamDiff
to compare the two .LST files. They're identical except for the #include
statement and two lines after it, that have the PIC name in them.
Since your program fails in the section that tests the push button, you
should carefully check the connections in that area. Do you have a
pullup resistor on your 16F877 circuit, but it's missing on the 16F876
board ? That could cause the problem. Look for things like this. |
|
|
microccd
Joined: 08 Aug 2006 Posts: 10
|
|
Posted: Mon Aug 14, 2006 5:39 pm |
|
|
thanks a lot for the help. I checked the connections of 16f876. I do use the pullup resistor for the push button. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 14, 2006 5:53 pm |
|
|
Can you describe what you mean, when you say the program
"doesn't work" with the 16F876 ? What does the program do,
and what do you expect it to do ? |
|
|
|