PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 16, 2012 12:11 pm |
|
|
Here is a demo program which shows how to read the analog voltage
(0 to +5v) on pin A0 and display it on an LCD:
Code: |
#include <18F452.H>
#device adc=10
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20M)
#include "flex_lcd.c"
//============================
void main()
{
int16 adc_value;
float volts;
lcd_init();
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
while(1)
{
adc_value = read_adc();
volts = (float)(adc_value * 5)/1023.0;
printf(lcd_putc, "\f%3.2f", volts);
delay_ms(500);
}
} |
|
|