多路超声波程序.zip

  • yyy555
    了解作者
  • C/C++
    开发工具
  • 123KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-03-06 14:17
    上传日期
多路超声波测距报警,可存储报警值,lcd1602显示
多路超声波程序.zip
  • 多路超声波程序
  • DS1302.c
    3.5KB
  • 测距程序.hex
    16.6KB
  • DS1302.OBJ
    8KB
  • 测距程序.OBJ
    40.1KB
  • 测距程序.uvgui_11263.bak
    69.1KB
  • 1602.OBJ
    5.6KB
  • 1602.c
    2.9KB
  • 测距程序.lnp
    112B
  • 测距程序_Opt.Bak
    981B
  • 测距程序.Uv2.bak
    2.1KB
  • 测距程序.build_log.htm
    1KB
  • 测距程序.uvgui_hgft.bak
    69.3KB
  • 测距程序.M51
    62.8KB
  • 24c02.c
    3.5KB
  • 测距程序_Uv2.Bak
    2.1KB
  • 测距程序.uvgui.11263
    69.1KB
  • 测距程序.uvproj
    14KB
  • DS1302.LST
    6.9KB
  • 测距程序
    56.1KB
  • 测距程序.uvgui.35481
    70.6KB
  • 测距程序_uvproj.bak
    13.5KB
  • 测距程序.C
    20KB
  • 测距程序.plg
    24.5KB
  • 24c02.LST
    7.7KB
  • 测距程序.LST
    34.7KB
  • 1602.LST
    5.4KB
  • 测距程序.uvopt
    6.5KB
  • 测距程序_uvopt.bak
    5.3KB
  • 测距程序.opt.bak
    977B
  • 24c02.OBJ
    11.5KB
  • 测距程序.uvgui.hgft
    69.3KB
  • DS1302.h
    1.8KB
