lcd_out library
AVR OR PIC have adc for read voltage.
AVR'* Project name:
' adc on lcd
'* Author:
' MikroElektronika, September 2006.
'* Description:
' This program demonstrates how to use ADC library.
'* Test configuration:
' MCU: ATmega16
' Dev.Board: Easy AVR 3
' Oscillator: External, 8 MHz
' Ext. Modules:
' SW: mikroBasic for AVR 4.00
' * NOTES:
' connect potentiometer to MCU
'
program adc_on_lcd
dim data as word
text as string[7]
main:
Lcd_Init(PORTC, 4, 2, PORTA, LCD_HI_NIBBLE)
Lcd_Cmd(LCD_CURSOR_OFF)
Lcd_Out(1,1,"Analog Voltage:")
while true
' adc input PORTA.1
data=Adc_Read(1)
WordToStr(data, text)
Lcd_Out(2,5, text)
Delay_ms(10)
wend
end.
'========================
PIC
'(*
' * Project name:
' adconlcd2
' * Copyright:
' (c) mikroElektronika, 2005 - 2006
' * Revision History:
' 20050312:
' - initial release.
' * Description:
' This code demonstrates how to use library function ADC_read, and library
' procedures and functions for LCD display (4 bit interface)
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board: EasyPIC4
' Oscillator: HS, 8.000 MHz
' Ext. Modules: None
' SW: mikroBasic v5.0 or higher
' * NOTES:
' - If you are using EasyPIC4, use provided jumper on top right to connect potentiometer to RA2
' *)
program AdcOnLcd2
dim ch as byte
CurrentValue, LastValue as word
Text as char[10]
qqqq, rrrr as float
sub procedure WordToStrWithZeros2(dim input_ as word, dim byref output as char[4])
dim len_, tmp as byte
len_ = 1
if input_ > 9 then
Inc(len_)
end if
if input_ > 99 then
Inc(len_)
end if
if input_ > 999 then
Inc(len_)
end if
output = "0000" ' right justified
dec(FSR)
while len_ > 0
tmp = (input_ mod 10) + 48
INDF = tmp
dec(FSR)
input_ = input_ div 10
dec(len_)
wend
end sub
main:
PORTB = 0 ' clear portb
INTCON = 0 ' disable all interrupts
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
TRISA = $FF ' designate porta as input
Lcd_Init(PORTD) ' initialize (4-bit interface connection)
Lcd_Cmd( LCD_CURSOR_OFF) ' send command to LCD (cursor off)
Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)
Lcd_Out(1,1,"mikroElektronika") ' print string a on LCD, 1st row, 1st column
Lcd_Out(2,1,"LCD example") ' print string a on LCD, 2nd row, 1st column
Delay_ms(2000)
Lcd_Out(2, 1, "voltage:") ' print string a on LCD, 2nd row, 1st column
Lcd_Chr(2, 15, "V") ' Write "V" out of the loop, since it never changes
LastValue = 0 ' Inititalize LastValue
while true
CurrentValue = ADC_read(2) ' get ADC value from channel No.2
if CurrentValue <> LastValue then ' perform conversion only if they are different
rrrr = CurrentValue*(5000.0/1024.0)' 5 Volts over 1024 levels (10-bit conversion)
CurrentValue = rrrr ' This assignment will convert float to word
WordToStrWithZeros2(CurrentValue, Text) ' Convert word to string with zeros (right justified)
Text[4] = Text[3] ' This sequence will
Text[3] = Text[2] ' insert the "." character
Text[2] = Text[1] ' just after the first char in Text.
Text[1] = "."
Text[5] = 0 ' The string always ends with 0
Lcd_Out(2, 9, Text) ' Write formatted text
LastValue = CurrentValue' Equalize them so next time we do not write the same value
end if
wend
end.