摁摁钮(接P3.4口)无法实现点阵管播放速度调节。
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
sfr P4SW=0xBB;
sfr P4=0xC0;
sbit P44=P4^4;
bit Hold=1;
bit ldelay=0;
uchar t=0,count=20;
typedef unsigned char uint8;
typedef char int8;
typedef unsigned int uint16;
#define COL_PORT P0
#define ROW_PORT P2
void Int0_srv() interrupt 0{
Hold=!Hold;
}
timer0() interrupt 3{
t++;
if(t==count) {t=0;ldelay=1;}
TH1=0x3c; TL1=0xb0;
}
speed0() interrupt 1{
count+=40;
if(count==140) count=20;
}
uint8 code DotTable1[][8]=
{
0x00,0x10,0x7c,0x54,0x38,0x28,0x28,0x00,
0x6c,0x54,0x7c,0x10,0x38,0x6c,0x00,0x00,
0x00,0x00,0x00,0x3e,0x24,0xe4,0x00,0x00,
0x00,0x14,0x7c,0x50,0x3e,0x20,0x20,0x00,
0x44,0x54,0x7c,0x10,0x38,0x28,0x28,0x00,
0x02,0x6a,0x3e,0x48,0x7c,0x04,0x04,0x04
};
uint8 code DotTable2[][8]=
{
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x28,0x10,0x00,0x00,0x00,
0x00,0x38,0x54,0x6c,0x54,0x38,0x00,0x00,
0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,
0x54,0xaa,0x44,0x82,0x44,0xaa,0x54,0x00,
0x54,0x82,0x00,0x82,0x00,0x82,0x54,0x00
};
void Delay(int ms);
void LedDotRefresh1();
void LedDotRefresh2();
uint8 LedDotDispBuff;
void main(){
uint8 i;
P4SW |=0x70;
P44=0;
TMOD=0x16;
TH1=0X3c;
TL1=0xb0;
TH0=TL0=0xFF;
IT0=1;
EX0=1;
TR0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
while(1){
if(Hold){
if(ldelay){
ldelay=0;
for(LedDotDispBuff=6;LedDotDispBuff!=0xff;LedDotDispBuff--)
for(i=0;i<1000/8;i++)
LedDotRefresh1();
}
}
else{
if(ldelay){
ldelay=0;
for(LedDotDispBuff=6;LedDotDispBuff!=0xff;LedDotDispBuff--)
for(i=0;i<1000/8;i++)
LedDotRefresh2();
}
}
}
void LedDotRefresh1()
{
uint8 i;
for(i=0;i<8;i++)
{
COL_PORT=~DotTable1[LedDotDispBuff][i];
ROW_PORT=0xF0+i;
Delay(1);
ROW_PORT=0xF8;
}
}
void LedDotRefresh2()
{
uint8 i;
for(i=0;i<8;i++)
{
COL_PORT=~DotTable2[LedDotDispBuff][i];
ROW_PORT=0xF0+i;
Delay(1);
ROW_PORT=0xF8;
}
}
void Delay(int ms)
{
uint16 i;
do{
i=790;
while(--i);
} while(--ms);
}