2019-07-18 11:49发布
longzhoubin 发表于 2015-9-10 20:34 #include #include #define uint unsigned int
最多设置5个标签!
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define duan P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uint displaydate[8] = {0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
uchar code GPIO_DIG_CODE[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
uchar time=0,miao=0,NUM=0;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void TimerConfiguration()
{
TMOD = 0x11; //打开两个中断方式1和3
TH0 = 0x3C; //设置初始值,
TL0 = 0xB0;
TH1=0Xf6; //打开终端1
TL1=0Xf6;
ET1=1;
TR1=1;
//打开定时器0中断
TR0 = 1; //启动定时器0
EA = 1; //打开总中断
}
void Timer0() interrupt 1
{
TH0 = 0x3C; //设置初始值
TL0 = 0xB0;
time++;
if(time==20)
{
time=0;
miao++;
if(miao==60)
miao=0;
}
}
void display() interrupt 3
{
TH1=0Xf6;
TL1=0Xf6;
duan=0x00;
switch(NUM)
{
case(0):
LSA=0;LSB=0;LSC=0; break;//显示第0位
case(1):
LSA=1;LSB=0;LSC=0; break;//显示第1位
}
duan=displaydate[NUM];
NUM++;
if(NUM>1)
{
NUM=0;
}
}
void main()
{
TimerConfiguration();
while(1)
{
if(key1==0)
{
delayms(100);
if(key1==0);
ET0 = 1;
}
if(key2==0)
{
delayms(100);
if(key2==0)
ET0 = 0;
}
if(key3==0)
{
delayms(100);
if(key3==0)
miao=0;
}
displaydate[0]=GPIO_DIG_CODE[miao/10];
displaydate[1]=GPIO_DIG_CODE[miao%10];
}
}
感谢你的热心帮助!
一周热门 更多>