单片机程序
#include<reg51.h>
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit START=P1^0;//开始
sbit STOP=P1^1;//停止
sbit RESET=P1^2;//复位
sbit dp=P0^7;
sbit w1=P2^6;
sbit w2=P2^7;
uchar aa,temp,STOPFLAG,STARTFLAG,miaoshi,miaoge;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳极数码表
void display(uchar temp);
void delay(uint z);
void init();
void main()
{
init();
temp=0;
if(START==0)
STARTFLAG=1;//开始标志
while(STARTFLAG==1)
{
if(aa==20)//中断20次即每秒加1
{
aa=0;
temp++;
if(temp== 60)
{
temp=0;
}
}
if(STOP==0)
{
STOPFLAG=1;//停止标志
while(STOPFLAG==1)
{
TR0=0;
display(temp);
if(START==0)
break; //退出停止即继续计时
if(RESET==0)//复位清零
{
temp=0;
display(temp);
}
}
}
if(STOP!=0)//继续计时判断
{
TR0=1;
STOPFLAG=0;
}
display(temp);
}
}
void delay(uint z)//延时函数
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar temp)//秒显示
{
miaoshi=temp/10;
miaoge=temp%10;
w1=1;
P0=table[miaoshi];
delay(2);
w1=0;
w2=1;
P0=table[miaoge];
delay(2);
w2=0;
}
void init()//定时器初始化
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0()interrupt 1//定时器T0中断服务子程序
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
想请问一下这个程序怎么改成共阴,位选怎么加进去,急!!!
|