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 CCS Technical Support

pic16f877 setup_adc_ports(all_digital); HELP

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



Joined: 06 Jul 2008
Posts: 13

View user's profile Send private message

pic16f877 setup_adc_ports(all_digital); HELP
PostPosted: Sun Jul 06, 2008 2:36 am     Reply with quote

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
Ttelmah
Guest







PostPosted: Sun Jul 06, 2008 2:58 am     Reply with quote

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
psypersky



Joined: 06 Jul 2008
Posts: 13

View user's profile Send private message

(undefined identifier ALL_DIGITAL)
PostPosted: Sun Jul 06, 2008 11:01 am     Reply with quote

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), ...
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sun Jul 06, 2008 11:21 am     Reply with quote

Quote:
'setup_adc_ports(ALL_DIGITAL)'


Change ALL_DIGITAL to NO_ANALOGS
_________________
David
psypersky



Joined: 06 Jul 2008
Posts: 13

View user's profile Send private message

PostPosted: Sun Jul 06, 2008 11:52 am     Reply with quote

drh wrote:
Quote:
'setup_adc_ports(ALL_DIGITAL)'


Change ALL_DIGITAL to NO_ANALOGS


It works now, thanks!! :grin:
Ttelmah
Guest







PostPosted: Sun Jul 06, 2008 2:45 pm     Reply with quote

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. Smile

Best Wishes
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