#include
#define uint unsigned int
#define uchar unsigned char
#define ZKB 6 //占空比初始值设定
#define max_time 100 //设置超出时刻
sbit gd1=P1^0; //光电开关被挡住是高电平,没有被挡住是低电平
sbit gd2=P1^1; //光电开关被挡住是高电平,没有被挡住是低电平
sbit en=P1^2; //步进电机使能端,高电平作业,低电平不作业
sbit zx=P1^3; //高电平步进电机正转,低电平步进电机回转
sbit clock=P1^4; //步进电机频率端口
sbit lcdrs=P2^3; //LCD1602端口界说
sbit lcdrw=P2^4; //LCD1602端口界说
sbit lcden=P2^5; //LCD1602端口界说
uchar k=0;
uchar j=0;
uchar flag=0; //标志位
uint avr_time; //界说均匀时刻
uchar num; //界说液晶显现循环变量
uint zheng=0,fan=0; //正回转次数置零
uint shijian[51]; //界说时刻数组
uchar code table2[]=”forward: “; //LCD1602显现数组
uchar code table3[]=”backward: “; //LCD1602显现数组
uchar code table4[]=” error! “; //LCD1602显现数组
void timer_init()
{
}
uint data_pro(void)
{
}
void delay_50us(uint t)
{
uint y;
for(;t>0;t–)
for(y=19;y>0;y–);
}
void write_com(uchar com)
{
lcdrs=0;
lcdrw=0;
lcden=0;
P0=com;
delay_50us(10);
lcden=1;
delay_50us(20);
lcden=0;
}
void write_data(uchar date)
{
lcden=0;
lcdrs=1;
lcdrw=0;
P0=date;
delay_50us(10);
lcden=1;
delay_50us(20);
lcden=0;
}
void init()
{
write_com(0x38);
delay_50us(100);
delay_50us(100);
write_com(0x06);
delay_50us(100);
delay_50us(100);
}
void write_zheng(uchar add,uchar date)
{
uchar qian,bai,shi,ge;
qian=date/1000;
bai=date00/100;
shi=date0/10;
ge=date;
write_com(0x80+add);
write_data(0x30+qian);
write_data(0x30+bai);
write_data(0x30+shi);
write_data(0x30+ge);
}
void write_fan(uchar add,uchar date)
{
uchar qian,bai,shi,ge;
qian=date/1000;
bai=date00/100;
shi=date0/10;
ge=date;
write_com(0x80+0x40+add);
write_data(0x30+qian);
write_data(0x30+bai);
write_data(0x30+shi);
write_data(0x30+ge);
}
void main()
{
}
avr_time=data_pro();
write_zheng(12,zheng); //显现修改后,正转次数
}
{
}
}
void timer0() interrupt 1
{
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
k++;
}