/* * LED.c * A program that turns on all LEDs, waits for a while, then turns * them all off. * * Author: C.Schramm * Date: February 10, 2006 */ #define _IO_BASE 0 #define _ADDR(off) (unsigned char volatile *)(_IO_BASE + off) #define _P(off) *(unsigned char volatile *)(_IO_BASE + off) #define PORTK _P(0x32) #define DDRK _P(0x33) void delay(void); void main(void) { // Setup PortK with Bits 0..3 as output pins (1=output) // DO NOT CHANGE DDRK |= 0x0F; // Turn on all four LEDs PORTK = 0b00001111; // Delay for a while, so that users can see the lights on delay(); // Turn on a single light of your choice. // INITIALLY: Leave as is, and see which colour corresponds to Port K, Bit 0 // THEN: Change the value to turn on any LED(s) of your choice. PORTK = 0b00000001; delay(); // Turn off all four LEDs PORTK = 0b00000000; } /* delay * Does idle work for a period of time, keeping the CPU busy * but doing nothing useful */ void delay(void) { int x; int y; int dummy = 1000; for(y=0; y<0x1FF; y++) { for(x=0; x<0x3FF; x++) { dummy = dummy + 0; dummy = dummy * 1; dummy = dummy / 1; } } }