CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

question about 16F876

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
microccd



Joined: 08 Aug 2006
Posts: 10

View user's profile Send private message

question about 16F876
PostPosted: Mon Aug 14, 2006 3:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 3:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 3:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 4:19 pm     Reply with quote

Can you make the 16F876 do anything ? Try a very simple program
that just blinks an LED. Here is an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=19199&start=1
microccd



Joined: 08 Aug 2006
Posts: 10

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 4:24 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 4:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 4:29 pm     Reply with quote

CCS PCM C Compiler, Version 3.181, 23043
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 5:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 5:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 5:53 pm     Reply with quote

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 ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group