#include
#define uchar unsigned char
#define uint unsigned int
sbit KEY1= P3^4;
sbit KEY2= P3^5;
sbit KEY3= P3^6;
sbit IN1 = P1^0;
sbit IN2 = P1^1;
sbit ENA = P1^2;
ldata=0x80;
sfr
sbit dula=P2^6;
sbit wela=P2^7;
//sbit
lcden=P3^4;
//uchar timer,ms,t_set = 1;
uchar T_N=100;
uchar T_N1=100;
uchar T_H_N=50;
uchar T_H_N1=50;
void msplay(uchar,uchar);
uchar
x1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//uchar
x2[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar code
//uchar code x4[]={0x01,0x02,0x04,0x08,0x10,0x20};
x3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
code
code
// 延时函数
void delay(uint z)
{
uint x;
for(x=z;x>0;x--);
}
void Key_Scan()
{
if(KEY1== 0)
{
delay(20);
while(!KEY1);
T_H_N++;
if(T_H_N >=99)
{
T_H_N=99;
}
}
if(KEY2== 0)
{
delay(20);
while(!KEY2);
T_H_N--;
if(T_H_N <= 1)
{
T_H_N= 1;
}
}
if(KEY3== 0)
{
delay(15);
while(!KEY3);
IN1=~IN1;
IN2=~IN2;
}
}
void Motor_Init()
{
ENA = 0;
IN1 = 1;
IN2 = 0;
}
void Timer0_Init()
{
TMOD=0X12;
TH0=(256-50);
TL0=(256-50);
TH1=(65535-T_H)/256;
TL1=(65535-T_H)%256;
EA=1;
//
//
ET0=1;
TR0=1;
}
void main()
{
uchar k3,k2,k1,k0;
Timer0_Init();
Motor_Init();
while(1)
{
k2=T_H_N/10;k3=T_H_N%10;
k1=0;k0=0;
msplay(k0,2);
msplay(k1,3);
msplay(k2,4);
msplay(k3,5);
Key_Scan();
}
}
void timer0() interrupt 1
{
//
//
TR0=0;
TH0=(65536-50)/256;
TL0=(65536-50)%256;
T_H_N1--;
if(0==T_H_N1)
{
ENA=0;
T_H_N1=1;
}
T_N1--;
if(T_N1==0)
{
ENA=1;
T_N1=100;
T_H_N1=T_H_N;
}
TR0=1;
}
void msplay(uchar y1,uchar y2)
{
ldata = x1[y1];
dula=1;
dula=0;
delay(1);
ldata = x3[y2];
wela=1;
wela=0;
delay(1);
ldata = 0x00;
dula=1;
dula=0;
delay(1);
ldata = 0x0ff;
wela=1;
wela=0;
delay(1);
}