pic16f628 voltmeter
have u seen data sheet for pic16f628. i cant see any adc.
'******************************************************************************
' microcontroller P16F877A
'
' Project ADC_on_Leds
' This project is designed to work with PIC 16F877A
' with minor adjustments, it should work with any other PIC MCU
' that has ADC module.
'
' This code demonstrates using library function for ADC conversion
' (10 bits) result is displayed on portd and portb
' (two most significant bits are displayed on portb).
'******************************************************************************
program ADC_on_Leds
dim temp_res as word
main:
ADCON1 = $80 ' configure analog inputs and Vref
TRISA = $FF ' designate PORTA as input
TRISB = $3F ' designate RB7, RB6 pins as outputs
TRISD = $0 ' designate PORTD as output
while true
temp_res = ADC_read(2)
'now you can use temp_res ...'
PORTD = temp_res ' send lower 8 bits to PORTD
PORTB = word(temp_res >> 2)
' send two most significant bits to PORTB, pins RB7,RB6
wend
end.
'******************************************************************************
' microcontroller P16F877A
'
' Project: adconlcd
' This project is designed to work with PIC 16F877A
' with minor adjustments, it should work with any other PIC MCU
' that has ADC module.
'
' This code demonstrates how to use library function ADC_read, and library
' procedures and functions for LCD display (4 bit interface)
'
'******************************************************************************
program adconlcd
dim ch as byte
dim t as integer
dim a as string[20]
dim tlong as longint
main:
PORTB = 0 ' clear portb
TRISB = 0 ' designate portb as output (LCD is connected to portb)
intcon = 0 ' disable all interrupts
Lcd_init(PORTB) ' 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)
a = "mikroElektronika" ' assign text to string a
lcd_out(1,1,a) ' print string a on LCD, 1st row, 1st column
a = "LCD example" ' assign text to string a
lcd_out(2,1,a) ' print string a on LCD, 2nd row, 1st column
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
TRISA = $FF ' designate porta as input
Delay_ms(2000)
a = "voltage:" ' assign text to string a
DoAdc:
t = ADC_read(2) ' get ADC value from 2nd channel
lcd_out(2,1,a) ' print string a on LCD, 2nd row, 1st column
tlong = t*5000
t = longint(tlong >> 10)
ch = t div 1000 ' prepare value for diplay
lcd_chr(2,9,48+ch) ' write ASCII at 2nd row, 9th column
lcd_chr(2,10,".")
ch = integer(t div 100) mod 10
lcd_chr(2,11,48+ch)
ch = integer(t div 10) mod 10
lcd_chr(2,12,48+ch)
ch = t mod 10
lcd_chr(2,13,48+ch)
lcd_chr(2,14,"V")
delay_ms(1)
goto DoAdc
end.