/******************************************************************************** Includes ********************************************************************************/ #include #include #include /******************************************************************************** Macros and Defines ********************************************************************************/ #define BAUD 19200 #define MYUBRR F_CPU/16/BAUD-1 /******************************************************************************** Function Prototypes ********************************************************************************/ void usart_init(uint16_t ubrr); char usart_getchar( void ); void usart_putchar( char data ); void usart_pstr(char *s); unsigned char usart_kbhit(void); /******************************************************************************** Main ********************************************************************************/ int main( void ) { unsigned char input; uint8_t value; value = 0; // configure PORTA as output DDRA = 0xFF; // setup PORTB data direction as an input DDRB = 0; // make sure it is high impedance and will not source PORTB = 0; // fire up the usart usart_init ( MYUBRR ); // dump some strings to the screen at power on usart_pstr("Ready to rock and roll!\n\r"); usart_pstr("Type in a character, and I will transpose it up by 1:\n\r"); // main loop while(true) { // if a key has been pressed, then process it if(usart_kbhit()) { input = usart_getchar(); switch (input) { case 'a': usart_pstr("You pressed 'a'. Turning all lights on.\n\r"); PORTA=0x00; break; case 'b': usart_pstr("You pressed 'b'. Turning all lights off.\n\r"); PORTA=0xFF; break; default: usart_pstr("I don't know what to do with that key.\n\r"); } } // hold down SW0 to count binary patterns to the LEDs if(bit_is_clear(PINB,PB0)) { //usart_pstr("Incrementing value and setting up the lights.\n\r"); value++; PORTA = ~value; } // hold down SW1 to invert the LED's if(bit_is_clear(PINB,PB1)) { //usart_pstr("Inverting the light values.\n\r"); PORTA = ~PORTA; } } return 0; } /******************************************************************************** usart Related ********************************************************************************/ void usart_init( uint16_t ubrr) { // Set baud rate UBRRH = (uint8_t)(ubrr>>8); UBRRL = (uint8_t)ubrr; // Enable receiver and transmitter UCSRB = (1<