有沒有大佬幫忙看一下,真的不會改了 這是源代碼
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code segdata[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
uchar dispbitcode[]={0xfe,0xfd,0xbf,0x7f};
uchar key,xuanshou;
uchar sec,cnt,sectemp,i;
uchar flag=0;
bit qiangda=0,shezhi=0,inc=0,dec=0;
void delayms(uint n)
{
uchar i;
while(n--)
for(i=0;i<113;i++);
}
void Timer0Init(void)
{
TMOD=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
TF0=0;
TR0=1;
ET0=1;
EA=1;
}
void timer0() interrupt 1
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
i++;
if(i==9)
i=1;
void disp(void);
}
void keyscan()
{
uchar temp,i;
P2=0X0F;
temp=P2&0x0F;
if(temp!=0x0F)
{
for(i=0;i<200;i++);
temp=P2&0x0F;
if(temp!=0x0F)
{
P2=0XF7;
temp=P2&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0x70:key=9;break;
case 0xb0:key=10;break;
case 0xd0:key=11;break;
case 0xe0:key=12;break;
}
}
while((P2&0XF0)!=0XF0);
P2=0xfb;//2
temp=P2&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0x70:key=8;break;
case 0xb0:key=7;break;
case 0xd0:key=6;break;
case 0xe0:key=5;break;
}
}
P2=0xfd;//3
temp=P2&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0x70:key=4;break;
case 0xb0:key=3;break;
case 0xd0:key=2;break;
case 0xe0:key=1;break;
}
}
while((P2&0XF0)!=0XF0);
}
void disp(void)
{
P0=dispbitcode[0];
P1=segdata[sec/10];
delayms(2);
P0=dispbitcode[1];
P1=segdata[sec%10];
delayms(2);
P0=dispbitcode[2];
P1=segdata[xuanshou/10];
delayms(2);
P0=dispbitcode[3];
P1=segdata[xuanshou%10];
delayms(2);
}
}
void flash_disp(void)
{
uchar i;
for(i=0;i<50;i++)
{
P0=dispbitcode[0];
P1=segdata[sec/10];
delayms(2);
P0=dispbitcode[1];
P1=segdata[sec%10];
delayms(2);
P0=dispbitcode[2];
P1=segdata[xuanshou/10];
delayms(2);
P0=dispbitcode[3];
P1=segdata[xuanshou%10];
delayms(2);
}
for(i=0;i<50;i++)
{
P0=dispbitcode[2];
P1=segdata[xuanshou/10];
delayms(2);
P0=dispbitcode[3];
P1=segdata[xuanshou%10];
delayms(2);
}
}
|