内容介绍
#include <reg52.h> #include <intrins.h> #include "ds1302.h" #define LCD_DATA P0 //LCD的数据口 #define LCD_GO_HOME 0x02 //AC=0,光标、画面回HOME位 //输入方式设置 #define LCD_AC_AUTO_INCREMENT 0x06 //数据读、写操作后,AC自动增一 #define LCD_AC_AUTO_DECREASE 0x04 //数据读、写操作后,AC自动减一 #define LCD_MOVE_ENABLE 0x05 //数据读、写操作,画面平移 #define LCD_MOVE_DISENABLE 0x04 //数据读、写操作,画面不动 //设置显示、光标及闪烁开、关 #define LCD_DISPLAY_ON 0x0C //显示开 #define LCD_DISPLAY_OFF 0x08 //显示关 #define LCD_CURSOR_ON 0x0A //光标显示 #define LCD_CURSOR_OFF 0x08 //光标不显示 #define LCD_CURSOR_BLINK_ON 0x09 //光标闪烁 #define LCD_CURSOR_BLINK_OFF 0x08 //光标不闪烁 //光标、画面移动,不影响DDRAM #define LCD_LEFT_MOVE 0x18 //LCD显示左移一位 #define LCD_RIGHT_MOVE 0x1C //LCD显示右移一位 #define LCD_CURSOR_LEFT_MOVE 0x10 //光标左移一位 #define LCD_CURSOR_RIGHT_MOVE 0x14 //光标右移一位 //工作方式设置 #define LCD_DISPLAY_DOUBLE_LINE 0x38 //两行显示 #define LCD_DISPLAY_SINGLE_LINE 0x30 //单行显示 #define uchar unsigned char #define uint unsigned int #define ulong unsigned long #define WriteDeviceAddress 0xa0 //定义器件写地址 #define ReadDviceAddress 0xa1 //定义器件读地址 #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();}; #define jiexian 30 //报警距离 CM //引脚定义 sbit Trig1=P3^0; sbit Ecno1=P3^1; sbit Trig2=P3^2; sbit Ecno2=P3^3; sbit Trig3=P2^4; sbit Ecno3=P2^5; sbit Trig4=P2^6; sbit Ecno4=P2^7; sbit beep=P3^7; sbit LED=P3^6; bit TimeSet_flag=0,Savedata_flag=0,Readback_flag=0,full_flag=0,succeed_flag,succeed_flag; unsigned char m,n; unsigned char keydata,writenumber=0,readnumber=0; void LCD_check_busy(void); //检测LCD状态,看它是不是还在忙呢 void LCD_cls(void); //LCD清屏 void LCD_write_instruction(unsigned char LCD_instruction); //写指令到LCD void LCD_write_data(unsigned char LCD_data); //输出一个字节数据到LCD void LCD_set_position(unsigned char x); //LCD光标定位到x处 void LCD_printc(unsigned char lcd_data); //输出一个字符到LCD void LCD_prints(unsigned char *lcd_string); //输出一个字符串到LCD void LCD_initial(void); //初始化LCD void StartModule(); void Start(); void Stop(); void YEAck(); /*发应答信号*/ void NoAck(); /*发非应答信号*/ bit TestAck(); /*测试应答信号*/ void Write8Bit(unsigned char input); /*写入 8 个 bit 到 24c02 */ unsigned char Read8Bit(); /*从 24c02 中读出 8 个 bit*/ void write_24c02(unsigned char *lcd_string,nn); /*向24c02中写入第nn条记录,11个字的字符串数据*/ void read_24c02 (uchar mm);/*从24c02中读取第mm条记录(第一条起始地址00h,第二条地址10h,第三条20h,....)*/ uchar readnumber_24c02 (); void writenumber_24c02(unsigned char dd); //记录序号存至0xff单元 void writeclear_24c02(); /*24c02清0*/ void DelayMs(unsigned int number); unsigned char LCD1602disbuff1[16]={"20170410 12:00 "}; unsigned char LCD1602dis2buff1[16]; unsigned char LCD1602dis2buff2[16]={"baojingjuli "}; unsigned char code num[]={"0123456789 :."}; unsigned char write24c02buff[11]; unsigned char read24c02buff[11]; unsigned int time1=0; unsigned int time2=0; unsigned int time3=0; unsigned int time4=0; long S1=0; long S2=0; long S3=0; long S4=0; bit flag =0; unsigned char disbuff[4]={0,0,0,0,}; /*********************/ /*********************/ /* */ /* 延时函数 */ /* */ /*********************/ void delay(uint x) { uint i,j; for(i=x;i>0;i--) for(j=110;j>0;j--); } void Delaynms(unsigned int di) //延时 { unsigned int da,db; for(da=0;da<di;da++) for(db=0;db<10;db++); } void baojing() { LED=0; beep=~beep; } void delay20ms() { unsigned int i; for(i=1000;i>0;i--) ; } unsigned char keyscan() //键盘扫描 { unsigned char row,col,k=0xff; //定义行、列、返回值 P1=0xf0; if((P1&0xf0)==0xf0) return k; //无键按下,返回 delay20ms(); //延时去抖 if((P1&0xf0)==0xf0) return k; //抖动引起,返回 for(row=0;row<4;row++) //行扫描 { P1=~(1<<row); //扫描值送P2 k=P1&0xf0; //注意:此处m不能用k代替,因为k是有符号数,会使结果出错 if(k!=0xf0) //列线不全为1 { col=0; while((k&(1<<(col+4)))!=0) col++; //所按键不在该列, 查找结果为0的列号 k=4*row+col; //计算键值 P1=0xf0; while((P1&0xf0)!=0xf0); //等待键释放 break; } } return k; //返回键值 } void LCD1602disp(void) //测量状态显示 { LCD_set_position(0x40); LCD_prints(LCD1602disbuff1); } void LCD1602disp3(void) //设置时间状态显示 { LCD_write_instruction(0x01); LCD_set_position(0); LCD_prints(LCD1602disbuff1); } void LCD1602disp2(void) //回看状态显示 { LCD1602dis2buff1[0]=read24c02buff[0]+0x30; LCD1602dis2buff1[1]=' '; LCD1602dis2buff1[2]=read24c02buff[1]/10+0x30; LCD1602dis2buff1[3]=read24c02buff[1]%10+0x30; LCD1602dis2buff1[4]=read24c02buff[2]/10+0x30; LCD1602dis2buff1[5]=read24c02buff[2]%10+0x30; LCD1602dis2buff1[6]=read24c02buff[3]/10+0x30; LCD1602dis2buff1[7]=read24c02buff[3]%10+0x30; LCD1602dis2buff1[8]=read24c02buff[4]/10+0x30; LCD1602dis2buff1[9]=read24c02buff[4]%10+0x30; LCD1602dis2buff1[10]=' '; LCD1602dis2buff1[11]=read24c02buff[5]/10+0x30; LCD1602dis2buff1[12]=read24c02buff[5]%10+0x30; LCD1602dis2buff1[13]=':'; LCD1602dis2buff1[14]=read24c02buff[6]/10+0x30; LCD1602dis2buff1[15]=read24c02buff[6]%10+0x30; LCD1602dis2buff2[11]=read24c02buff[7]+0x30; LCD1602dis2buff2[12]=' '; LCD1602dis2buff2[13]=read24c02buff[8]+0x30; LCD1602dis2buff2[14]=read24c02buff[9]+0x30; LCD1602dis2buff2[15]=read24c02buff[10]+0x30; LCD_set_position(0); LCD_prints(LCD1602dis2buff1); LCD_set_position(0x40); LCD_prints(LCD1602dis2buff2); } /******************************************************************************/ void LCD_Write_number(unsigned char s)// 数字显示函数 { LCD_write_data(num[s]); Delaynms(1); } /********************************************************/ void Conut1(void) { time1=TH0*256+TL0; TH0=0x00; TL0=0x00; S1=time1*1.87/100; // 11.0592M晶振 if(flag==1) //超出测量 { flag=0; LCD_set_position(0); LCD_prints("err"); } else { disbuff[1]=S1%1000/100; disbuff[2]=S1%1000%100/10; disbuff[3]=S1%1000%100%10; LCD_set_position(0); LCD_Write_number(disbuff[1]); LCD_Write_number(disbuff[2]); LCD_set_position(2); LCD_Write_number(disbuff[3]); if(S1<jiexian) { baojing(); Savedata_flag=1; Ds1302_Read_Time(); write24c02buff[0]=writenumber; write24c02buff[1]=20; write24c02buff[2]=time_buf1[1]; write24c02buff[3]=time_buf1[2]; write24c02buff[4]=time_buf1[3]; write24c02buff[5]=time_buf1[4]; write24c02buff[6]=time_buf1[5]; write24c02buff[7]=1; write24c02buff[8]=disbuff[1]; write24c02buff[9]=disbuff[2]; write24c02buff[10]=disbuff[3]; write_24c02(write24c02buff,writenumber); writenumber++; if(writenumber==10) { // writenumber0=writenumber; writenumber=0;//最多10条记录 } writenumber_24c02(writenumber); LCD_write_instruction(0x01); LCD_write_instruction(0x80); LCD_prints("baojing1"); LCD_write_instruction(0xc0); LCD_prints("The Data Saved"); DelayMs(10000); Savedata_flag=0; LCD_write_instruction(0x01); } else { beep=1; LED=1; } } } /*********************************************
评论
    相关推荐