hello/hello.c
author Scott Tsai <scottt.tw@gmail.com>
Sun Feb 22 19:36:00 2009 +0800 (3 years ago)
changeset 5 8ca4281a11b0
child 16 124daab51555
permissions -rw-r--r--
combine arduino and other avr8 programs
     1 #include <ctype.h>
     2 #include <stdint.h>
     3 #include <stdio.h>
     4 
     5 #include <avr/wdt.h> 
     6 #include <avr/io.h>
     7 #include <avr/interrupt.h>
     8 #include <avr/pgmspace.h>
     9 #include <util/delay.h>
    10 
    11 #include "uart.h"
    12 
    13 static void io_init(void)
    14 {
    15 	uart_init();
    16 }
    17 
    18 FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
    19 
    20 int main(void)
    21 {
    22 	wdt_disable();
    23 
    24 	cli();
    25 	if (F_CPU == 16000000UL) {
    26 		CLKPR = 0x80; // prescaler change enable
    27 		CLKPR = 0; // clock division factor == 1, so we have 16 MHz mpu frequency with our 16 MHz crystal
    28 	}
    29 
    30 	io_init();
    31 	DDRA = 0xFF;
    32 
    33 	stderr = stdout = stdin = &uart_str;
    34 
    35 	for (;;) {
    36 		fprintf(stderr, "Hello World\n");
    37 		PORTA = 0xff;
    38 		_delay_ms(2000);
    39 		PORTA = 0x00;
    40 		_delay_ms(2000);
    41 	}
    42 	return 0;
    43 }