|
|
View previous topic :: View next topic |
Author |
Message |
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
Input () Function Issue..... |
Posted: Thu Mar 02, 2006 9:24 am |
|
|
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
|
|
|
Ttelmah Guest
|
|
Posted: Thu Mar 02, 2006 9:55 am |
|
|
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
|
|
Posted: Thu Mar 02, 2006 12:38 pm |
|
|
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
|
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Mar 02, 2006 2:50 pm |
|
|
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
|
|
Posted: Thu Mar 02, 2006 3:10 pm |
|
|
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
|
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 |
|
|
|
|
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
|