diff tests/ledtest.c @ 0:a0ce8ebf2f18

LED on PINB0 & PINB1 and UART testing. - LED flasing on PINB0 & PINB1. - print 'hello' messages to UART for every flashing round.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 21 Feb 2009 15:49:59 +0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ledtest.c	Sat Feb 21 15:49:59 2009 +0800
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include "avriotools.h"
+#include <util/delay.h>
+#include <avr/io.h>
+
+int main(int argc, char *const argv[]) {
+    int i, cnt = 0;
+    const char *msg = "hello%d\n";
+    char buf[64];
+    
+    uart_init(400000);
+    
+    pin_mode(&PORTB, PINB0, PM_OUTPUT);
+    pin_mode(&PORTB, PINB1, PM_OUTPUT);
+    pin_lo(PORTB, PINB1);
+    for(i = 0; i < 30; i++) {
+	pin_hi(PORTB, PINB0);
+	_delay_ms(100);
+	pin_lo(PORTB, PINB0);
+	_delay_ms(100);
+    }
+    
+    while(1) {
+	pin_hi(PORTB, PINB0);
+	_delay_ms(100);
+	pin_lo(PORTB, PINB0);
+	_delay_ms(100);
+	pin_hi(PORTB, PINB0);
+	_delay_ms(100);
+	pin_lo(PORTB, PINB0);
+	_delay_ms(100);
+	pin_hi(PORTB, PINB0);
+	_delay_ms(500);
+	pin_lo(PORTB, PINB0);
+	_delay_ms(100);
+	
+	sprintf(buf, msg, cnt++);
+	for(i = 0; buf[i] != 0; i++)
+	    uart_putc(buf[i]);
+    }
+}