/*
* Analog Voltmeter
*
* Created: 12/1/2023 1:29:09 PM
* Author : VGU1
*/
#include <stdio.h>
#define F_CPU 8000000UL
#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header file */
#define analog_port PORTA
#define analog_ddr DDRA
float volt;
void ADC_Init(){
PORTA = 0x00; /* Make ADC port as input */
ADCSRA = 0x87; /* Enable ADC, with freq/128 */
ADMUX |= (1<<REFS0); /* Vref: Avcc, ADC channel: 0 */
}
int ADC_Read(char channel)
{
ADMUX = 0x40 | (channel & 0x07); /* set input channel to read */
ADCSRA |= (1<<ADSC); /* Start ADC conversion */
while (!(ADCSRA & (1<<ADIF))); /* Wait until end of conversion by polling ADC interrupt flag */
ADCSRA |= (1<<ADIF); /* Clear interrupt flag */
_delay_ms(1); /* Wait a little bit */
return ADCW; /* Return ADC word */
}
int main()
{
char Voltage[10];
ADC_Init(); /* initialize ADC*/
int i;
lcd_initialization(); /* Initialization of LCD*/
lcd_display_string("DC Voltage");
lcd_sending_command(0xc0); /* Go to 2nd line*/
while (1) {
volt = (ADC_Read(3)*0.0322);
volt = (volt/10.00);
lcd_sending_command(0xc0);
lcd_sending_command(0x0C);
lcd_string_float(volt,2,1 );/* send string data for printing */
lcd_display_string(" V");
_delay_ms(10);
}
}