我写的51单片机程序,现在不会写调节时间程序,请大神帮忙指点,谢谢
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
sbit key1=P2^0; //功能键
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
uint num1=0; //功能键按键次数
uint num,num2,num3,num4;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90}; //不带小数点数组
uchar code table1[]=
{0x40,0x79,0x24,0x30,0x19,
0x12,0x02,0x78,0x00,0x10}; //带小数点数组
void delayms(uint xms);
void keyscan(void);
void display();
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint num)
{
uint qian,bai,shi,ge;
qian=num/1000;
bai= num/100%10;
shi= num/10%10;
ge = num%10;
wei1=0;
wei2=1;
wei3=1;
wei4=1;
P1=table[ge];
delayms(1);
wei1=1;
wei1=1;
wei2=0;
wei3=1;
wei4=1;
P1=table[shi];
delayms(1);
wei2=1;
wei1=1;
wei2=1;
wei3=0;
wei4=1;
P1=table1[bai];
delayms(1);
wei3=1;
wei1=1;
wei2=1;
wei3=1;
wei4=0;
P1=table[qian];
delayms(1);
wei4=1;
}
void keyscan(void)
{
if((key2==0)) //start or stop
{
delayms(10);
if(key2==0)
{
while(!key2);
TR0=0;
}
if(key2==0)
{
while(!key2);
TR0=1;
}
}
if(key1==0)
{
delayms(10);
if(key1==0)
{
num1++;
while(!key1);
}
}
if((key3==0)&&(num1==2)) //秒表加减1ms,调节小数点后时间,我不会写
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==2))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
if((key3==0)&&(num1==3)) //秒表加减1s,调节小数点前面时间
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==3))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
}
void main()
{
TMOD=0x01;
TH0=(65535-4587)/256;
TL0=(65535-4587)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(num2);
keyscan();
}
}
void T1_time() interrupt 1
{
TH0=(65536-4587)/256;
TL0=(65536-4587)%256;
num3++;
if(num3==2)
{
num3=0;
num2++;
if(num3==10000)
{
num3=0;
}
}
}
#define uint unsigned int
#define uchar unsigned char
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
sbit key1=P2^0; //功能键
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
uint num1=0; //功能键按键次数
uint num,num2,num3,num4;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90}; //不带小数点数组
uchar code table1[]=
{0x40,0x79,0x24,0x30,0x19,
0x12,0x02,0x78,0x00,0x10}; //带小数点数组
void delayms(uint xms);
void keyscan(void);
void display();
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint num)
{
uint qian,bai,shi,ge;
qian=num/1000;
bai= num/100%10;
shi= num/10%10;
ge = num%10;
wei1=0;
wei2=1;
wei3=1;
wei4=1;
P1=table[ge];
delayms(1);
wei1=1;
wei1=1;
wei2=0;
wei3=1;
wei4=1;
P1=table[shi];
delayms(1);
wei2=1;
wei1=1;
wei2=1;
wei3=0;
wei4=1;
P1=table1[bai];
delayms(1);
wei3=1;
wei1=1;
wei2=1;
wei3=1;
wei4=0;
P1=table[qian];
delayms(1);
wei4=1;
}
void keyscan(void)
{
if((key2==0)) //start or stop
{
delayms(10);
if(key2==0)
{
while(!key2);
TR0=0;
}
if(key2==0)
{
while(!key2);
TR0=1;
}
}
if(key1==0)
{
delayms(10);
if(key1==0)
{
num1++;
while(!key1);
}
}
if((key3==0)&&(num1==2)) //秒表加减1ms,调节小数点后时间,我不会写
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==2))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
if((key3==0)&&(num1==3)) //秒表加减1s,调节小数点前面时间
{
delayms(10);
if(key3==0)
{
while(!key3);
}
}
if((key4==0)&&(num1==3))
{
delayms(10);
if(key4==0)
{
while(!key4);
}
}
}
void main()
{
TMOD=0x01;
TH0=(65535-4587)/256;
TL0=(65535-4587)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(num2);
keyscan();
}
}
void T1_time() interrupt 1
{
TH0=(65536-4587)/256;
TL0=(65536-4587)%256;
num3++;
if(num3==2)
{
num3=0;
num2++;
if(num3==10000)
{
num3=0;
}
}
}
调节时间程序? 没明白到底啥意思。
谢谢
记得是在按键扫描程序里面写吧
程序写的真恶心看的,要格式没格式,要简介没简介。哪里还用定义wei?哪里还需要定义带小数点的数组?
这貌似是作业?
嗯,思路最重要!别急,慢慢想一下就明白了。
再说两句:不要受评论的影响,爷爷也是从孙子过来的!你遇到的问题是学习当中必然要遇到的,整理一下你的思路相信你可以写好的。
你是不是没见过8段数码管.....
没有注释 看不懂
赞同!顶一下