/***************************************************************************** * File: serial.c * Date: Sat Jun 8 16:51:19 NZST 2002 * Author: Clark Mills (clark@kiwi.gen.nz) * Description: Play with the serial port on an AT90S8535 MCU * License: GPL *****************************************************************************/ #define UBRR 0x09 // UART Baud Rate Register #define USR 0x0B // UART Status Register #define UCR 0x0A // UART Control Register /* USR Register Bits */ #define UDRE 5 // set when ok to send a byte #define RXC 7 // set when byte in receive register /* UCR Register Bits */ #define RXEN 4 // enable receive on UART #define TXEN 3 // enable transmit on UART #include // prototypes int getc( void ); void putc( int ch ); void stepper_init( void ); void stepper_delay( void ); void led_init( void ); void serial_init( void ); void serial_putc( int ch ); int serial_getc( void ); /***************************************************************************** * Test it */ void main(void) { char ch; stepper_init(); led_init(); serial_init(); while (1) // Forever... { ch = serial_getc(); serial_putc( ch ); // sbi(PORTB,PB5); // LED Off // cbi(PORTB,PB5); // LED On /* // Clockwise Port 1 sbi(PORTD,PD4); stepper_delay(); cbi(PORTD,PD4); sbi(PORTD,PD4); sbi(PORTB,PB0); stepper_delay(); cbi(PORTB,PB0); cbi(PORTD,PD4); sbi(PORTB,PB0); stepper_delay(); cbi(PORTB,PB0); sbi(PORTB,PB0); sbi(PORTD,PD6); stepper_delay(); cbi(PORTD,PD6); cbi(PORTB,PB0); sbi(PORTD,PD6); stepper_delay(); cbi(PORTD,PD6); sbi(PORTD,PD6); sbi(PORTD,PD5); stepper_delay(); cbi(PORTD,PD5); cbi(PORTD,PD6); sbi(PORTD,PD5); stepper_delay(); cbi(PORTD,PD5); sbi(PORTD,PD5); sbi(PORTD,PD4); stepper_delay(); cbi(PORTD,PD4); cbi(PORTD,PD5); */ // Clockwise Port 2 sbi(PORTB,PB4); sbi(PORTB,PB1); stepper_delay(); cbi(PORTB,PB1); cbi(PORTB,PB4); sbi(PORTB,PB4); stepper_delay(); cbi(PORTB,PB4); sbi(PORTB,PB3); sbi(PORTB,PB4); stepper_delay(); cbi(PORTB,PB4); cbi(PORTB,PB3); sbi(PORTB,PB3); stepper_delay(); cbi(PORTB,PB3); sbi(PORTB,PB2); sbi(PORTB,PB3); stepper_delay(); cbi(PORTB,PB3); cbi(PORTB,PB2); sbi(PORTB,PB2); stepper_delay(); cbi(PORTB,PB2); sbi(PORTB,PB1); sbi(PORTB,PB2); stepper_delay(); cbi(PORTB,PB2); cbi(PORTB,PB1); sbi(PORTB,PB1); stepper_delay(); cbi(PORTB,PB4); } } /***************************************************************************** * LED serial port */ void led_init( void ) { sbi(DDRB,PB5); // enable PB5 as output LED sbi(PORTB,PB5); // LED Off } /***************************************************************************** * Init stepper port */ void stepper_init( void ) { // Enable Port 1 sbi(DDRD,PD4); // enable PD4 as output sbi(DDRB,PB0); // enable PB0 as output sbi(DDRD,PD6); // enable PD6 as output sbi(DDRD,PD5); // enable PD5 as output // Enable Port 2 sbi(DDRB,PB1); // enable PB1 as output sbi(DDRB,PB2); // enable PB2 as output sbi(DDRB,PB3); // enable PB3 as output sbi(DDRB,PB4); // enable PB4 as output } /***************************************************************************** * Delay */ void stepper_delay( void ) { int j, k; for (j=0; j<40; j++) { for (k=0; k<100; k++) sbi(DDRB,PB5); // enable PB5 as output LED } } /***************************************************************************** * Init serial port */ void serial_init( void ) { // outp( 0x19, UBRR ); // 9600 baud @ 4Mhz outp( 0x41, UBRR ); // 9600 baud @ 10Mhz outp( 1<