I have another problem. Im going to get the output of the analog signals via RA0, RA1 and RA3 and convert then into Binary and display on the LCD using a button. So far I have this code which I think the button didn't work. Here's the code:
INCLUDE "BS1DEFS.BAS "
Define ADC_CLOCK 3 'default value is 3
DEFINE ADC_BITS 8
Define ADC_SAMPLEUS 10 'default value is 20
Define LCD_BITS 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG PORTB
Define LCD_DBIT 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG PORTD 'RS port
Define LCD_RSBIT 1 'RS pin
Define LCD_EREG PORTD 'En port
Define LCD_EBIT 3 'En pin
Define LCD_RWREG PORTD 'R/W port
Define LCD_RWBIT 2 'R/W pin
DEFInE LCD_LINES 4 'LCD lines
DEFINE BUTTON_PAUSE 50 'button debounce delay is 50ms
an0 var word 'set variable an0 as word
an1 var word 'set variable an1 as word
B var PORTC.4 'define RC4 as pin input to select RA0 or RA1 as input
btn var byte
ledrc0 var PORTC.0 'set ledrc1 as RC0 indicates RA0 as input
ledrc1 var PORTC.1 'set ledrc2 as RC1 indicates RA1 as input
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = 4 ' Set RA0, RA1 & RA3 as analog input
btn = 0
goto loop 'skip subroutine
ra0: 'ra0 subroutine
high ledrc0 = 1
low ledrc1 = 0
Adcin 0, an0
Lcdout $fe, $01 ' Clears your LCD
Lcdout $fe, $c0 ' Cursor to Line 2 Column 1
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14, " ", "RA0", " ", "VALUE:" ' Formatted text for line 2
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $94 ' cursor to line 3
Lcdout $fe, $14, BIN8 an0 ' Formatted text for line 3
pause 1000
return
ra1: 'ra1 subroutine
high ledrc1
low ledrc0
ADCIN 1, an1
Lcdout $fe, $01 ' Clears your LCD, sets cursor to Line 1 Column 1
Lcdout $fe, $c0 ' Cursor to Line 2 Column 1
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $14, " ", "RA1", " ", "VALUE:" ' Formatted text for line 2
Lcdout $fe, $14 ' move cursor 1 space
Lcdout $fe, $94 ' cursor to line 3
Lcdout $fe, $14, BIN8 an1 ' Formatted text for line 3
pause 1000
return
loop: 'main
Button B,1,10,5,btn,0,loop
if btn = 1 then
Gosub ra1
else
gosub ra0
endif
Goto loop 'loop forever
END
Anyone I need help with buttons as to which pin I will connect it and how to declare them correctly...Thank you...
Bookmarks