标题:
大佬帮忙看看这个程序哪里错了 求帮助
[打印本页]
作者:
lzslzs
时间:
2020-6-17 11:31
标题:
大佬帮忙看看这个程序哪里错了 求帮助
#include<reg51.h>
#include "string.h"
#include "stdio.h"
#include "math.h"
#include <INTRINS.H>
#define uchar unsigned char
#define uint unsigned int
uchar a ,b ,time; //声明变量
sbit wei1=P0^0; //关键字
sbit wei2=P0^1;
sbit key0= P0^2;
sbit key1= P0^3;
sbit key2= P0^4;
bit dao=0; //定义位变量dao(倒计时)=0
uchar code table[]={0x40,0x4f,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18}; //段码表
void Delay5ms() //@12MHz
{
unsigned char i, j;
i =9;
j = 255;
do //循环指令
{
while (--j);
}
while (--i); //循环
Delay5ms(); //延时
}
main()
{
TMOD=0X01; //工作方式1
TH0=(65535-50000)/256; //赋予初值
TL0=(65535-50000)%256;
EA=1; //允许中断
ET0=1; //允许外部中断1
while(1)
{
if(key0==0) //启动
{
Delay5ms(); //延时消抖
if(key0==0)
{
while(!key0); //暂停/继续
TR0=~TR0; //TR0取反
}
}
YUI(key2==0)
{
if(key2==0) //复位
{
while(!key2);
time=0;
TR0=0; //停止T0计数
}
}
wei1=0;
P2=table[a]; //P2接口接到table[a]
wei2=0;
P3=table
;
if(key1==0)
{
Delay5ms();
if(key1==0)
{
while(!key1);
dao=~dao ; //取反,反向计时
Delay5ms();
}
}
a=time/10; //手动赋初值
b=time%10;
}
}
void TIME0()interrupt 1 //定时器0中断
{
uchar i;
TH0=(65535-50000)/256; //初值高8位
TL0=(65535-50000)%256; //初值低8位
i++;
if(i>20)
{if(dao==0) //若倒计时为0
time++; //计时正向(加)
else
if(time==0) //若时间为0
{ //正向倒向均为0
time=0;
TR0=0;
dao=0;
}
else
time--; //计时反向(减)
if(time>=59)
{
time=59; //计数到59
dao=1;
TR0=0;
}
a=time/10; //赋予初值
b=time%10;
i=0;
}
}
顶顶顶顶.png
(170.35 KB, 下载次数: 60)
下载附件
2020-6-17 11:31 上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1