// Copyright 2006 Yamane Akira //ICC-AVR application builder : 2005/08/17 15:29:42 // Target : M48 // Crystal: 8.0000Mhz #include #include void port_init(void) { PORTB = 0xFF; DDRB = 0xFF; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0xEF; DDRD = 0x14; // set PD4 & PD2 as output for SCK & SS } //UART0 initialize // desired baud rate: 100000 // actual: baud rate:100000 (0.0%) void uart0_init(void) { UCSR0B = 0x00; //disable while setting baud rate UCSR0A = 0x00; UCSR0C = 0xC0; UCSR0B = 0x18; UBRR0L = 0x04; //set baud rate lo UBRR0H = 0x00; //set baud rate hi } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); uart0_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EIMSK = 0x00; TIMSK0 = 0x00; //timer 0 interrupt sources TIMSK1 = 0x00; //timer 1 interrupt sources TIMSK2 = 0x00; //timer 2 interrupt sources PCMSK0 = 0x00; //pin change mask 0 PCMSK1 = 0x00; //pin change mask 1 PCMSK2 = 0x00; //pin change mask 2 PCICR = 0x00; //pin change enable PRR = 0x00; //power controller SEI(); //re-enable interrupts //all peripherals are now initialized } unsigned char USART_MSPIM(unsigned char tdata) { while (!(UCSR0A & (1 << UDRE0))); UDR0=tdata; while (!(UCSR0A & (1 << RXC0))); return UDR0; } void delay() { unsigned char a,b; for (a=1; a; a++) for (b=1; b; b++) ; } // void main(void) { unsigned char i; init_devices(); while(1) { for (i=0; i<8; i++) { PORTD &= ~0x04; PORTB = USART_MSPIM(i); PORTD |= ~0x04; delay(); } } }