hi Eric
The code is as shown below... even though it compiles fine it does not display anything on the lcd... I am not sure of the functions used to write to LCD and the library used as this is new to me...
#include <avr/io.h>
#include "lcd_lib.h"
#include <util/delay.h>
void init(void)
{
LCDinit(); //initialises LCD
LCDGotoXY(0, 0); //Cursor Home
}
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
int main (void)
{
int buffer[7];
int num ;
init ();
DDRB |= (1 << 2); // Set LED1 as output
DDRC = (1 << 0); // Set LED2 as output
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set ADC prescalar
ADMUX |= (1 << REFS0) | (1 << REFS1); // Set ADC reference to 2.56V
ADMUX |= (1 << ADLAR); // Left adjust ADC result
// No MUX values needed to be changed to use ADC0
ADCSRA |= (1 << ADATE); // Set ADC to Free-Running Mode
ADCSRA |= (1 << ADEN); // Enable ADC
ADCSRA |= (1 << ADSC); // Start A2D Conversions
for(;
// Loop Forever
{
ADCH = num ; // convert integer into string
Itoa ( num , buffer, 10);
Printf ("The velocity is");
Printf ("%d", ADCH);
if(ADCH < 128)
{
PORTB|= (1 << 2); // Turn on LED1
PORTC &= ~(1 << 0); // Turn off LED2
}
else
{
PORTB &= ~(1 << 2); // Turn off LED1
PORTC|= (1 << 0); // Turn on LED2
}
}
delay1s();
delay1s();
}
The code above is written to perform the analogue to digital conversion and for the display on the LCD. The first part of the code is to initialise the LCD for it to be ready to display. Then the ADC is initialised by setting the various bits of the ADCSRA register and ADMUX register. The result is left adjusted to read only the eight bits of the register. Only eight bits of the ADC is used so the resolution is only 256 bits. I have set port B and Port D LEDs just to indicate if the value contained in ADCH is above 128 or below 128.