智能车制作
标题:
做点阵LED动态扫描,LED出现很快的闪烁
[打印本页]
作者:
zyh19941117
时间:
2014-7-11 20:39
标题:
做点阵LED动态扫描,LED出现很快的闪烁
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "MC9S12XS128.h"
static unsigned char j = 0;
uchar LedChar[] = {0x3C,0x3C,0x3C,0x00,0x00,0x3C,0x3C,0x3C};
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 16 TOI_ISR(void)
{
TFLG2_TOF = 1;
PORTA = 0xff;
switch(j)
{
case 0: PORTB_PB5=0; PORTB_PB6=0; PORTB_PB7=0; break;
case 1: PORTB_PB5=1; PORTB_PB6=0; PORTB_PB7=0; break;
case 2: PORTB_PB5=0; PORTB_PB6=1; PORTB_PB7=0; break;
case 3: PORTB_PB5=1; PORTB_PB6=1; PORTB_PB7=0; break;
case 4: PORTB_PB5=0; PORTB_PB6=0; PORTB_PB7=1; break;
case 5: PORTB_PB5=1; PORTB_PB6=0; PORTB_PB7=1; break;
case 6: PORTB_PB5=0; PORTB_PB6=1; PORTB_PB7=1; break;
case 7: PORTB_PB5=1; PORTB_PB6=1; PORTB_PB7=1; break;
default: break;
}
PORTA=LedChar[j++];
}
#pragma CODE_SEG DEFAULT
void main(void) {
/* put your own code here */
TSCR1_TEN = 1; //中断使能
TSCR2_TOI = 1; //溢出中断允许
TC0 = 0xfacb; //赋初值,1ms
DDRB=0xff;
PORTB_PB4=1;
DDRA = 0xff;
PORTA = 0xff;
EnableInterrupts;
for(;;)
{
if(j>=8) j=0;
} /* loop forever */
/* please make sure that you never leave main */
}
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2