#include <reg51.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
sbit open = P2^0;
sbit close=P2^1;
sbit swap=P2^2;
sbit sub_speed=P2^4;
sbit add_speed=P2^3;
sbit warning=P2^0;
sbit PWM1=P2^1;
sbit PWM2=P2^2;
/********L298接口定义control******/
sbit MOTOR_A_2=P2^1;
sbit MOTOR_A_1=P2^2;
sbit EN_MOTOR_A=P2^3;
sbit k1=P1^0;
sbit k2=P1^1;
sbit k3=P1^2;
sbit k4=P1^3;
uchar T=0;
uchar W=0;
uchar A=0;
uchar k=10;
uchar table1[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar table2[]={0xfe,0xfb,0xfd,0xf7}
/********液晶显示control******/
sbit E=P2^7;
sbit RW=P2^6;
sbit RS=P2^5;
sbit test=P1^7;
int
time=0;
int high=20;
int period=30;
int change=0;
int flag=0;
int num_medium=0;
int num_display=0;
int count_speed=0;
/************ t0中断******pwm产生****/
void time0_int(void) interrupt 1
{
time++;
TH0=0Xec;
TL0=0x78;
if (change==0)
{
PWM2=1;
if( time==high)
PWM1=0;
else if (time==period)
{
PWM1=1;
time=0;
}
}
else
{
PWM1=1;
if( time == high)
PWM2=0;
else if (time==period)
{
PWM2=1;
time=0;
}
}
}
/**************control**********/
void motor_control()
{
if(open==1)
EA=1;
if(close==1)
EA=0;
if(swap==1)
{
change=~change;
while(swap!=0)
{
}
}
if(sub_speed==1)
{
high++;
if(high==30)
EA=0;
while(sub_speed != 0)
{
}
}
if(add_speed==1)
{
high--;
if(high==5)
high=5;
while(add_speed !=0)
{
}
}
}
/************延时************/
void delay(uchar t)
{
uint i;
while(t)
{
for(i=0;i<125;i++);
t--;
}
}
/*******ding li jun ****/
void wc51r(uchar j)
{
RS=0;
RW=0;
P1=j;
E=1;
E=0;
delay(3);
}
void wc51ddr(uchar j)
{
RS = 1;
RW = 0;
P1 = j;
E = 1;
E = 0;
delay(2);
}
/*****初始化LCD*****/
void init()
{
wc51r(0x01); //清屏
wc51r(0x38); //使用8位数据,显示两行,使用5*7的字型
wc51r(0x0c); //显示器件,光标开,字符不闪烁
wc51r(0x06); //字符不动,光标自动右移一格
}
/********t1中断**********单位时间方波个数********/
void time1_int(void) interrupt 3
{
count_speed++;
if(count_speed==20)
{
count_speed=0;
num_display=num_medium;
num_medium=0;
}
}
/**********速度显示的数据处理********************/
void datamade()
{
wc51r(0xc3);
wc51ddr('V');
wc51ddr('=');
wc51ddr(0x3a);
if(open==1)
{ wc51ddr('o');
wc51ddr('p');
wc51ddr('e');
wc51ddr('n');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
}
if(swap==1)
{ wc51ddr('b');
wc51ddr('i') ;
wc51ddr('a');
wc51ddr('n');
wc51ddr(' ');
wc51ddr('x');
wc51ddr('i');
wc51ddr('a');
wc51ddr('n');
wc51ddr('g');
}
if(sub_speed==1)
{ wc51ddr('v');
wc51ddr('-');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
}
if(add_speed==1)
{ wc51ddr('v');
wc51ddr('+');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
}
if (close==1)
{ wc51ddr('c');
wc51ddr('l');
wc51ddr('o');
wc51ddr('s');
wc51ddr('e');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr(' ');
}
}
/*************** 告警程序**********/
void warning_speed()
{
if(zhuan>100)
{
warning=1;
}
if(zhuan<=100)
{
warning=0;
}
}
void main()
{
P2=0x00;
ET0=1;
ET1=1;
TMOD=0X11;
TH0=0Xec;
TL0=0X78;
TH1=0X3C;
TL1=0Xb0;
TR0=1;
TR1=1;
init(); //lcdcsh
while(1)
{
wc51r(0x80);
wc51ddr('d');
wc51ddr('g');
wc51ddr('u');
wc51ddr('t');
wc51ddr(' ');
wc51ddr('l');
wc51ddr('i');
wc51ddr('j');
wc51ddr('u');
wc51ddr('n');
wc51ddr(' ');
wc51ddr(' ');
wc51ddr('b');
wc51ddr('y');
wc51ddr('s');
wc51ddr('j');
if(test==0)
num_medium++;
datamade();
motor_control();
}
}
错误:Build target 'Target 1'
assembling STARTUP.A51...
compiling LCD.c...
LCD.c(38): error C141: syntax error near 'sbit'
LCD.c(38): error C247: non-address/-constant initializer
LCD.c(247): error C202: 'zhuan': undefined identifier
LCD.c(251): error C202: 'zhuan': undefined identifier
Target not created
求大神指导
一周热门 更多>