本帖最后由 laslison 于 2010-4-15 16:34 编辑
程序如下
数码管不好使,按下键以后老闪,还有就是按下启动后,他等一会才开始计时
我自学单片机已经不短了,还是菜鸟一个
高手们帮我看看
#include <reg52.h>
#define zheng unsigned int
#define xiao unsigned char
sbit duan=P1^2;
sbit w1=P1^3;
sbit w2=P1^4;
sbit w3=P1^5;
sbit w4=P1^6;
sbit w5=P1^7;
sbit zo=P1^0;//正转
sbit fo=P1^1;//反转
sbit gj=P2^0;//功能键
sbit jiaj=P2^4;//加键
sbit jianj=P2^2;//减键
sbit qd=P2^1;//启动键
sbit tz=P2^3;//停止键
xiao tt=0,sj,yqd=0,a=0,b=0,c=0,d=3,e=0,fd=0,fe=2,ff=0,g=0,i=0,j,k,l=0,m=0,n=0,zd=0,ze=2,zf=0,z,zt=0,f=0,jishu=0,jishu1=0;jishu2=0;
xiao code table[]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B,0x7e};//数码管0-9
xiao code qq[]={/*9,*/0x20,/*9,*/0x10,/*9,*/0x08,/*9,*/0x04,/*9,*/0x02,/*9,*/0x40};
void xh1(zheng z);//循环函数定义
void main()
{
P2=0x00;
P3=0x00;
gj=1;
jiaj=1;
jianj=1;
qd=1;
tz=1;
w1=1;
w2=1;
w3=1;
w4=1;
w5=1;
duan=0;
zo=1;
fo=1;
k=1;
TMOD=0x01;//设置定时器0为工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
while(1)
{
if(yqd==1)
{
for(j=1;j<=k;j++)
{
if(yqd==1)
{
sj=zd+ze*10+zf*100;
while(sj>0)
{
if(tt==20)
{
tt=0;
sj--;
m++;
}
a=sj%100%10;
b=sj%100/10;
c=sj/100;
yqd=1;
zo=0;
fo=1;
if(tz==0)
{
sj=0;
}
if(m==6)
m=0;
duan=1;
P3=table[a];
duan=0;
w1=0;
xh1(1);
w1=1;
duan=1;
P3=table;
duan=0;
w2=0;
xh1(1);
w2=1;
duan=1;
P3=table[c];
duan=0;
w3=0;
xh1(1);
w3=1;
duan=1;
P3=qq[m];
duan=0;
w4=0;
xh1(1);
w4=1;
duan=1;
P3=table[yqd];
duan=0;
w5=0;
xh1(1);
w5=1;
}
yqd=2;
zo=1;
fo=1;
}
/*************************/
|
|