'For 16F886 4MHz clock and using R/W bit in LCD interface
Define CONFIG = 0x20c4
Define CONFIG2 = 0x3fff
#define LCD_LINES = 4
#define LCD_CHARS = 20
#define LCD_BITS = 4
#define LCD_DREG = PORTB
#define LCD_DBIT = 0
#define LCD_RSREG = PORTB
#define LCD_RSBIT = 6
#define LCD_EREG = PORTB
#define LCD_EBIT = 4
#define LCD_RWREG = PORTB
#define LCD_RWBIT = 5
#define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
#define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
#define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
#define ADC_Clk = 3
#define ADC_Sample_uS = 50
All_Digital
TRISB = 0
ANSEL = %00000100 'configure all PORTA pins except RA2 as digital I/O's
Dim buffer(16) As Byte
Dim data As Word
Dim dumm As Word
Lcdinit 0
Lcddefchar 0, %00000, %00000, %00000, %00000, %00000, %00000, %00000, %00000
Lcddefchar 1, %10000, %10000, %10000, %10000, %10000, %10000, %10000, %10000
Lcddefchar 2, %10100, %10100, %10100, %10100, %10100, %10100, %10100, %10100
Lcddefchar 3, %10101, %10101, %10101, %10101, %10101, %10101, %10101, %10101
main:
ADC_Read 2, data
dumm = data / 21
dumm = dumm * 100 / 48
Lcdcmdout LcdLine1Home
Lcdout " BAR GRAPH ", #dumm, " "
Lcdcmdout LcdLine2Home
Call bar(data)
Goto main
End
Proc bar(dat As Word)
Dim idx As Byte
Dim pos1 As Byte
Dim pos2 As Byte
pos1 = dat / 21
pos2 = (pos1 Mod 3)
pos1 = pos1 / 3
For idx = 0 To 15
buffer(idx) = 0x20
Next idx
For idx = 1 To pos1
buffer(idx - 1) = 3
Next idx
If pos2 = 0 Then
buffer(idx - 1) = 0x20
Else
buffer(idx - 1) = pos2
Endif
For idx = 0 To 15
Lcdout buffer(idx)
Next idx
End Proc
'All_Digital
'Lcdinit LcdCurBlink
'loop:
'Lcdout "Hello world!"
'WaitMs 1000
'Lcdcmdout LcdClear
'WaitMs 1000
'Goto loop