PDA

View Full Version : Problem with PIC18F458 ADC code



minmin
- 25th September 2006, 20:15
HI, I am new to PicBasic.

I am trying to use PIC18F458 convert 0-5 v analog input, and show the result to LCD. I post my code below. The LCD part works fine, but it always show number "255" on the LCD, even I did not give any voltage input to PORTA.3

So anyone can help me look at my code, and see what is the problem?

Many thanks!!

Min

My code is:
-------------------------------------
DEFINE OSC 4

W1 VAR WORD

include "modedefs.bas"

PAUSE 1000 'LCD takes a second to start

TRISA = 255 'PORTA all inputs
ADCON1 = 0 'PORTA Analog I/O
ADCON0.7 = 1 'Right justified.


' Initialize USART
TRISC = %10111111 'Set TX (PortC.6) to out, rest in
TXSTA = %00100000 'Enable transmit and asynchronous mode

SEROUT PORTC.6,N9600,["Citrus Counter ",254,2]
PAUSE 1000

SEROUT PORTC.6,N9600,[254,1] ' Clear screen

LOOP1:
ADCIN PORTA.3, W1
SEROUT PORTC.6,N9600,[#W1,13]
GOTO LOOP1
END
--------------------------------------------------

BigWumpus
- 25th September 2006, 20:19
ADCIN PORTA.3, W1


Just use the right syntax !

ADCIN 3,W1 (use the channelnumber, not the Portpin!)

minmin
- 25th September 2006, 20:38
it works!!!
Thanks
Min

sayzer
- 25th September 2006, 20:43
Also, how do you send a word size variable via serial comm?

francisco767
- 1st June 2011, 07:25
Hi, wich simulator you used?


HI, I am new to PicBasic.

I am trying to use PIC18F458 convert 0-5 v analog input, and show the result to LCD. I post my code below. The LCD part works fine, but it always show number "255" on the LCD, even I did not give any voltage input to PORTA.3

So anyone can help me look at my code, and see what is the problem?

Many thanks!!

Min
__________-




My code is:
-------------------------------------
DEFINE OSC 4

W1 VAR WORD

include "modedefs.bas"

PAUSE 1000 'LCD takes a second to start

TRISA = 255 'PORTA all inputs
ADCON1 = 0 'PORTA Analog I/O
ADCON0.7 = 1 'Right justified.


' Initialize USART
TRISC = %10111111 'Set TX (PortC.6) to out, rest in
TXSTA = %00100000 'Enable transmit and asynchronous mode

SEROUT PORTC.6,N9600,["Citrus Counter ",254,2]
PAUSE 1000

SEROUT PORTC.6,N9600,[254,1] ' Clear screen

LOOP1:
ADCIN PORTA.3, W1
SEROUT PORTC.6,N9600,[#W1,13]
GOTO LOOP1
END
--------------------------------------------------

mister_e
- 1st June 2011, 07:59
There's no mention he used a simulator but a standard LCD.

mister_e
- 1st June 2011, 08:13
I meant standard serial LCD. sorry (Yeah I know... think more post less... plah plah plah)