#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xBF};
sbit fmq=P3^6;
sbit P2_7=P2^7;
void beef1(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-500)/256; //定时器T1的高8位赋初值
TL1=(65536-500)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-500)/256; //定时器T0的高8位赋初值
TL1=(65536-500)%256; //定时器T0的高8位赋初值
}
}
}
void beef2(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-250)/256; //定时器T1的高8位赋初值
TL1=(65536-250)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-250)/256; //定时器T0的高8位赋初值
TL1=(65536-250)%256; //定时器T0的高8位赋初值
}
}
}
void beef3(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-167)/256; //定时器T1的高8位赋初值
TL1=(65536-167)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-167)/256; //定时器T0的高8位赋初值
TL1=(65536-167)%256; //定时器T0的高8位赋初值
}
}
}
void beef4(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-125)/256; //定时器T1的高8位赋初值
TL1=(65536-125)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-125)/256; //定时器T0的高8位赋初值
TL1=(65536-125)%256; //定时器T0的高8位赋初值
}
}
}
void beef5(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-100)/256; //定时器T1的高8位赋初值
TL1=(65536-100)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-100)/256; //定时器T0的高8位赋初值
TL1=(65536-100)%256; //定时器T0的高8位赋初值
}
}
}
void beef6(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-83)/256; //定时器T1的高8位赋初值
TL1=(65536-83)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-83)/256; //定时器T0的高8位赋初值
TL1=(65536-83)%256; //定时器T0的高8位赋初值
}
}
}
void beef7(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-71)/256; //定时器T1的高8位赋初值
TL1=(65536-71)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-71)/256; //定时器T0的高8位赋初值
TL1=(65536-71)%256; //定时器T0的高8位赋初值
}
}
}
void beef8(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-63)/256; //定时器T1的高8位赋初值
TL1=(65536-63)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-63)/256; //定时器T0的高8位赋初值
TL1=(65536-63)%256; //定时器T0的高8位赋初值
}
}
}
void beef9(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-56)/256; //定时器T1的高8位赋初值
TL1=(65536-56)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-56)/256; //定时器T0的高8位赋初值
TL1=(65536-56)%256; //定时器T0的高8位赋初值
}
}
}
void beef10(void)
{
TMOD=0x10; //使用定时器T1的模式1
TH1=(65536-50)/256; //定时器T1的高8位赋初值
TL1=(65536-50)%256; //定时器T1的高8位赋初值
TR1=1; //启动定时器T1
TF1=0;
while(1)//无限循环等待查询
{
while(TF1==1)
{
TF1=0;
fmq=~fmq; //将P3.6引脚输出电平取反
TH1=(65536-50)/256; //定时器T0的高8位赋初值
TL1=(65536-50)%256; //定时器T0的高8位赋初值
}
}
}
void delay1ms(unsigned int i)
{
uchar j;
while(i--)
{for(j=0;j<115;j++){;}
}
}
void display(unsigned char i)
{
P2=0xbf;;
//选通最右端的数码管显示
P0=tab[i/10]; //显示i参数传来的字型码
delay1ms(5);
P2=0x7f;
P0=tab[i%10];
delay1ms(5);
P2=0xff;
P0=0xff;
delay1ms(5);
}
void main(void)
{
unsigned char temp; uint i,j;
display(16);
while(1)
{
//P1=0xff; //先向P1口写1;端口读状态
P1=0xf0;
temp=P1;
if(temp!=0xf0)
{
delay1ms(15); //消除按键抖动
if(temp!=0xf0)
{
P1=0xfe; //按行进行按键扫描,先扫描第一行
temp=P1;
switch(temp)
{
case(0xee):beef1();for(j=0;j<100;j++)display(1);break;
case(0xde):for(i=0;i<1000;i++)beef2();for(j=0;j<100;j++)display(2);break;
case(0xbe):for(i=0;i<1000;i++)beef3();for(j=0;j<100;j++)display(3);break;
case(0x7e):beef4();for(j=0;j<100;j++)display(4);break;
}
P1=0xfd; //按行进行按键扫描,扫描第二行
temp=P1;
switch(temp)
{
case(0xed):for(i=0;i<1000;i++)beef5();for(j=0;j<100;j++)display(5);break;
case(0xdd):for(i=0;i<1000;i++)beef6();for(j=0;j<100;j++)display(6);break;
case(0xbd):for(i=0;i<1000;i++)beef7();for(j=0;j<100;j++)display(7);break;
case(0x7d):beef8();display(8);break;
}
P1=0xfb; //按行进行按键扫描,扫描第三行
temp=P1;
switch(temp)
{
case(0xeb):for(i=0;i<1000;i++)beef9();for(j=0;j<100;j++)display(9);break;
case(0xdb):for(i=0;i<1000;i++)beef10();for(j=0;j<100;j++)display(10);break;
}
}
}
}
}
|