/* Title: AVR-GCC test program #4 for the STK200 eva board Author: Volker Oth Date: 4/1999 Purpose: Uses the UART to communicate with a terminal program on the pc. The "tranceive complete" interrupt is used to send the string "Serial Data from AVR receiced###" continuously to the pc. When a byte was received from the pc, the "receive complete" interrupt is called, which outputs the byte to PortB where the LEDs visualize the 8 bits it consists of. UART format: 9600 baud, 8bit, 1 stopbit, no parity needed Software: AVR-GCC to compile needed Hardware: ATS90S8515/8535/2313/mega(?) on STK200/300 board Note: To contact me, mail to volkeroth@gmx.de You might find more AVR related stuff at my homepage: http://members.xoom.com/volkeroth */ #include #include #include #define F_CPU 4000000 /* 4Mhz */ #define UART_BAUD_RATE 9600 /* 9600 baud */ #define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16)-1) /* diese Formel wird im Datenblatt angegeben Ursprünglich war dort eine 161, aber im Datenblatt stand nur eine 16 deshalb hab ich sie geändert. Klappt trotzdem nicht */ typedef unsigned char u08; typedef char s08; typedef unsigned short u16; typedef short s16; /* uart globals */ static volatile u08 *uart_data_ptr; static volatile u08 uart_counter; SIGNAL(SIG_UART_TRANS) /* signal handler for uart txd ready interrupt */ { uart_data_ptr++; if (--uart_counter) outp(*uart_data_ptr, UDR); /* write byte to data buffer */ } SIGNAL(SIG_UART_RECV) /* signal handler for receive complete interrupt */ { register char led; led = inp(UDR); /* read byte for UART data buffer */ outp(~led, PORTB); /* output received byte to PortB (LEDs) */ } void uart_send(u08 *buf, u08 size) /* send buffer to uart */ { if (!uart_counter) { /* write first byte to data buffer */ uart_data_ptr = buf; uart_counter = size; outp(*buf, UDR); } } void uart_init(void) /* initialize uart */ { /* enable RxD/TxD and ints */ outp((1<