#include <REG51.H>
//#include <absacc.H>
#define uint unsigned int
#define uchar unsigned char
char t0_val=0;
unsigned char code tabltl0[] ={0x18,0x04,0x18,0x0c
};
unsigned char code tablth0[] ={0xc7,0xd1,0xc0,0xf0
};
unsigned char code tabltl1[] ={0x18,0x0c,0x18,0x04
};
unsigned char code tablth1[] ={0xf9,0xf0,0xc0,0xd1
};
sbit key_h = P3^2;
sbit key_l = P3^3;
sbit output = P1^7;
void my_delay10nms(unsigned int n) //延时函数
{
unsigned i,j;
while(n --)
{
for(i = 128;i > 0;i --)
for(j = 10;j > 0;j --);
}
}
void tcosrv (void) interrupt 3
{ TR1=0;TR0=1;
TH1=tablth1[t0_val];
TL1=tabltl1[t0_val];
output=1;
}
void tc0_srv(void) interrupt 1
{ TR0=1;TR1=1;
TH0=tablth0[t0_val];
TL0=tabltl0[t0_val];
output=0;
}
void main()
{
TMOD=0X00;
TH1=tablth1[t0_val];
TL1=tabltl1[t0_val];
TH0=tablth0[t0_val];
TL0=tabltl0[t0_val];
ET1=1;
ET0 = 1;
TR0 = 1;
TR1=1;
EA=1;
while(1)
{
if(key_h==0)
{
my_delay10nms(10);
if(key_h==0)
{
while(key_h==0);
t0_val++;
if( t0_val>3)
t0_val=3;
}
}
if(key_l==0)
{
my_delay10nms(10);
if(key_l==0)
{
while(key_l==0);
t0_val--;
if(t0_val<0)
t0_val=0;
}
}
}
}
不知道对不对
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>