![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
psypersky
Joined: 06 Jul 2008 Posts: 13
|
pic16f877 setup_adc_ports(all_digital); HELP |
Posted: Sun Jul 06, 2008 2:36 am |
|
|
I have this program and everything works, except the digital inputs on port a, it always read the same, no matter the state of the pin :S
i tried everything to make in work but i cant, can some one help me with this please?
The unworking peace of code it's almost at the bottom....
The compiler make an error .. (Undefined identifier ALL_DIGITAL)...
[sorry for my realy bad english :oops: ]
Code: | #include <16F877a.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#include <flex_lcd.c>
#include <x10.c>
#include <input.c>
#include <STDLIB.H>
//#define Digital_in_0 PIN_A0
//#use standard_io(A)
void main()
{
int32 prueba=0;
int nose =0;
char house_code;
BYTE key_code;
setup_adc_ports(all_digital);
setup_comparator(NC_NC_NC_NC);
output_bit( PIN_B4, nose);
output_bit( PIN_E0, nose);
lcd_init();
lcd_putc("\fHello World\n");
lcd_putc("\f" );
printf("Ruben`s module 16f877 online\n\r");
while (TRUE) {
prueba++;
if(prueba==20000){//papadeo de B4
if(nose==0)
nose=1;
else
nose=0;
output_bit( PIN_B4, nose);
output_bit( PIN_E0, nose);
prueba=0;
}
if(kbhit()) {
house_code = getc();
printf("%c", house_code);
if((house_code>='A') && (house_code<='P')) {
key_code=gethex();
// printf("%c%2X", house_code, key_code);
printf("Mandando>>\n\r");
x10_write(house_code,key_code);
//x10_write(house_code,key_code);
printf("%c%2X", house_code, key_code);
}
printf("Fin de kbhit\n\r");
}
if(x10_data_ready()) {
putc('>');
x10_read(&house_code, &key_code);
printf("%c%2X", house_code, key_code);
if(house_code == 'A')
printf("house code = A");
if(key_code== 0x1B)
printf("key code = 1b");
}
if(!input(PIN_A4)) // This is the part than doesn`t work !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
x10_write('B',0x01);
lcd_putc("\fPin A0 precionado\n");
delay_us(50);
}
}
} |
Last edited by psypersky on Sun Jul 06, 2008 11:03 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Jul 06, 2008 2:58 am |
|
|
First, the line 'setup_adc_ports(ALL_DIGITAL)', neds to be _in_ the program. This is 'code', not a 'configuration' (like a #define, or fuse statement), and needs to actually be _run_. Put it into your main, immediately after your variable declarations. Currently it is not being called.
Second, on the 'A' chip, there are _two_ analog devices, that use the pins. The ADC,and the comparator. _Both_ should be disabled. So as the next line after the setup_adc_ports, you want:
setup_comparator(NC_NC_NC_NC);
which turns off the comparator connections.
With these done, the pins become available for digital use.
Anything in the manual, which in it's 'example', has a ';' at the end of the line, is code, and needs to be inside a routine where it is called, to actually work.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
psypersky
Joined: 06 Jul 2008 Posts: 13
|
(undefined identifier ALL_DIGITAL) |
Posted: Sun Jul 06, 2008 11:01 am |
|
|
Ttelmah wrote: | First, the line 'setup_adc_ports(ALL_DIGITAL)', neds to be _in_ the program. This is 'code', not a 'configuration' (like a #define, or fuse statement), and needs to actually be _run_. Put it into your main, immediately after your variable declarations. |
Thanks Ttelmah.... I put setup_adc_ports(all_digital); after my variable declarations, but now it says (undefined identifier ALL_DIGITAL), ... |
|
![](templates/subSilver/images/spacer.gif) |
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Sun Jul 06, 2008 11:21 am |
|
|
Quote: | 'setup_adc_ports(ALL_DIGITAL)' |
Change ALL_DIGITAL to NO_ANALOGS _________________ David |
|
![](templates/subSilver/images/spacer.gif) |
psypersky
Joined: 06 Jul 2008 Posts: 13
|
|
Posted: Sun Jul 06, 2008 11:52 am |
|
|
drh wrote: | Quote: | 'setup_adc_ports(ALL_DIGITAL)' |
Change ALL_DIGITAL to NO_ANALOGS |
It works now, thanks!! :grin: |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Jul 06, 2008 2:45 pm |
|
|
The text inside these statements, is contained in the .h file for the processor, as a series of 'defines'. Unfortunately, not quite 'standard' (CCS has changed the form used at various times over the years), so when wanting to know what to put into the statements, look in the file for your processor.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|