完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
超声波模块用的HC-SR04,程序会在下面给出,现在的问题是测距总显示000,程序似乎进不到中断里面(debug时用断点试过),不知是哪的问题?还有就是不知道3.3v对HC-SR04来说算不算是高电平,HC-SR04是用5V供电的 程序如下
#include "config.h" #define RS 1<<0//p0.0 #define SID 1<<2//p0.2 #define E 1<<4//p0.4 #define RST 1<<6//p0.6 #define Trig 1<<19//p0.10 #define Echo 1<<17//p0.12 uint32 timer0_time=0; uint8 Echo_flag=0; unsigned char IC_DAT1[]="欢迎使用"; unsigned char IC_DAT2[]="智能清洁机器人!!"; //unsigned char num[]="0123456789"; unsigned char num[]={'0','1','2','3','4','5','6','7','8','9'}; unsigned char DIST[]="距离"; unsigned char cm[]="cm"; void TransferCom(unsigned char data0); void TransferData(unsigned char data1); void delayms(unsigned int n); void DisplayGraphic(unsigned char *adder); void delay(unsigned int m); //void lcd_mesg(unsigned char *adder1,unsigned char hang,unsigned char lie); void __irq IRQ_Timer0(void); void delayms(unsigned int n) { unsigned int i,j; for(i=0;i } void delay(unsigned int m) { unsigned int i,j; for(i=0;i } void delay_10us(uint32 t) { uint32 i; for(;t>0;t--) for(i=84;i>0;i--); } /*******************LCD12864字库初始化*************************/ void initina1(void) { delay(40); //IO0CLR=PSB;//低,串行 //delay(1); IO0CLR=RST; delay(1); IO0SET=RST; delay(10); TransferCom(0x30); delay(100); TransferCom(0x0c); delay(100); TransferCom(0x01); delay(10); TransferCom(0x06); delay(100); } /**************************图片初始化********************************/ void initina2(void) { delay(40); //IO0CLR=PSB; //delay(1); IO0CLR=RST; delay(1); IO0SET=RST; delay(10); TransferCom(0x36); delay(100); TransferCom(0x36); delay(37); TransferCom(0x3e); delay(100); TransferCom(0x01); delay(100); } /***********************设置显示位置***********************/ void lcd_pos(unsigned char hang,unsigned char lie) { unsigned int a; if(lie>16) lie=1; if(hang==1) a=0x80; if(hang==2) a=0x90; if(hang==3) a=0x88; if(hang==4) a=0x98; a=a+lie-1; TransferCom(a); delay(100); } /**************************显示汉字********************************/ void lcd_mesg(unsigned char *adder1) { /*unsigned int a; if(lie>16) lie=1; if(hang==1) a=0x80; if(hang==2) a=0x90; if(hang==3) a=0x88; if(hang==4) a=0x98; a=a+lie-1; TransferCom(a); delay(100);*/ while(*adder1!=' |