流水灯C语言程序

发布网友 发布时间:2022-04-26 07:21

我来回答

2个回答

热心网友 时间:2022-06-25 05:18

#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 */

counter = 0;

DDRB=0xff; /* PTB as output */

PORTB=0xff; /* LEDs off */

asm{

nop

}

for (;;)

{

TimerOverflow();

if (counter >= 8) {

counter = 0;

TSCR2 = 0x05; /* TCNT prescaler switch */

}

}

}

热心网友 时间:2022-06-25 05:18

上面的是什么程序啊,我编译了错了好多!!!!!!!

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com