View previous topic :: View next topic |
Author |
Message |
nicenoise
Joined: 10 May 2004 Posts: 17 Location: barcelona
|
strange problem with input pin in 18F1330 |
Posted: Thu Jul 03, 2008 10:15 am |
|
|
hello,
this is very strange...
maybe you can help me with this pic, compiler is 4.065
this is my simple program...
Code: | #include <18f1330.h>
#fuses HS, NOWDT,NOPROTECT,NOMCLR
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A2, rcv=PIN_A3, parity=N, bits=8)
void main(void)
{
set_tris_a(0xFF);
setup_adc(ADC_OFF);
output_low(PIN_B1);
output_low(PIN_B5);
output_low(PIN_B7);
while(TRUE)
{
if(input(PIN_A1))
output_high(PIN_B5);
else
output_low(PIN_B5);
if(input(PIN_A0))
output_high(PIN_B1);
else
output_low(PIN_B1);
}
} |
the input(PIN_A1) command not respond!!!
any sugestions??
thanks,
alex |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 03, 2008 10:45 am |
|
|
By default the PIC's I/O pins are defined as analog input ports (see the PIC datasheet). You have turned off the A/D-converter with the call to setup_adc() but there is a second function to be used for defining the I/O-pins as digital pins: Code: | setup_adc_ports( NO_ANALOGS ); |
By default the CCS compiler will automatically configure the TRIS register on each I/O operation so your setting of the TRIS register has little effect and can be removed. If you want to save a little on program memory usage than you can manually set the TRIS register once like you do but than instruct the compiler to not set the TRIS registers by adding the directive #USE FAST_IO at the start of your program. |
|
|
nicenoise
Joined: 10 May 2004 Posts: 17 Location: barcelona
|
|
Posted: Thu Jul 03, 2008 10:49 am |
|
|
thanks,
it works!! |
|
|
|