基于51單片機家具門屜耐用性自動檢測裝置程序設(shè)計
#define uint unsigned int
#define uchar unsigned char
#define ZKB 6 //占空比初始值設(shè)定
#define max_time 100 //設(shè)置超出時間
sbit gd1=P1^0; //光電開關(guān)被擋住是高電平,沒有被擋住是低電平
sbit gd2=P1^1; //光電開關(guān)被擋住是高電平,沒有被擋住是低電平
sbit en=P1^2; //步進電機使能端,高電平工作,低電平不工作
sbit zx=P1^3; //高電平步進電機正轉(zhuǎn),低電平步進電機反轉(zhuǎn)
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; //定義液晶顯示循環(huán)變量
uint zheng=0,fan=0; //正反轉(zhuǎn)次數(shù)置零
uint shijian[51]; //定義時間數(shù)組
uchar code table2[]="forward: "; //LCD1602顯示數(shù)組
uchar code table3[]="backward: "; //LCD1602顯示數(shù)組
uchar code table4[]=" error! "; //LCD1602顯示數(shù)組
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); //顯示修改后,正轉(zhuǎn)次數(shù)
}
{
}
}
void timer0() interrupt 1
{
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%6;
k++;
}
評論