/**************************************************************************** * * Copyright (c) 2005 Dave Hylands * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * ****************************************************************************/ /* Flash-LED.c modified by Dima Diall to read ADC on-demand */ #include #include #include "a2d.h" #include "Hardware.h" #include "UART.h" int main(void) { FILE *u0; InitHardware(); // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. So u0 is stdin, stdout, and stderr #if defined( __AVR_LIBC_VERSION__ ) u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); #else u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 ); #endif printf( "*****\n" ); printf( "***** Read-LED program\n" ); printf( "*****\n" ); while( 1 ) { // Poll UART for incoming characters if ( UART0_IsCharAvailable() ) { // Get ADC channel number as ASCII character char ch = getchar() - '0'; // Turn all of the LEDs off LED_OFF( RED ); LED_OFF( BLUE ); LED_OFF( YELLOW ); // Verify if ADC channel is in range (0..7) if ( ch >= 0 && ch <= 7 ) { // Read requested ADC channel and print result (in hex) LED_ON( BLUE ); printf( "0x%04x\n", a2d_10( ch )); } else { // Channel out of range: error! LED_ON( RED ); printf( "???\n" ); } } // Do other work, introduce some delay, go to sleep (...) } return 0; }