内容发布更新时间 : 2024/11/14 13:20:52星期一 下面是文章的全部内容请认真阅读。
word专业整理
附录: 附录一
主控板和小车整体实物图:
学习资料 整理分享
word专业整理
附录二
单片机程序: #include \#include
#define uchar unsigned char //宏定义无符号字符型
#define uint unsigned int //宏定义无符号整型 #define LCD_Data P0
#define Busy 0x80 //检测LCD状态字中的Busy标识
/********IO引脚定义*******/ sbit LCD_E =P2^7; sbit LCD_RW=P2^6; sbit LCD_RS=P2^5; //定义引脚
sbit RX =P1^6;
//模块超声波模块ECH0 接 P1^3 sbit TX =P1^7;
// 超声波模块Trig 接 P1^4 sbit IN1=P1^0; sbit IN2=P1^1; sbit IN3=P1^2; sbit IN4=P1^3; sbit EN1=P1^4; sbit EN2=P1^5;
学习资料 整理分享
unsigned char code net[] = {\JLCM \
unsigned char code forward[] = {\ford \
unsigned char code back[] = {\back \
unsigned char code left[] = {\left \
unsigned char code right[] = {\righ \
unsigned char code stop[] = {\stop \
unsigned char code Clef[] = {\Clef \
unsigned int time=0; unsigned long S=0; bit flag =0,flagg=0; unsigned
char l_disbuff[4]={ 0,0,0,0,};
//显示缓冲
uchar date;
uchar rec,startmove=0; uchar x,speed=100,speed2; uchar ii; uchar sudu;
word专业整理
uint mm,mmm;
LCD_Data = WDLCD; LCD_RS = 1;
void delayms(unsigned int timer) LCD_RW = 0;
//毫秒延时
{ int x,y;
for(x=timer;x>0;x--)
for(y=120;y>0;y--); }
/***********读状态*****/
unsigned char ReadStatusLCD(void) {
LCD_Data = 0xFF; LCD_RS = 0; LCD_RW = 1; LCD_E = 0; LCD_E = 0; LCD_E = 1;
while (LCD_Data & Busy);
//检测忙信号
return(LCD_Data); }
/***********写数据*******/ void WriteDataLCD(unsigned char WDLCD) {
ReadStatusLCD(); //检测忙
学习资料 整理分享
LCD_E = 0;
//若晶振速度太高可以在这后加
小的延时 LCD_E = 0;
//延时
LCD_E = 1; }
/***********写指令**********/ void
WriteCommandLCD(unsigned
char WCLCD,BuysC)
//BuysC为0时忽略忙检测 {
if (BuysC) ReadStatusLCD();
//根据需要检测忙
LCD_Data = WCLCD; LCD_RS = 0; LCD_RW = 0; LCD_E = 0; LCD_E = 0; LCD_E = 1;
}
/********初始化*****/
void LCDInit(void)
word专业整理
{
LCD_Data = 0;
WriteCommandLCD(0x38,0);
//三次模式设置,不检测忙信
号
delayms(5);
WriteCommandLCD(0x38,0); delayms(5);
WriteCommandLCD(0x38,0); delayms(5);
WriteCommandLCD(0x38,1);
//显示模式设置,开始要求每次检测忙信号
WriteCommandLCD(0x08,1);
//关闭显示
WriteCommandLCD(0x01,1);
//显示清屏
WriteCommandLCD(0x06,1);
//显示光标移动设置
WriteCommandLCD(0x0C,1);
//显示开及光标设置
}
/****按指定位置显示一个字符****/
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData) {
学习资料 整理分享
Y &= 0x1; X &= 0xF;
//限制X不能大于15,Y不能大于1 if (Y) X |= 0x40;
//当要显示第二行时地址码
+0x40;
X |= 0x80;
//算出指令码
WriteCommandLCD(X, 0);
//这里不检测忙信号,发送地址码 WriteDataLCD(DData); }
/******按指定位置显示一串字符**/
void DisplayListChar(unsigned
char X, unsigned char Y, unsigned char code *DData) {
unsigned char ListLength;
ListLength = 0;
Y &= 0x1; X &= 0xF;
//限制X不大于15,Y不大于1
while
(DData[ListLength]>=0x20) {
//若到达字串尾则退出
word专业整理
if (X <= 0xF) {
//X坐标应小于0xF
DisplayOneChar(X,
Y,
DData[ListLength]); //显示单个字符 ListLength++; X++;
}
} }
void Conut(void) { time=TH0*256+TL0; TH0=0; TL0=0; S=(time*1.7)/100;
//算出来是CM if((S>=100)||flag==1)
//超出测量范围显示“-”
{ flag=0;
DisplayOneChar(7, 1,'-');
DisplayOneChar(8, 1,'.');
DisplayOneChar(9, 1,'-');
DisplayOneChar(10,
1,'-');
DisplayOneChar(11,
学习资料 整理分享
1,'m'); } else {
l_disbuff[0]=S00/100+0x30; //加上0X30是将数字转为ASCII
码
l_disbuff[1]=S000/10+0x30; l_disbuff[2]=S00 +0x30; DisplayOneChar(7, 1,l_disbuff[0]);
DisplayOneChar(8, 1,'.');
DisplayOneChar(9,
1,l_disbuff[1]);
DisplayOneChar(10,
1,l_disbuff[2]);
DisplayOneChar(11, 1,'m');
}
if((S<40||flag==1)&(startmove
==1||startmove==2))
{
IN1=1; IN2=0;
IN3=1;
IN4=0;
delayms(5);
EN1=1;
EN2=1;
delayms(50);