#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
//uart has received a character in UDR
unsigned char tmp=0;
tmp = UDR;
if(tmp==0xaa)
{
ADCSR |= 0x40; //start single AD convertion
}
else
ADCSR = 0x8F;
}
#pragma interrupt_handler adc_isr:iv_ADC
void adc_isr(void)
{
//conversion complete, read value (int) using...
//unsigned int value = 0;
//value=ADCL; //Read 8 low bits first (important)
//value|=(unsigned int)ADCH << 8; //read 2 high bits and shift into top byte
//UDR = value;
unsigned char tmpL=0,tmpH=0;
tmpL = ADCL;
tmpH = ADCH;
UDR = tmpH; //show the High byte of ADC result
while(!(UCSRA&(1<
UDR = tmpL; //show the Low byte of ADC result
while(!(UCSRA&(1<
ADCSR = 0x8F; //close the ADC
//ToDo: Next step test the free-run mode, but I wonder how could I stop it?? Just do it!
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();
adc_init();