汽车倒车雷达源程序lcd12864显示倒车的距离,及当前温度和时间
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- /************* 12864LCD引脚定义 *************/
- #define LCD_data P0 //数据口
- sbit LCD_RS = P2 ^ 4; //寄存器选择输入
- sbit LCD_RW = P2 ^ 5; //液晶读/写控制
- sbit LCD_EN = P2 ^ 6; //液晶使能控制
- sbit LCD_PSB = P2 ^ 1; //串/并方式控制
- uchar address,site;
- bit off;
- /************Ds1302定义*********************/
- #define write_sec 0x80 //写秒
- #define read_sec 0x81 //读秒
- #define write_min 0x82 //写分钟
- #define read_min 0x83 //读分钟
- #define write_hour 0x84 //写小时
- #define read_hour 0x85 //读小时
- #define write_day 0x86 //写日
- #define read_day 0x87 //读日
- #define write_mon 0x88 //写月
- #define read_mon 0x89 //读月
- #define write_week 0x8a //写星期
- #define read_week 0x8b //读星期
- #define write_year 0x8c //写年
- #define read_year 0x8d //读年
- #define write_wp 0x8e //写保护
- void DS1302write_byte(uchar data_a);
- void writeDS1302(uchar addr,uchar da);
- void initDS1302(void);
- void DS1302_time();
- void DS1302_display();
- void assist_display(void);
- void DS1302_key(void);
- void DS1302_add(void);
- void DS1302_reduce(void);
- sbit sclk=P1^5; //DS1302时钟信号
- sbit dio=P1^6; //DS1302数据信号
- sbit rst=P1^7; //DS1302片选
- sbit acc_7=ACC^7;
- sbit key0=P1^1; //设置键
- sbit key1=P1^2; //加键
- sbit key2=P1^3; //减键
- uchar sec,min,hour,day,mon,week,year,time;
- bit set,m,ho,d,mo,w,y,timer,ja,jian;
- uchar install; //设置时钟
- /************Ds18b20定义*********************/
- sbit DQ =P3^6; //定义室内DS18B20通信端口
- uint t,h; //t:读取温度,h:显示延时
- uchar tt,shi,ge,shi0,ge0,shi1,ge1; //tt:处理后的温度,shi:温度十位,ge:温度个位
- void init_18b20(); //复位程序
- void write_18b20(uchar data_a); //写一个字节程序
- void read_t(); //读取温度程序
- void dispose_t(); //处理温度
- void DS18B20_display(); //显示温度
- bit Temp_mark;
- /*****************超声波测距程序定义******************************/
- sbit key3=P1^4;
- sbit led=P3^3;
- sbit buzzer=P2^0;
- bit wave,change;
- uchar times,Q,delayed;
- uint L;
- long int S;
- bit open;
- sbit P1_0=P1^0;
- void ultrasonic_key(void);
- void ultrasonic_display(void);
- void alerting(); //报警
- /*********************************************************/
- unsigned char code DIS1[] =
- {
- '0','1','2','3','4','5','6','7','8','9',' '
- };
- unsigned char code DIS2[] =
- {
- "Date:"
- };
- unsigned char code DIS3[]=
- {
- ':',' ',':',' ',':',' ',':',' ',':',' '
- };
- unsigned char code DIS4[]=
- {
- 'a','m','p'
- };
- unsigned char code DIS5[]=
- {
- "Week:"
- };
- unsigned char code DIS6[]=
- {
- "Monday"
- };
- unsigned char code DIS7[]=
- {
- "Tuesday"
- };
- unsigned char code DIS8[]=
- {
- "Wednesday"
- };
- unsigned char code DIS9[]=
- {
- "Thursday"
- };
- unsigned char code DIS10[]=
- {
- "Friday"
- };
- unsigned char code DIS11[]=
- {
- "Saturday"
- };
- unsigned char code DIS12[]=
- {
- "Sunday"
- };
- unsigned char code DIS13[]=
- {
- "<T>:"
- };
- unsigned char code DIS15[]=
- {
- " "
- };
- unsigned char code Photo0[] =
- {
- /*-- 数字0,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0xFF,0xFF,0x00,
- 0x01,0xFF,0xFF,0x80,0x03,0xFF,0xFF,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x01,0xFF,0xFF,0x80,
- 0x00,0xFF,0xFF,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- /******************************************************************************/
- unsigned char code Photo1[] =
- {
- /*-- 数字1,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x07,0xE0,0x00,
- 0x00,0x0F,0xE0,0x00,0x00,0x1F,0xE0,0x00,0x00,0x3F,0xE0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xE0,0x00,0x03,0xFF,0xFF,0xE0,
- 0x03,0xFF,0xFF,0xE0,0x03,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo2[] =
- {
- /*-- 数字2,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFE,0x00,0x00,0x3F,0xFF,0x00,
- 0x00,0x7F,0xFF,0x80,0x00,0xF0,0x07,0x80,0x00,0xF0,0x07,0x80,0x00,0xE0,0x07,0x80,
- 0x00,0x00,0x07,0x80,0x00,0x00,0x07,0x80,0x00,0x00,0x07,0x80,0x00,0x00,0x07,0x80,
- 0x00,0x00,0x0F,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x78,0x00,
- 0x00,0x00,0xF0,0x00,0x00,0x01,0xE0,0x00,0x00,0x03,0xC0,0x00,0x00,0x07,0x80,0x00,
- 0x00,0x0F,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x78,0x00,0x00,
- 0x00,0xF0,0x00,0x00,0x01,0xF0,0x00,0xE0,0x01,0xF0,0x00,0xE0,0x01,0xFF,0xFF,0xE0,
- 0x01,0xFF,0xFF,0xE0,0x01,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo3[] =
- {
- /*-- 数字3,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xF0,0x00,0x01,0xFF,0xF8,0x00,
- 0x07,0xFF,0xFC,0x00,0x07,0x80,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,
- 0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,
- 0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x01,0xFF,0xFC,0x00,0x01,0xFF,0xF8,0x00,
- 0x01,0xFF,0xFC,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,
- 0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,
- 0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x03,0xC0,0x1E,0x00,0x03,0xFF,0xFC,0x00,
- 0x00,0xFF,0xF8,0x00,0x00,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo4[] =
- {
- /*-- 数字4,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x3C,0x00,
- 0x00,0x00,0x7C,0x00,0x00,0x00,0xFC,0x00,0x00,0x01,0xFC,0x00,0x00,0x03,0xFC,0x00,
- 0x00,0x07,0xBC,0x00,0x00,0x0F,0x3C,0x00,0x00,0x1E,0x3C,0x00,0x00,0x3C,0x3C,0x00,
- 0x00,0x78,0x3C,0x00,0x00,0xF0,0x3C,0x00,0x01,0xE0,0x3C,0x00,0x03,0xC0,0x3C,0x00,
- 0x07,0x80,0x3C,0x00,0x0F,0xFF,0xFF,0xC0,0x0F,0xFF,0xFF,0xC0,0x0F,0xFF,0xFF,0xC0,
- 0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,
- 0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x3C,0x00,
- 0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo5[]=
- {
- /*-- 数字5,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0x80,
- 0x01,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0x80,0x01,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,
- 0x01,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,
- 0x01,0xE0,0x00,0x00,0x01,0xFF,0xFF,0x00,0x01,0xFF,0xFF,0x00,0x01,0xFF,0xFF,0xC0,
- 0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,
- 0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,0x00,0x00,0x07,0xC0,
- 0x00,0x00,0x07,0xC0,0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,0x00,0xFF,0xFF,0xC0,
- 0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo6[]=
- {
- /*-- 数字6,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x03,0xE0,0x00,
- 0x00,0x0F,0xE0,0x00,0x00,0x3F,0x00,0x00,0x00,0xFC,0x00,0x00,0x01,0xF0,0x00,0x00,
- 0x01,0xE0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,
- 0x07,0x80,0x00,0x00,0x07,0x80,0x00,0x00,0x07,0xFF,0xF8,0x00,0x07,0xFF,0xFE,0x00,
- 0x07,0xFF,0xFE,0x00,0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,
- 0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,
- 0x07,0xC0,0x1F,0x00,0x07,0xC0,0x1F,0x00,0x03,0xFF,0xFE,0x00,0x03,0xFF,0xFE,0x00,
- 0x00,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo7[]=
- {
- /*-- 数字7,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xC0,
- 0x01,0xFF,0xFF,0xC0,0x01,0xFF,0xFF,0xC0,0x01,0xC0,0x03,0xC0,0x01,0xC0,0x03,0xC0,
- 0x00,0x00,0x07,0xC0,0x00,0x00,0x0F,0x80,0x00,0x00,0x3E,0x00,0x00,0x00,0x7C,0x00,
- 0x00,0x01,0xF8,0x00,0x00,0x03,0xF0,0x00,0x00,0x03,0xE0,0x00,0x00,0x03,0xC0,0x00,
- 0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,
- 0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,
- 0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,
- 0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo8[]=
- {
- /*-- 数字8,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0xFF,0xFF,0x00,
- 0x01,0xFF,0xFF,0x80,0x03,0xFF,0xFF,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x01,0xFF,0xFF,0x80,
- 0x00,0xFF,0xFF,0x00,0x01,0xFF,0xFF,0x80,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,
- 0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x03,0xE0,0x07,0xC0,0x01,0xFF,0xFF,0x80,
- 0x00,0xFF,0xFF,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo9[]=
- {
- /*-- 数字9,宽度x高度=32x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x7F,0xFF,0x00,
- 0x00,0xFF,0xFF,0x80,0x01,0xFF,0xFF,0xC0,0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,
- 0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,
- 0x01,0xE0,0x07,0xC0,0x01,0xE0,0x07,0xC0,0x01,0xFF,0xFF,0xC0,0x00,0xFF,0xFF,0xC0,
- 0x00,0xFF,0xFF,0xC0,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,
- 0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,
- 0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,0x3F,0xFF,0x80,0x00,0x3F,0xFF,0x00,
- 0x00,0x3F,0xFE,0x00,0x00,0x0F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code Photo10[]=
- {
- /*-- 车,宽度x高度=128x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x10,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x80,0x00,0x20,0x00,0x03,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x80,0x00,0x40,0x00,0x04,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x80,0x00,0x08,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x80,0x01,0x00,0x00,0x10,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x80,0x02,0x00,0x00,0x60,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0xFF,0xFF,0xFF,0xFF,0xC0,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x01,0x00,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,0x00,0x03,0xFF,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x00,0x03,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x80,0x02,0x00,0x00,0x41,
- 0x00,0x00,0x00,0x06,0xA4,0x60,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x42,
- 0x00,0x00,0x00,0x0D,0x12,0x60,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x44,
- 0x00,0x00,0x00,0x11,0x21,0xE0,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x60,0x00,0x48,
- 0x00,0x00,0x00,0x21,0xC3,0xF7,0xF0,0x00,0x00,0x00,0x00,0x87,0xC0,0x60,0x7E,0x50,
- 0x00,0x07,0xFF,0xC1,0x77,0x01,0xF8,0x00,0x00,0x00,0x00,0x8F,0xC0,0xF0,0x63,0x60,
- 0x00,0x0F,0xEB,0x01,0x04,0x00,0x0C,0x00,0x00,0x00,0x00,0x98,0x01,0x98,0x63,0x40,
- 0x00,0x18,0x00,0x08,0x04,0x00,0x06,0x00,0x00,0x00,0x00,0x98,0x01,0x98,0x63,0x40,
- 0x00,0x30,0x00,0x08,0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x98,0x03,0x0C,0x7F,0x40,
- 0x00,0x20,0x00,0x08,0x74,0x00,0x01,0x0F,0x3C,0xF3,0xC0,0x98,0x03,0xFC,0x7E,0x40,
- 0x00,0x40,0x00,0x08,0x04,0x00,0x01,0x09,0x24,0x92,0x40,0x98,0x07,0xFE,0x78,0x40,
- 0x00,0x84,0x00,0x08,0x00,0x00,0x01,0x09,0x24,0x92,0x40,0x98,0x06,0x06,0x6C,0x40,
- 0x01,0x8A,0x18,0x08,0x00,0x0C,0x07,0x39,0xE7,0x9E,0x60,0x8F,0xCC,0x03,0x66,0x40,
- 0x01,0x84,0x24,0x00,0x00,0x12,0x04,0x00,0x00,0x00,0x00,0x87,0xCC,0x03,0x63,0x40,
- 0x00,0x80,0x42,0x00,0x00,0x21,0x58,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x40,
- 0x00,0x7F,0x99,0xF0,0xFF,0xCC,0xC0,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x40,
- 0x00,0x1F,0x99,0xFF,0xFF,0xCC,0x80,0x00,0x00,0x00,0x07,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x42,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x0F,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x24,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x1F,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x18,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x3F,0x80,0x02,0x00,0x00,0x40,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x02,0x00,0x00,0x40,
- };
- unsigned char code Photo11[]=
- {
- /*单位cm,32*32*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x0F,0xF0,0x3C,0xF0,0x1F,0xF8,0x7F,0xF8,0x38,0x38,0xE7,0x9C,0x70,0x00,0xC3,0x0C,
- 0x60,0x00,0xC3,0x0C,0x60,0x00,0xC3,0x0C,0x60,0x00,0xC3,0x0C,0x70,0x00,0xC3,0x0C,
- 0x38,0x38,0xC3,0x0C,0x1F,0xF8,0xC3,0x0C,0x0F,0xF0,0xC3,0x0C,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- /**********************************************************
- us延时子函数 (4.34us)
- **********************************************************/
- void delayNOP()
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- /**********************************************************
- ms延时子函数
- ***********************************************************/
- void delayms(unsigned int ms)
- {
- unsigned char y;
- while (ms--)
- {
- for (y = 0; y < 114; y++)
- ;
- }
- }
- /**********************************************************
- 检查LCD忙状态
- lcd_busy为1时,忙,等待。
- lcd-busy为0时,闲,可写指令与数据。
- **********************************************************/
- bit lcd_busy()
- {
- bit result;
- LCD_RS = 0;
- LCD_RW = 1;
- LCD_EN = 1;
- delayNOP();
- result = (bit)(P0 &0x80);
- LCD_EN = 0;
- return (result);
- }
- /**********************************************************
- 写指令数据到LCD
- RS=L,RW=L,E=高脉冲,D0-D7=指令码。
- **********************************************************/
- void lcd_wcmd(unsigned char cmd)
- {
- while (lcd_busy())
- ;
- LCD_RS = 0;
- LCD_RW = 0;
- LCD_EN = 1;
- P0 = cmd;
- delayNOP();
- LCD_EN = 0;
- }
- /**********************************************************
- 写显示数据到LCD
- RS=H,RW=L,E=高脉冲,D0-D7=数据。
- **********************************************************/
- void lcd_wdat(unsigned char dat)
- {
- while (lcd_busy())
- ;
- LCD_RS = 1;
- LCD_RW = 0;
- LCD_EN = 1;
- P0 = dat;
- delayNOP();
- LCD_EN = 0;
- }
- /**********************************************************
- LCD初始化设定
- **********************************************************/
- void lcd_init()
- {
- LCD_PSB = 1; //并口方式
- delayms(5);
- lcd_wcmd(0x34); //扩充指令操作
- delayms(5);
- lcd_wcmd(0x30); //基本指令操作
- delayms(5);
- lcd_wcmd(0x0C); //显示开,关光标
- delayms(5);
- lcd_wcmd(0x06); //光标的移动方向
- delayms(5);
- lcd_wcmd(0x01); //清除LCD的显示内容
- delayms(5);
- }
- /****指定要显示字符的坐标********/
- void gotoxy(unsigned char y, unsigned char x)
- {
- if(y==1)
- lcd_wcmd(0x80|x);
- if(y==2)
- lcd_wcmd(0x90|x);
- if(y==3)
- lcd_wcmd((0x80|x)+8);
- if(y==4)
- lcd_wcmd((0x90|x)+8);
- }
- /*****液晶显示字符串程序******/
- void print(uchar *str)
- {
- while(*str!='\0')
- {
- lcd_wdat(*str);
- str++;
- }
- }
- /*****填充液晶DDRAM全为空格******/
- void clrram_lcd (void)
- {
- lcd_wcmd(0x30);
- lcd_wcmd(0x01);
- }
- /********设定图片显示位置子函数********************************/
- void lcd_pos(unsigned char X, unsigned char Y)
- {
- 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;
- }
- pos = X + Y; //确定显示地址
- lcd_wcmd(pos); //写显示地址
- }
- /******清屏子函数**************/
- void clr_screen()
- {
- lcd_wcmd(0x30); //基本指令操作
- delayms(5);
- lcd_wcmd(0x01); //清屏
- delayms(5);
- }
- /***********写字符串子函数**************/
- void wr_string(unsigned char str[])
- {
- unsigned char num = 0;
- while (str[num])
- {
- lcd_wdat(str[num++]); //写数据
- }
- }
- /****32*32图形显示子函数-上半屏四块***********/
- void photodisplay(unsigned char *amp)
- {
- unsigned char i, j;
- if(off==0)
- {
- lcd_wcmd(0x34); //写数据时,关闭图形显示
- }
- switch(address)
- {
- case 0:site=0x80;break;
- case 1:site=0x82;break;
- case 2:site=0x84;break;
- case 3:site=0x86;break;
- default: break;
- }
- for (i = 0; i < 32; i++)
- //32行(上半屏)
- {
- lcd_wcmd(0x80 + i); //先写入Y坐标值
- lcd_wcmd(site); //写入X坐标值
- for (j = 0; j < 4; j++)
- //4*8列
- lcd_wdat(*amp++);
- delayms(1);
- }
- if(off==1)
- lcd_wcmd(0x36); //写完数据,开图形显示
- }
- /*******128*32图形显示子函数-下半屏一块************/
- void phot4display(unsigned char *bmp)
- {
- unsigned char i, j;
- for (i = 0; i < 32; i++)
- //32行(下半屏)
- {
- lcd_wcmd(0x80 + i); //先写入Y坐标值
- lcd_wcmd(0x88); //写入X坐标值
- for (j = 0; j < 16; j++)
- //16*8列
- lcd_wdat(*bmp++);
- delayms(1);
- }
- lcd_wcmd(0x36); //写完数据,开图形显示
- }
- /***********主函数**************/
- void main()
- {
- TMOD=0x12; //定时器控制状态,定时器0只要TR0,1置1时,定时器选通。定时器1在INT0或1为高电平且TR0或1 为1时,被选通,工作方式为0,13位计数器
- CP_RL2=0; //捕获/重装载标志,选择重装载功能
- RCLK=0; //接收时钟标志,定时器1溢出脉冲做接收时钟
- TCLK=0; //发送时钟标志,定时器1溢出脉冲做发送脉冲
- RCAP2H=(65536-30000)/256;
- RCAP2L=(65536-30000)%256; //预定义重装载值, CP_RL2=0把预定义的数据自动装入TH2 TL2
- ET2=1; //定时器2中断运行
- TR2=1; //定时器2运行控制,启动定时器
- TH0=256-12;
- TL0=256-12; //定时器0取时间12微秒,因为外部中断引脚每个机器周期被采样一次,为确保采样,由引脚INT0输入的信号
- //应至少保持一个机器周期,即12个振荡周期。
- TH1=0;
- TL1=0; //定时器1初始化
- ET0=1; //运行定时器0中断
- ET1=1; //允许定时器1中断
- TR1=1; //启动定时器1
- IT0=0; //外部中断0类型控制位,低电平触发
- IP=0x01; //外部中断0的优先级最高
- EA=1; //总中断允许,每个中断源由各自的允许位确定
- initDS1302(); //初始化DS1302
- lcd_init(); //初始化LCD
- P1_0=0;
- times=10; // 初始化
- off=0; //关显示图片标志位
- Temp_mark=0; //温度标志位
- change=0; //切换标志
- wave=0; //切换键标志位
- led=1;
- timer=1;
- m=ho=d=1;
- mo=w=y=1; //分,时,日,月,年,星期标志位
- delayms(50); //上电,等待稳定
- clrram_lcd();
- gotoxy(1,0);
- print("汽车倒车雷达"); //第一行显示汽车倒车雷达
- gotoxy(3,2);
- print("毕业设计!!") ;
- off=1; //开显示图片标志位
- delayms(3000); //停留3000ms
- off=0; //关显示图片标志位
- clr_screen(); //清屏
- delayms(500); //停留500ms
- assist_display(); //辅助显示时钟和温度字体和图形
- while (1)
- {
- buzzer=0;
- led=1;
- ultrasonic_key(); //切换键
- if(change==0)
- {
- DS1302_key(); //设置键
- DS1302_add(); //加键
- DS1302_reduce(); //减键
- read_t(); //读取温度
- if(timer==1)
- {
- timer=0;
- DS1302_time(); //读时钟
- DS1302_display(); //显示时钟
- DS18B20_display();
- Temp_mark=~Temp_mark;
- buzzer=1;
-
- }
- }
- else
- {
- if(open==1)
- {
- open=0;
- EA=0;
- S=TH1*256+TL1;
- L=(uint)(S/58);//为什么除以58等于厘米, Y米=(X秒*344)/2
- // X秒=( 2*Y米)/344 -> X秒=0.0058*Y米 -> 厘米=微秒/58
- ultrasonic_display();
- delayms(10);
- alerting();
- EA=1;
- TR1=1;
- TH1=0;
- TL1=0;
- }
- }
-
- }
- }
- /***************************************************
- DS1302程序
- ***************************************************/
- /*DS1302写一个字节*/
- void DS1302write_byte(uchar data_a)
- {
- uchar i;
- for(i=8;i>0;i--)
- {
- dio=(bit)(data_a&0x01);
- sclk=0;
- data_a>>=1;
- sclk=1;
- }
- }
- /*DS1302读一个字节*/
- uchar DS1302read_byte(void)
- {
- uchar i;
- uchar data_b=0;
- for(i=8;i>0;i--)
- {
- sclk=1;
- ACC>>=1;
- sclk=0;
- acc_7=dio;
- }
- data_b=ACC;
- return data_b;
- }
- /*写DS1302寄存器*/
- void writeDS1302(uchar addr,uchar da)
- {
- rst=0;
- sclk=0;
- rst=1;
- DS1302write_byte(addr);
- DS1302write_byte(da);
- sclk=1;
- rst=0;
- }
- /*读DS1302寄存器内容*/
- uchar readDS1302(uchar addr)
- {
- uchar ucdata;
- rst=0;
- sclk=0;
- rst=1;
- DS1302write_byte(addr|0x01);
- ucdata=DS1302read_byte();
- sclk=1;
- rst=0;
- return ucdata;
- }
- /*DS1302初始化*/
- void initDS1302(void)
- {
- unsigned char flag;
- flag= readDS1302(0x81);
- if(flag&0x80)
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_sec,0x50); //秒位初始化,50秒
- writeDS1302(write_min,0x35); //分钟初始化,35分
- writeDS1302(write_hour,0x09); //小时初始化,9点
- writeDS1302(write_day,0x23); //日初始化,23日
- writeDS1302(write_mon,0x05); //日初始化,5月
- writeDS1302(write_year,0x12); //看初始化 2012年
- writeDS1302(write_week,0x03); //日初始化,星期三
- writeDS1302(write_wp,0x80); //允许写保护
- }
- /*读取时间日期*/
- void DS1302_time()
- {
- sec=readDS1302(read_sec); //读秒
- min=readDS1302(read_min); //读分钟
- hour=readDS1302(read_hour); //读小时
- day=readDS1302(read_day); //读日
- mon=readDS1302(read_mon); //读月
- week=readDS1302(read_week); //读星期
- year=readDS1302(read_year); //读年
- }
- /********************************
- DS1302时钟显示程序
- *********************************/
- void DS1302_display()
- {
- uchar second_a,minute_a,minute_b;
- uchar hour_a,hour_b,day_a,day_b,mon_a,mon_b;
- uchar year_a,year_b,week_a,am,pm;
- second_a=sec&0x0f;
- if(y==1)
- {
- year_a=year>>4;
- year_b=year&0x0f;
- }
- else
- {
- year_a=year_b=10;
- }
- if(mo==1)
- {
- mon_a=(mon>>4)&0x01;
- mon_b=mon&0x0f;
- }
- else
- {
- mon_a=mon_b=10;
- }
-
- if(d==1)
- {
- day_a=day>>4;
- day_b=day&0x0f;
- }
- else
- {
- day_a=day_b=10;
- }
- if(ho==1)
- {
- hour_a=(hour>>4)&0x03;
- hour_b=hour&0x0f;
- }
- else
- {
- hour_a=hour_b=10;
- }
- if(m==1)
- {
- minute_a=min>>4;
- minute_b=min&0x0f;
- }
- else
- {
- minute_a=minute_b=10;
- }
- if(hour<0x12)
- {
- am=0;
- pm=1;
- }
- else
- {
- am=2;
- pm=1;
- }
- if(w==1)
- {
- week_a=week;
- }
- else
- {
- week_a=0x08;
- }
- lcd_pos(1,4);
- lcd_wdat(DIS1[year_a]);
- lcd_wdat(DIS1[year_b]);
- lcd_pos(1,5);
- lcd_wdat('-');
- lcd_wdat(DIS1[mon_a]);
- lcd_pos(1,6);
- lcd_wdat(DIS1[mon_b]);
- lcd_wdat('-');
- lcd_pos(1,7);
- lcd_wdat(DIS1[day_a]);
- lcd_wdat(DIS1[day_b]);
- lcd_pos(2,1);
- lcd_wdat(DIS4[am]);
- lcd_wdat(DIS4[pm]);
- lcd_pos(2,3);
- lcd_wdat(DIS1[hour_a]);
- lcd_wdat(DIS1[hour_b]);
- lcd_pos(2,4);
- lcd_wdat(DIS3[second_a]);
- lcd_wdat(DIS1[minute_a]);
- lcd_pos(2,5);
- lcd_wdat(DIS1[minute_b]);
- lcd_pos(3,3);
- switch (week_a)
- {
- case 0x07: wr_string(DIS12);
- lcd_pos(3,6);
- lcd_wdat(0x20);
- lcd_wdat(0x20);
- break;
- case 0x01: wr_string(DIS6); break;
- case 0x02: wr_string(DIS7); break;
- case 0x03: wr_string(DIS8); break;
- case 0x04: wr_string(DIS9);
- lcd_pos(3,7);
- lcd_wdat(0x20); break;
- case 0x05: wr_string(DIS10);
- lcd_pos(3,6);
- lcd_wdat(0x20);
- lcd_wdat(0x20);break;
- case 0x06: wr_string(DIS11); break;
- case 0x08: wr_string(DIS15);break;
- default:break;
- }
- }
- /********************************
- DS1302时钟辅助显示程序
- *********************************/
- void assist_display(void)
- {
- lcd_pos(1,0); //写date地址
- wr_string(DIS2); //写date字体数据
- lcd_pos(1,3); //写年20地址
- lcd_wdat(DIS1[2]);
- lcd_wdat(DIS1[0]); //写年20数据
- lcd_pos(2,0); //左三角形地址
- lcd_wdat(0x10); //显示左三角形
- lcd_pos(2,7); //右三角形地址
- lcd_wdat(0x11); //显示右三角形
- lcd_pos(3,0); //写week地址
- wr_string(DIS5); //写week数据
- lcd_pos(4,0); //写<T>:地址
- wr_string(DIS13); //写<T>:字体数据
- lcd_pos(4,3); //写车外温度单位地址
- lcd_wdat(0xa1);
- lcd_wdat(0xe6); //写车外温度单位
- }
- /*DS1302设置键程序*/
- void DS1302_key(void)
- {
- if(key0==0)
- {
- set=1;
- }
- if((set&&key0)==1)
- {
- buzzer=0;
- set=0;
- install++;
- if(install>=7)
- {
- install=0;
- m=ho=d=mo=w=y=1;
- }
- }
- switch(install)
- {
- case 0:m=ho=d=mo=w=y=1;break;
- case 1:m=~m;ho=d=mo=w=y=1;break;
- case 2:ho=~ho;m=d=mo=w=y=1;break;
- case 3:d=~d;m=ho=mo=w=y=1;break;
- case 4:mo=~mo;m=ho=d=w=y=1;break;
- case 5:y=~y;m=ho=d=mo=w=1;break;
- case 6:w=~w;m=ho=d=mo=y=1;break;
- default:break;
- }
-
- }
- /*DS1302加键程序*/
- void DS1302_add(void)
- {
- if(key1==0)
- {
- ja=1;
- }
- if(ja&&key1)
- {
- ja=0;
- if(install==1)
- {
- buzzer=0;
- min++;
- if((min&0x0f)==0x0a)
- {
- min=(min&0x70)+0x10;
- if((min&0x70)==0x60)
- {
- min=0x00;
- }
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_min,min); //修改分钟时间
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==2)
- {
- buzzer=0;
- hour++;
- if(hour!=0x24)
- {
- if((hour&0x0f)==0x0a)
- {
- hour=(hour&0x30)+0x10;
- }
- }
- else
- {
- hour=hour&0x00;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_hour,hour); // 修改小时时间
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==3)
- {
- buzzer=0;
- day++;
- if(day!=0x32)
- {
- if((day&0x0f)==0x0a)
- {
- day=(day&0x30)+0x10;
- }
- }
- else
- {
- day=0x01;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_day,day); // 修改日期
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==4)
- {
- buzzer=0;
- mon++;
- if(mon!=0x13)
- {
- if((mon&0x0f)==0x0a)
- {
- mon=0x10;
- }
- }
- else
- {
- mon=0x01;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_mon,mon); // 修改月期
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==5)
- {
- buzzer=0;
- year++;
- if((year&0x0f)==0x0a)
- {
- year=(year&0xf0)+0x10;
- if((year&0xf0)==0xa0)
- {
- year=0x00;
- }
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_year,year); // 修改年
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==6)
- {
- buzzer=0;
- week++;
- if(week==0x08)
- {
- week=0x01;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_week,week); // 修改星期
- writeDS1302(write_wp,0x80); //允许写保护
- }
- }
-
- }
- /*DS1302减键程序*/
- void DS1302_reduce(void)
- {
- if(key2==0)
- {
- jian=1;
- }
- if(jian&&key2)
- {
- jian=0;
- if(install==1)
- {
- buzzer=0;
- min--;
- if((min&0x0f)==0x0f)
- {
- min=min&0x79;
- if(min==0x79)
- {
- min=0x59;
- }
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_min,min); //分钟初始化,59分
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==2)
- {
- buzzer=0;
- hour--;
- if((hour&0x0f)==0x0f)
- {
- hour=hour&0x39;
- if(hour==0x39)
- {
- hour=0x23;
- }
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_hour,hour); // 修改小时时间
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==3)
- {
- buzzer=0;
- day--;
- if(day!=0x00)
- {
- if((day&0x0f)==0x0f)
- {
- day=day&0x39;
- }
- }
- else
- {
- day=0x31;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_day,day); // 修改日期
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==5)
- {
- buzzer=0;
- year--;
- if((year&0xf0)!=0xf0)
- {
- if((year&0x0f)==0x0f)
- {
- year=year&0xf9;
- }
- }
- else
- {
- year=0x99;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_year,year); // 修改年
- writeDS1302(write_wp,0x80); //允许写保护
- }
- else if(install==6)
- {
- buzzer=0;
- week--;
- if(week==0x00)
- {
- week=0x07;
- }
- writeDS1302(write_wp,0x00); //禁止写保护
- writeDS1302(write_week,week); // 修改星期
- writeDS1302(write_wp,0x80); //允许写保护
- }
- }
-
- }
- /***************************************************
- DS18B20程序
- ***************************************************/
- /*DS18B20延时程序*/
- void delay_18b20(uint n)
- {
- while(n--);
- }
- /*复位程序*/
- void init_18b20(void)
- { if(Temp_mark==0)
- DQ=1; //拉高总线
- delay_18b20(8); //延时一段时间
- DQ=0; //拉低总线
- delay_18b20(80); //延时大于480us
- DQ=1; //拉高总线
- delay_18b20(14);
- while(DQ!=1) //稍做延时后,等待DS18B20应答
- delay_18b20(5);
-
- }
- /*写一个字节程序*/
- void write_18b20(uchar data_a)
- {
- uchar loop=0;
- for(loop=8;loop>0;loop--)
- {
- if(Temp_mark==0)
- DQ=1;
- _nop_();
- _nop_();
- DQ=0; // 拉低总线,一段时间
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- DQ=data_a&0x01; //写一位
- delay_18b20(5); //稍做延时
- DQ=1; //拉高总线
- data_a>>=1; //为下一位做准备
- }
- }
- /*读一个字节程序*/
- uchar read_18b20()
- {
- uchar loop=0,data_b=0;
- for(loop=8;loop>0;loop--)
- {
- if(Temp_mark==0)
- DQ=0; //拉低总线
- data_b>>=1; //读取一位
- DQ=1; //拉高总线,为读取温度做准备
- if(DQ) //判断总线上是否读取1
- data_b|=0x80; //是,送1
- delay_18b20(4); //稍做延时
- }
- return data_b;
- }
- /*读温度程序*/
- void read_t(void)
- {
- uchar t_l=0; //清温度低位
- uchar t_h=0; //清温度高位
- init_18b20(); //复位
- write_18b20(0xcc); //跳过Rom
- write_18b20(0x44); //温度转换
- delay_18b20(160); //延时900us,等待温度转换
- init_18b20(); //复位
- write_18b20(0xcc); //跳过Rom
- write_18b20(0xbe); //读暂存器温度
- t_l=read_18b20(); //读取温度低位
- t_h=read_18b20(); //读取温度高位
- t=t_h;
- t<<=8;
- t|=t_l; //将温度低位与高位合并
- dispose_t(); //处理温度数据
- }
- /*处理温度*/
- void dispose_t(void)
- {
- t=(t*0.0625); //得到正确温度值
- tt=(uchar)t; //取整数,舍去小数部分
- shi=tt%100/10;
- ge=tt%100%10;
- if(shi==0) //十位是否等于0
- shi=10; //十位等于0,十位不显示
- if(Temp_mark==0)
- {
- shi0=shi;
- ge0=ge;
- }
- else
- {
- shi1=shi;
- ge1=ge;
- }
- }
- /*显示程序*/
- void DS18B20_display()
- {
- lcd_pos(4,2); //室内温度地址
- lcd_wdat(DIS1[shi0]); //室内温度十位
- lcd_wdat(DIS1[ge0]); //室内温度个位
- }
- /*定时器2*/
- void timer2(void) interrupt 5 using 1
- {
- TF2=0;
- time++;
- if(time==11)
- {
- time=0;
- timer=1;
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
汽车倒车雷达源程序.zip
(69.97 KB, 下载次数: 83)
|