步进电机LCD显示可设定转数程序
#include <reg51.h> //51芯片管脚定义头文件
#include <intrins.h> //内部包含延时函数 _nop_();
#define uchar unsigned char
#define uint unsigned int
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
uchar code FFW[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};
uchar code REV[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};
sbit K1 = P1^4; //运行与停止
sbit K2 = P1^5; //设定圈数
sbit K3 = P1^6; //方向转换
sbit K4 = P1^7; //速率调整
sbit BEEP = P3^7; //蜂鸣器
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_EN = P2^2;
bit on_off=0; //运行与停止标志
bit direction=1; //方向标志
bit rate_dr=1; //速率标志
bit snum_dr=1; //圈数标志
uchar code cdis1[ ] = {" STEPPING MOTOR "};
uchar code cdis2[ ] = {"CONTROL PROCESS"};
uchar code cdis3[ ] = {" STOP "};
uchar code cdis4[ ] = {"NUM: RATE: "};
uchar code cdis5[ ] = {" RUNNING "};
uchar m,v=0,q=0;
uchar number=0,number1=0;
uchar snum=5,snum1=5; //预设定圈数
uchar rate=8; //预设定速率
uchar data_temp,data_temp1,data_temp2;
/********************************************************/
/*
/* 延时t毫秒
/* 11.0592MHz时钟,延时约1ms
/*
/********************************************************/
void delay(uint t)
{
uchar k;
while(t--)
{
for(k=0; k<125; k++)
{ }
}
}
/********************************************************/
void delayB(uchar x) //x*0.14MS
{
uchar i;
while(x--)
{
for (i=0; i<13; i++)
{ }
}
}
/********************************************************/
void beep()
{
uchar j;
for (j=0;j<100;j++)
{
delayB(4);
BEEP=!BEEP; //BEEP取反
}
BEEP=1; //关闭蜂鸣器
delay(170);
}
/********************************************************/
/*
/*检查LCD忙状态
/*lcd_busy为1时,忙,等待。为0时,闲,可写指令与数据。
/*
/********************************************************/
bit lcd_busy()
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delayNOP();
result = (bit)(P0&0x80);
LCD_EN = 0;
return(result);
}
/********************************************************/
/*
/*写指令数据到LCD
上一篇:继电器定时器程序