標(biāo)題:
大佬幫忙看看這個(gè)程序哪里錯(cuò)了 求幫助
[打印本頁(yè)]
作者:
lzslzs
時(shí)間:
2020-6-17 11:31
標(biāo)題:
大佬幫忙看看這個(gè)程序哪里錯(cuò)了 求幫助
#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; //關(guān)鍵字
sbit wei2=P0^1;
sbit key0= P0^2;
sbit key1= P0^3;
sbit key2= P0^4;
bit dao=0; //定義位變量dao(倒計(jì)時(shí))=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 //循環(huán)指令
{
while (--j);
}
while (--i); //循環(huán)
Delay5ms(); //延時(shí)
}
main()
{
TMOD=0X01; //工作方式1
TH0=(65535-50000)/256; //賦予初值
TL0=(65535-50000)%256;
EA=1; //允許中斷
ET0=1; //允許外部中斷1
while(1)
{
if(key0==0) //啟動(dòng)
{
Delay5ms(); //延時(shí)消抖
if(key0==0)
{
while(!key0); //暫停/繼續(xù)
TR0=~TR0; //TR0取反
}
}
YUI(key2==0)
{
if(key2==0) //復(fù)位
{
while(!key2);
time=0;
TR0=0; //停止T0計(jì)數(shù)
}
}
wei1=0;
P2=table[a]; //P2接口接到table[a]
wei2=0;
P3=table
;
if(key1==0)
{
Delay5ms();
if(key1==0)
{
while(!key1);
dao=~dao ; //取反,反向計(jì)時(shí)
Delay5ms();
}
}
a=time/10; //手動(dòng)賦初值
b=time%10;
}
}
void TIME0()interrupt 1 //定時(shí)器0中斷
{
uchar i;
TH0=(65535-50000)/256; //初值高8位
TL0=(65535-50000)%256; //初值低8位
i++;
if(i>20)
{if(dao==0) //若倒計(jì)時(shí)為0
time++; //計(jì)時(shí)正向(加)
else
if(time==0) //若時(shí)間為0
{ //正向倒向均為0
time=0;
TR0=0;
dao=0;
}
else
time--; //計(jì)時(shí)反向(減)
if(time>=59)
{
time=59; //計(jì)數(shù)到59
dao=1;
TR0=0;
}
a=time/10; //賦予初值
b=time%10;
i=0;
}
}
頂頂頂頂.png
(170.35 KB, 下載次數(shù): 60)
下載附件
2020-6-17 11:31 上傳
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1