program F676_exp
' Declarations section
'******************************************************
dim LCD_RS as sbit at RC4_bit ' Lcd
LCD_EN as sbit at RC5_bit
LCD_D4 as sbit at RC3_bit
LCD_D5 as sbit at RC2_bit
LCD_D6 as sbit at RC1_bit
LCD_D7 as sbit at RC0_bit
LCD_RS_Direction as sbit at TRISC4_bit
LCD_EN_Direction as sbit at TRISC5_bit
LCD_D4_Direction as sbit at TRISC3_bit
LCD_D5_Direction as sbit at TRISC2_bit
LCD_D6_Direction as sbit at TRISC1_bit
LCD_D7_Direction as sbit at TRISC0_bit ' LCD
dim text as string [16] ' text string
dim ch, adc_rd as word ' ch, adc_rd word
dim tlong as word ' tlong, longword
sub procedure settings
CMCON=7
ANSEL=%00000001
ADCON1=%00110000
ADCON0=%10000001
TRISA=%000001
INTCON = 0 ' all interrupts disabled
TRISC = 0 ' PORTC is output
end sub
main:
' Main program
settings
Lcd_Init() ' LCD
Lcd_Cmd(_LCD_CURSOR_OFF) ' LCD (off)
Lcd_Cmd(_LCD_CLEAR) ' LCD command (clear LCD)
text = "mikroElektronika" ' First message
Lcd_Out(1,1,text) ' First message, first line
text = "LCD example" ' Second message
Lcd_Out(2,1,text) ' Second message, second line
Delay_ms(500)
text = "Voltage=" ' Third message
while 1 ' Loop
adc_rd = ADC_Read(0) ' A/D conversion. RA0 input.
Lcd_Out(2,1,text) ' Result second line
tlong = adc_rd * 5000 ' Milivolt
tlong = tlong / 1023 ' 0..1023 -> 0-5000mV
ch = (tlong / 1000) mod 10 '
'
Lcd_Chr(2,9,48+ch) '
Lcd_Chr_CP(".") '
ch = (tlong / 100) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = (tlong / 10) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = tlong mod 10 '
Lcd_Chr_CP(48+ch) '
Lcd_Chr_CP("V") ' Show "V"
Delay_ms(1) ' 1mS delay
wend
end.