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

Input () Function Issue.....

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



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

Input () Function Issue.....
PostPosted: Thu Mar 02, 2006 9:24 am     Reply with quote

Guys

I has some issue with input() function,
My code is below:

Code:

#include <18F2525.h> // Call for PIC18F2525 Driver
//#device ICD=TRUE
#device ADC=10 // Use 10bits ADC
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16000000) // 16Mhz Crystal is Used
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8) 

#include <MAX517mod.c>
#byte PORTB = 0xf81
#byte PORTC = 0xf82



#include <stdlib.h>
#include <math.h>




//Start main program
void main()

{

   

while(1)

  {
     
      output_high(PIN_C5); // Power On LED
      delay_us(100);

     

      while ( !input(PIN_A2) );

      // waits for freq ready signal from A2

        output_low(PIN_C5);//LED OFF

       printf("\n\r we got A2 signal ON");

 
     }

}





Even though I tied PIN_A2 with 5V.... It won't proceed the later "printf" statment....

Did I miss to declare something?
Do I have to define PORT A as INPUT??(SET_TRISA???)



thx in advance...

sonic
Smile
Ttelmah
Guest







PostPosted: Thu Mar 02, 2006 9:55 am     Reply with quote

What you post, should basically work. However on some chips/compiler versions, the default state for some peripherals (especially the comparator), may be 'enabled', and so you should try disabling these:
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_COMPARATOR(NC_NC_NC_NC);
The compiler auotmatically handles TRIS for you, setting the port as an input, or output when required.
Also add 'NOBROWNOUT' to the fuses, or set the brownout voltage to a required level.

Best Wishes
sonicdeejay



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

PostPosted: Thu Mar 02, 2006 12:38 pm     Reply with quote

I use PIN C0 as input now...and it is working...

I can't afford to close ADC ports(PORT A) as I am uing 2 ADC...

thx again


sonic

Smile
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 02, 2006 2:50 pm     Reply with quote

Read carefully the documentation for SETUP_ADC(). You can configure some pins as analog in, some as reference levels and the rest and digital.

As with most CCS functions, you should also check the LST file against the datasheet. They have had a history of subtle errors.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Ttelmah
Guest







PostPosted: Thu Mar 02, 2006 3:10 pm     Reply with quote

sonicdeejay wrote:
I use PIN C0 as input now...and it is working...

I can't afford to close ADC ports(PORT A) as I am uing 2 ADC...

thx again


sonic

Smile

You are trying a _test_ to get things working. This test does not have any ADC's, so you should turn the ports off, especially since you are using portA.
Once you have the test working, then work out how to turn on the ADC pins you want to use. However you will have problems with your code as shown, since if enabled, port A0, is always an ADC pin.
You do understand that the 'input' function, reads the pins as digital inputs, not as analog, and a pin cannot be used for an ADC pin, and for digital I/O at the same time?...

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