/************************************************* * * * Program: Port H Switch Inputs * * * * Name : phoa4evb.c * * * * Date : 13 June 2002 * * * * By : Jake Gamage * * Adapted from phoa4evb.asm * * written by Steven J. Dombrowski * * * * This program outputs all 8 bits on * * the M68HC12A4EVB and continuously updates all * * outputs. * * * * To execute this program type G 5000 * * * ************************************************/ #include #include #include /* D_1MS is the time it takes for the processor to execute one subtract operation. It is used to somewhat accurately create a delay. The compiler adds a lot of overhead, so its hard to tell exactly how long the delay function actually takes. For a more accurate timer setup, try using the timed interrupts to keep track. */ /* I could define this as (800/2) for the frequency divided by the clock cycles for a subtract instruction. However, every time D_1MS would appear in the code, it would have to perform a divide instruction (this is very slow compared to other instructions). */ #define D_1MS 400 void delay(unsigned int); int __main() { _H12DDRH = 0xFF; /* Set for all output */ DB12->printf("This program will output all 8 bits on PortH\n\r"); while(1) { /* This program just outputs a different value to Port H every half second. This will make the signals on Port H flash in sequence. */ _H12PORTH = 0xFE; delay(500); _H12PORTH = 0xFD; delay(500); _H12PORTH = 0xFB; delay(500); _H12PORTH = 0xF7; delay(500); _H12PORTH = 0xEF; delay(500); _H12PORTH = 0xDF; delay(500); _H12PORTH = 0xBF; delay(500); _H12PORTH = 0x7F; delay(500); } } void delay(unsigned int ms) { int i; int j = D_1MS; while(ms > 0) { i = j; while(i > 0) { i-=1; }ms-=1; } }