电路图:
protues仿真文件和完好代码下载地址:http://www.51hei.com/bbs/dpj-20399-1.html
下面是部分程序代码:
#include”reg51.h”
#include”intrins.h”
#include”math.h”
#include”absacc.h”
#define PORTA XBYTE[0x8500]
#define PORTB XBYTE[0x8502]
#define PORTC XBYTE[0x8504]
#define PORTC0 XBYTE[0x8506]
#definenop_nop_()
#define Right_RUN 1
#define Left_RUN 0
unsignedlongRunSpeed=76;
unsigned char RUNState=1;
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit P17=P1^7;
bitflag=0;
unsigned char xx[]=”speed(n/min):”;
unsigned char SD[]=”76″;
char state[2][14]={“direction:cw”,”direction:ccw”};
unsigned char FLG,INMA=0;
unsigned char t,s=0x01;
unsigned int a;
main()
{
void OPJIAN();
unsigned char JIAN();
unsigned char JIANZHI();
void speed();
void SHOW_LCD();
void show_state();
void write1();
void writ2(unsigned char i);
void delay();
void time();
void busy();
unsigned char i;
i=0x90;
PORTC0=i;
i=0x01;
TMOD=i;
t=0x10;
a=0x0f;
TH0=0x10;
TL0=0x0f;
FLG=INMA;
SHOW_LCD();
show_state();
EA=1;
ET0=1;
TR0=1;
while(1)
{
i=JIAN();
if(i!=0)
{
time();
time();
}
i=JIAN();
if(i!=0)
{
INMA=JIANZHI();
OPJIAN();
time();
}
if(FLG!=INMA||flag==1)
{ FLG=INMA;
SHOW_LCD();
show_state();
flag=0;
}
}
}
void SHOW_LCD()/*lcd设置程序*/
{
P1=0x38;
write1();
delay();
P1=0x38;
write1();
delay();
P1=0x38;
write1();
delay();
P1=0x01;
write1();
delay();
P1=0x0f;
write1();
delay();
P1=0x06;
write1();
delay();
P1=0x0c;
write1();
}