Build target 'Target 1'
compiling 單片機DS1302電子打鈴系統 LCD1602顯示.C...
LCD1602.H(163): error C202: 'P1_5': undefined identifier
LCD1602.H(171): error C202: 'P1_5': undefined identifier
LCD1602.H(183): error C202: 'P1_5': undefined identifier
LCD1602.H(191): error C202: 'P1_5': undefined identifier
LCD1602.H(198): error C202: 'P1_5': undefined identifier
LCD1602.H(212): error C202: 'P1_7': undefined identifier
LCD1602.H(217): error C202: 'P1_7': undefined identifier
LCD1602.H(225): error C202: 'P1_7': undefined identifier
單片機DS1302電子打鈴系統 LCD1602顯示.C(1312): warning C316: unterminated conditionals
Target not created
源代碼為
#ifndef _LCD1602_H_
#define _LCD1602_H_
#define uchar unsigned char
#define uint unsigned int
#define data_1602 P0
uchar code table_num[]="0123456789abcdefg";
sbit rs=P2^5; //暫存器選擇信號 H:資料暫存器 L:指令暫存器
sbit rw=P2^6; //暫存器選擇信號 H:資料暫存器 L:指令暫存器
sbit e =P2^7; //片選信號 下降沿觸發
/***********************延時函式************************/
void delay_uint(uint q)
{
while(q--);
}
/***********************lcd1602寫命令函式************************/
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P0=com;
delay_uint(3);
e=1;
delay_uint(25);
e=0;
}
/***********************lcd1602寫資料函式************************/
void write_data(uchar dat)
{
e=0;
rs=1;
rw=0;
P0=dat;
delay_uint(3);
e=1;
delay_uint(25);
e=0;
}
/***********************lcd1602初始化設定************************/
void init_1602() //lcd1602初始化設定
{
write_com(0x38); //
write_com(0x0c);
write_com(0x06);
}
/***********************lcd1602上顯示兩位十進制數************************/
void write_sfm1(uchar hang,uchar add,uchar date)
{
if(hang==1)
write_com(0x80+add);
else
write_com(0x80+0x40+add);
write_data(0x30+date % 10);
}
/***********************lcd1602上顯示兩位十進制數************************/
void write_sfm2_ds1302(uchar hang,uchar add,uchar date)
{
uchar shi,ge;
if(hang==1)
write_com(0x80+add);
else
write_com(0x80+0x40+add);
shi=date/16;
ge=date%16;
write_data(table_num[shi]);
write_data(table_num[ge]);
}
/***********************lcd1602上顯示這字符函式************************/
void write_string(uchar hang,uchar add,uchar *p)
{
if(hang==1)
write_com(0x80+add);
else
write_com(0x80+0x40+add);
while(1)
{
if(*p == '\0') break;
write_data(*p);
p++;
}
}
/*****************控制游標函式********************/
void write_guanbiao(uchar hang,uchar add,uchar date)
{
if(hang==1)
write_com(0x80+add);
else
write_com(0x80+0x40+add);
if(date == 1)
write_com(0x0f); //顯示游標并且閃爍
else
write_com(0x0c); //關閉游標
}
/****************開機液晶顯示函式 初始化液晶的內容********************************/
void init_1602_dis_csf() //初始化液晶
{
write_string(1,0," : : W: ");
write_string(2,0," 20 - - ");
}
#ifndef _LED_H_
#define _LED_H_
unsigned char flag_beep_en;
//定義小車驅動模塊輸入IO口
sbit IN3=P1^5;
sbit IN4=P1^6;
sbit EN2=P1^7;
#define Right_moto_pwm P1_7 //PWM信號端
#define Right_moto_go {P1_5=1,P1_6=0;} //右邊電機向前走
#define Right_moto_back {P1_5=0,P1_6=1;} //右邊電機向后走
#define Right_moto_Stop {P1_5=0,P1_6=0;} //右邊電機停轉
unsigned char pwm_val_right =0;
unsigned char push_val_right=0;// 右電機占空比N/20
bit Right_moto_stop=1;
unsigned int time3=0;
//前速前進
void run(void)
{
push_val_right=35;
Right_moto_go ; //右電機往前走
flag_beep_en = 0;
}
void run_1(void)
{
push_val_right=3;
Right_moto_go ; //右電機往前走
flag_beep_en = 0;
}
//前速后退
void back(void)//后退
{
push_val_right=35;
Right_moto_back ; //右電機往前走
flag_beep_en = 0;
}
void back_1(void)//后退
{
push_val_right=3;
Right_moto_back ; //右電機往前走
flag_beep_en = 0;
}
//停止
void stop(void)
{
Right_moto_Stop;
flag_beep_en = 0;
}
/******************************************************************/
/* 右電機調速 */
void pwm_out_right_moto(void)
{
if(Right_moto_stop)
{
if(pwm_val_right<=push_val_right)
{
Right_moto_pwm=1;
}
else
{
Right_moto_pwm=0;
}
if(pwm_val_right>=40)
pwm_val_right=0;
}
else
{
Right_moto_pwm=0;
}
}
/***************************************************/
///*TIMER0中斷服務子函式產生PWM信號*/
/*
void timer0()interrupt 1 using 2
{
TH0=0XFc; //1Ms定時
TL0=0X18;
time3++;
pwm_val_right++;
pwm_out_right_moto();
}
*/
/*********************************************************************/
#endif
uj5u.com熱心網友回復:
下面的宏定義錯誤#define Right_moto_pwm P1_7 //PWM信號端
#define Right_moto_go {P1_5=1,P1_6=0;} //右邊電機向前走
#define Right_moto_back {P1_5=0,P1_6=1;} //右邊電機向后走
#define Right_moto_Stop {P1_5=0,P1_6=0;} //右邊電機停轉
uj5u.com熱心網友回復:
樓上說的對,這里要用 ; 而非 ,#define Right_moto_go {P1_5=1; P1_6=0;}
uj5u.com熱心網友回復:
你的P1_5、P1_7沒有定義sbit P1_5=P1^5;
sbit P1_7=P1^7;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/37457.html
標籤:單片機/工控
上一篇:單片機
