/*******************/
/* Designed By YYQ */
/*******************/
#include "STC15W4Kxx.H"
#define DATA_PORT P0//并行口数据线选定P0
#define CYCLE 0x7FFFL //PWM周期
#define DUTY10 20L //占空比设置
/*****************************/
/******12864功能引脚定义******/
sbit LCD12864_EN = P2^2;
sbit LCD12864_RSET = P2^4;
sbit LCD12864_RS = P2^0;
sbit LCD12864_RW = P2^1;
sbit LCD12864_PSB = P2^3;
/*****************************/
/*******超声波引脚定义********/
sbit Trig=P1^4;
sbit Echo=P1^5;
/*****************************/
/********L298N引脚定义********/
sbit IN1 = P1^0;
sbit IN2 = P1^7;
sbit IN3 = P1^2;
sbit IN4 = P1^3;
/*****************************/
sbit ACK = P2^7; //确认按键定义
sbit SR04_Sta = P2^6; //超声波状态定义
sbit BlueTooth_Sta = P2^5; //蓝牙状态定义
sbit Ctrl = P1^6; //控制模式按键定义
bit Ctrl_Flag = 0;//控制模式标志 0:超声波自动避障 1:蓝牙控制
unsigned char rxbuf;//串口数据寄存
unsigned int time;//超声波定时
unsigned long dist;//距离
unsigned char DisplayBuffer[4]={0,0,0,0};//12864显示距离数组
unsigned char cnt;//预留计数器,程序中基本无用
unsigned long count0;
unsigned long count1;
const unsigned char binli[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 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FF,0xFF,0xF8,0x0F,0x0F,0x7F,0xFB,0xFF,0xE0 ,
0xE0,0x00,0x00,0x00,0x3C,0x78,0xFF,0xFF,0x00,0x00,0x0F,0x0F,0x7F,0xF1,0xFF,0xE0 ,
0xE0,0x00,0x00,0x00,0x3C,0x78,0x7F,0x00,0x00,0x00,0x0F,0x0F,0x7F,0xE0,0xFF,0xE0 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
};//开机绘图数组
void delay(unsigned int x) //11.0592晶振
{
unsigned int i,j;
for(j=0;j<x;j++)
for(i=0;i<110*9;i++);
}//延时函数,110*9原因:110是因为用了11.0592晶振,*9是由于这种单片机比常规51单片机速度快约10倍
/*以下为12864功能函数定义*/
bit LcdBusyCheck()//忙检测
{
bit result;
LCD12864_RS = 0;
LCD12864_RW = 1;
LCD12864_EN = 1;
result = (bit)(DATA_PORT&0x80);
LCD12864_EN = 0;
return result;
}
void WriteCmdToLCD(unsigned char cmd)//写命令
{
delay(10);
LCD12864_RS=0;
LCD12864_RW=0;
LCD12864_EN=1;
DATA_PORT=cmd;
delay(5);
LCD12864_EN=0;
delay(5);
LCD12864_EN=1;
}
void WriteDatToLcd(unsigned char dat)//写数据
{
delay(10);
LCD12864_RS=1;
LCD12864_RW=0;
LCD12864_EN=1;
DATA_PORT=dat;
delay(5);
LCD12864_EN=0;
delay(5);
LCD12864_EN=1;
}
void WriteStrToLcd(unsigned char *str)//写数据串,采用指针方式
{
while(*str != '\0')
{
WriteDatToLcd(*str++);
delay(5);
}
}
void WriteCharToLcd(unsigned char c)//写单个字符
{
WriteDatToLcd(c);
delay(5);
}
void LcdPos(unsigned char x,unsigned char y)//设定12864的显示坐标
{
unsigned char pos;
if(x == 1)
{
x = 0x80;
}
else if(x == 2)
{
x = 0x90;
}
else if(x == 3)
{
x = 0x88;
}
else if(x == 4)
{
x = 0x98;
}
评论1