📄 main.c
字号:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
int counter;
int flag;
void TimerOverflow(void) {
/* This function waits for th timer overflow.
Then it changes the LEDs bargraph display */
while (TCNT != 0x0000);
while (TCNT == 0x0000);
if(flag)
counter--;
else
counter++;
if (counter == 8) PORTB = 0x7f; /* LEDs' lightshow */
if (counter == 7) PORTB = 0xbf;
if (counter == 6) PORTB = 0xdf;
if (counter == 5) PORTB = 0xef;
if (counter == 4) PORTB = 0xf7;
if (counter == 3) PORTB = 0xfb;
if (counter == 2) PORTB = 0xfd;
if (counter == 1) PORTB = 0xfe;
}
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) {
flag=1;
/* counter = 0;*/
TSCR2 = 0x03; /* TCNT prescaler switch */
}
if(counter==1) {
flag=0;
TSCR2= 0x05;
}
}
}
/* please make sure that you never leave this function */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -