流水灯C语言程序

来源:百度知道 编辑:UC知道 时间:2024/06/27 04:54:11

#include <hidef.h> /* common defines and macros */

#include <mc9s12dg128.h> /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

int counter;

void TimerOverflow(void) {

/* This function waits for th timer overflow.

Then it changes the LEDs bargraph display */

while (TCNT != 0x0000);

while (TCNT == 0x0000);

counter++;

if (counter == 8) PORTB = 0x7e; /* LEDs' lightshow */

if (counter == 7) PORTB = 0xbd;

if (counter == 6) PORTB = 0xdb;

if (counter == 5) PORTB = 0xe7;

if (counter == 4) PORTB = 0xe7;

if (counter == 3) PORTB = 0xdb;

if (counter == 2) PORTB = 0xbd;

if (counter == 1) PORTB = 0x7e;

}

void main(void)

{

TSCR1 = 0x80; /* enable timer TCNT */

TSCR2 = 0x03; /* TCNT prescaler setup */

c