📄 light1.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <Fx2.h>
#include <Fx2regs.h>
unsigned char flag;
unsigned char count_20;
unsigned char i, j ;//i is the index of DSP7LED
//j is the count of interrupt
unsigned char digbit;//BITTAB[digbit]
main()
{
OEA = 0xff;//sets the input/output direction
OEB = 0xff;
IOA = 0xff;//set the initial number
IOB = 0xff;
TMOD = 0x11;//use two timers
//set initial 50ms
TL0 = 0xB0;
TH0 = 0x3C;
//1ms
TL1=0x18;
TH1=0xFC;
EA = 1;//interrupt enable
ET0 = 1;// timer0 enable
ET1 = 1;
TR0 = 1;//begin timer0
TR1 = 1;
while(1);//loop
}
void timer0(void) interrupt 1 using 0{
TL0=0xB0;
TH0=0x3C;
if(count_20<19){
count_20++;
flag=0;
}else{
count_20 = 0;
flag = 1;
}
if(flag){
if (j<7) j++;
else j=0;
}
}
void ledcontrol(void) interrupt 3 using 1
{
unsigned char temp_DSP7LED[16];//add dp to the number
unsigned char DSP7LED[16] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //ten numbers 0-9
unsigned char BITTAB[8]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//8 LED enable
// TH0 = (time/256);//put in the time again;
// TL0 = (time%256);
TL1=0x18; //USED FOR AD SAMPLING
TH1=0xFC;
// if (j<7) j++;//每中断一次J就加1 显示就变一次
// else j=0;
// do{
switch(digbit+1)
{
case 1 : i = j%10; break;
case 2 : i = (j+1)%10; break;
case 3 : i = (j+2)%10; break;
case 4 : i = (j+3)%10; break;
case 5 : i = (j+4)%10; break;
case 6 : i = (j+5)%10; break;
case 7 : i = (j+6)%10; break;
case 8 : i = (j+7)%10; break;
default:;
}
//以下的是新加的小数点显示
if(digbit==j)
temp_DSP7LED[i] = 0x80 + DSP7LED[i];//dsp7led + 1000 0000
else
temp_DSP7LED[i] = DSP7LED[i];
//小数点操作结束
IOA = temp_DSP7LED[i];
IOB = BITTAB[digbit];
if(digbit<7)
digbit = digbit+1;
else
digbit = 0;//扫描显示
// }while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -