标题:
新帖求找错,百分之一秒跑表程序
[打印本页]
作者:
541888
时间:
2018-10-10 14:59
标题:
新帖求找错,百分之一秒跑表程序
#include
#define uchar unsigned char
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P27=P0^7;
sbit KS=P1^0; //开始
sbit KR=P1^1; //复位
uchar time,xs,ge,shi,bai,qian;
uchar code tab[ ]= {
0x3F,/*0*/
0x06,/*1*/
0x5B,/*2*/
0x4F,/*3*/
0x66,/*4*/
0x6D,/*5*/
0x7D,/*6*/
0x07,/*7*/
0x7F,/*8*/
0x6F,/*9*/
};
void delay_ms(unsigned int ms) //1ms延时
{
uchar a;
while(ms--)
for(a=123;a>0;a--);
}
void display();
void T0intinit( ) //定时器T0初始化
{
TMOD=0x01;
TH0=(65536-10000)/256; //10ms定时
TL0=(65536-10000)%256;
EA=1;
ET0=1;
}
void main()
{
T0intinit( );
while(1)
{
display( );
while(!KS) //开始/暂停 键
{
display( );
if(KS)
TR0=!TR0;
}
while(!KR) //清零键
{
display( );
if(KR)
TR0=0;
qian=0;
bai=0;
shi=0;
ge=0;
}
if(bai==10)
{
bai=0;
qian++;
}
if(qian==10)
{
qian=0;
TR0=0;
}
}
}
void display( )
{
P23=0;
P0=tab[ge];
delay_ms(1);
P23=1;
P22=0;
P0=tab[shi];
delay_ms(1);
P22=1;
P21=0;
P0=tab[bai]|0x80;
delay_ms(1);
P21=1;
P20=0;
P0=tab[qian];
delay_ms(1);
P20=1;
}
void T0int( ) interrupt 1 //定时器T0中断 方式1
{
TH0=(65536-10000)/256; //重装10ms定时常数
TL0=(65536-10000)%256;
ge++;
if(ge==10)
{
ge=0;
shi++;
}
if(shi==10)
{
shi=0;
bai++;
}
}
作者:
YJGG
时间:
2018-10-10 16:22
#include?
作者:
wulin
时间:
2018-10-10 20:58
你的按键程序有缺陷,给你改了一下,你试试。
#include <AT89X52.H>
#define uchar unsigned char
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
//sbit P27=P0^7;
sbit KS=P1^0; //开始
//sbit KR=P1^1; //复位
uchar zantin=0; //暂停标志
uchar ge=0,shi=0,bai=0,qian=0;
uchar code tab[ ]={
0x3F,/*0*/
0x06,/*1*/
0x5B,/*2*/
0x4F,/*3*/
0x66,/*4*/
0x6D,/*5*/
0x7D,/*6*/
0x07,/*7*/
0x7F,/*8*/
0x6F,/*9*/
};
void delay_ms(unsigned int ms) //1ms延时
{
uchar a;
while(ms--)
for(a=123;a>0;a--);
}
void T0intinit( ) //定时器T0初始化
{
TMOD=0x01;
TH0=(65536-10000)/256; //10ms定时
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
static uchar count2=0,count1=0; //计数变量
static bit key_sign=0; //按键状态标志
if(KS==0) //检测输入如果为0
{
count1++; //计数延时消抖
if((count1>=100)&&(key_sign==0))//检测按键如果为0
{
key_sign=1; //按键状态标志置1,防止重复响应
count2++;
if(count2>=3)
count2=0;
switch(count2)
{
case 0: ge=0;
shi=0;
bai=0;
qian=0; break;//清0
case 1: zantin=1; break;//计时
case 2: zantin=0; break;//暂停
}
}
}
else
{
count1=0; //计数变量清0
key_sign=0; //按键状态标志清0
}
}
void display()
{
P23=0;
P0=tab[ge];
delay_ms(1);
P23=1;
P22=0;
P0=tab[shi];
delay_ms(1);
P22=1;
P21=0;
P0=tab[bai]|0x80;
delay_ms(1);
P21=1;
P20=0;
P0=tab[qian];
delay_ms(1);
P20=1;
}
void main()
{
T0intinit();
while(1)
{
keyscan();
if(bai>=10)
{
bai=0;
qian++;
if(qian>=10)
qian=0;
}
display();
}
}
void T0int( ) interrupt 1 //定时器T0中断 方式1
{
TH0=(65536-10000)/256; //重装10ms定时常数
TL0=(65536-10000)%256;
if(zantin==1)
{
ge++;
if(ge>=10)
{
ge=0;
shi++;
if(shi>=10)
{
shi=0;
bai++;
}
}
}
}
作者:
kiwii
时间:
2018-10-10 22:38
1.#include <AT89x52.H>//添加头文件,keil里也要有
作者:
592292415
时间:
2018-10-12 09:12
1. 没有添加库函数
2. 第58行调用了全局变量
3. 第88行语法错误
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1