|
|
View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
same two line code on different chips 786 and 767 |
Posted: Tue Sep 28, 2004 10:56 am |
|
|
And the result is different. I checked the data sheet on both chips and the pin outs are the same.
767 code
Code: | #include <16F767.h>
#fuses NOWDT,NOPROTECT
#use delay(clock=1000000)
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
setup_oscillator(OSC_1MHZ);
printf("Starting\r\n");
printf("Booting\r\n");
while(1)
{
if (input(PIN_B1)==1) output_high(PIN_C4);
else output_low(PIN_C4);
}
} |
The code below works great, the code above never shows B1 going high.
876 code
Code: |
#include <16F876.h>
#fuses NOWDT,NOPROTECT,LP
#use delay(clock=1000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
printf("Starting\r\n");
printf("Booting\r\n");
while(1)
{
if (input(PIN_B2)==1) output_high(PIN_C4);
else
output_low(PIN_C4);
}
}
|
|
|
|
Nick Guest
|
|
Posted: Tue Sep 28, 2004 10:58 am |
|
|
ignore the
Code: | if (input(PIN_B1)==1) | i changed from B2 to B1 for testing. Its actually should be PIB_B2 like the other code. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 28, 2004 11:52 am |
|
|
Quote: | I checked the data sheet on both chips and the pin outs are the same. |
That's not quite correct. If you look at the pin diagram at the beginning
of the 16F767 data sheet, you see AN10, AN12, AN8, etc., all over port B.
It's got analog pins on port B.
So, if you want to use Port B as digital pins, you've got to ensure that
the PIC is setup for that mode.
Just as a general rule, CCS doesn't pay a lot of attention to setting
up the A/D pins as digital i/o on new chips. By "new chips", I mean
anything beyond a 16F877. So if I look at the startup code for
the 16F767 with PCM vs. 3.212, I see that they're setting ADCON1 = 3.
If I look at the chart for ADCON1 in the data sheet, I can see that '3'
sets AN12 and AN13 as digital, and all the rest as analog pins.
So you can't count on CCS doing it correctly. (Their theme that they
followed in the past, is to set all pins as digital in the startup code).
This means you have to do it yourself. So put this line at the start
of main():
Code: | setup_adc_ports(NO_ANALOGS); |
And of course, you should also look at the .LST file to confirm that
this function is really working the way you'd expect. I checked it
for PCM vs. 3.212, and it is.
The point to remember here is don't trust the startup code to setup
the A/D pins as all digital. Check the .LST file to confirm it, and if
necessary, put in code to fix it. This may mean writing directly to
registers if the CCS functions don't do the job. These comments
also apply to any chips with comparators. |
|
|
Nick Guest
|
|
Posted: Tue Sep 28, 2004 1:09 pm |
|
|
Thank you! I really appreciate your help. Its nice to have an expert that comes to the forums, again thank you!
Nick |
|
|
|
|
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
|