/******************************************************************************** Includes ********************************************************************************/ #include #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 kbhit(void); int usart_putchar_printf(char var, FILE *stream); /******************************************************************************** Global Variables ********************************************************************************/ static FILE mystdout = FDEV_SETUP_STREAM(usart_putchar_printf, NULL, _FDEV_SETUP_WRITE); // these values are changed in an ISR, so they must be declared as volatile volatile uint8_t timer0_ticks; volatile uint16_t seconds; volatile uint8_t lights; /******************************************************************************** Interrupt Routines ********************************************************************************/ // timer1 overflow ISR(TIMER1_OVF_vect) { printf("***** Timer1 Overflow *****\n"); } // timer0 overflow ISR(TIMER0_OVF_vect) { // lets make the PORTA lights do something every timer tick lights++; PORTA=~lights; // 61 ticks = 2 seconds @ 8.0MHz timer0_ticks++; if(timer0_ticks==30){ // fake it, notice the printf is printing seconds+1 printf("Its been %u seconds.\n",seconds+1); } if(timer0_ticks==61){ timer0_ticks = 0; // till you make it, now we increment seconds twice seconds++; seconds++; printf("Its been %u seconds.\n",seconds); } } /******************************************************************************** Main ********************************************************************************/ int main( void ) { // Configure PORTA as output DDRA = 0xFF; // Configure PORTB as input DDRB = 0x00; // make sure it is high impedance and will not source PORTB = 0; // setup our stdio stream stdout = &mystdout; // fire up the usart usart_init ( MYUBRR ); printf("Ready to rock!\n"); // enable timer overflow interrupt for both Timer0 and Timer1 TIMSK=(1<>8); UBRRL = (uint8_t)ubrr; // Enable receiver and transmitter UCSRB = (1<