这是一个小车的
做的是小车循线超声避障循光入库
这是主程序
- #include <AT89x51.H> //Æ÷¼þÅäÖÃÎļþ
- #include <intrins.h>
- #include "dianji.h"
- #include "xunxian.h"
- #include "ceju.h"
- #define ste P2_7 //¶æ»ú¿ØÖƽÅ
- #define RIGHT_led P0_5 //ÓÒ²àѹâled
- #define Before_led_one P0_6 //Ç°·½Ñ¹âled1
- #define Before_led_two P0_7 //Ç°·½Ñ¹âled2
- unsigned char Statusflag=1; //×Ü״̬±ê־λ
- void delayhaomiao(unsigned int ms)
- {
- unsigned char i=100,j;
- for(;ms;ms--)
- {
- while(--i)
- {
- j=10;
- while(--j);
- }
- }
- }
- void main()
- {
- while(Statusflag==1)
- {
- xunxian();
- ceju();
- if(S<=100)
- Statusflag=2;
- }
- while(Statusflag==2)
- {
- zuotui();
- youqian();
- delayhaomiao(500); //´ËʱÊý¾Ý¹©±àÒ룬ʵ¼ÊÐèÒªÐë¸ù¾ÝС³µÇé¿ö¸ü¸Ä
- qianjin();
- delayhaomiao(30000); //´ËʱÊý¾Ý¹©±àÒ룬ʵ¼ÊÐèÒªÐë¸ù¾ÝС³µÇé¿ö¸ü¸Ä
- youzhuan();
- delayhaomiao(500);
- qianjin();
- Statusflag=3;
- }
- /* while(Statusflag==3)
- {
- if(RIGHT_led==0)
- {
- zuoqian();
- youtui();
- delayhaomiao(500);
- if((Before_led_one==0)&&(Before_led_two==0))
- {
- zuoqian();
- youtui();
- delayhaomiao(500);
- qianjin();
- if(S==150)
- while(1);
- }
- }
- } */
- }
复制代码
- /*这个是测距用1602显示的子程序*/
- #include <AT89x51.H> //Æ÷¼þÅäÖÃÎļþ
- #include <intrins.h>
- #include "ceju.h"
- unsigned char code ASCII[15] = {'0','1','2','3','4','5','6','7','8','9','.','-','M'};
- unsigned char disbuff[4]={0,0,0,0,};
- unsigned char code mcustudio[] ={"==Range Finder=="};
- unsigned char code email[] = {" Hello Teachers "};
- unsigned char code Cls[] = {" "};
- static unsigned char DisNum = 0; //ÏÔʾÓÃÖ¸Õë
- unsigned int time=0;
- unsigned long S=0;
- bit flag =0;
-
- /****************дÊý¾Ý****************/
- void WriteDataLCM(unsigned char WDLCM)
- {
- ReadStatusLCM(); //¼ì²âæ
- LCM_Data = WDLCM;
- LCM_RS = 1;
- LCM_RW = 0;
- LCM_E = 0; //Èô¾§ÕñËÙ¶ÈÌ«¸ß¿ÉÒÔÔÚÕâºó¼ÓСµÄÑÓʱ
- LCM_E = 0; //ÑÓʱ
- LCM_E = 1;
- }
- /****************дָÁî*****************/
- void WriteCommandLCM(unsigned char WCLCM,BuysC) //BuysCΪ0ʱºöÂÔæ¼ì²â
- {
- if (BuysC) ReadStatusLCM(); //¸ù¾ÝÐèÒª¼ì²âæ
- LCM_Data = WCLCM;
- LCM_RS = 0;
- LCM_RW = 0;
- LCM_E = 0;
- LCM_E = 0;
- LCM_E = 1;
- }
- /****************¶ÁÊý¾Ý********************/
- unsigned char ReadDataLCM(void)
- {
- LCM_RS = 1;
- LCM_RW = 1;
- LCM_E = 0;
- LCM_E = 0;
- LCM_E = 1;
- return(LCM_Data);
- }
- /*****************¶Á״̬********************/
- unsigned char ReadStatusLCM(void)
- {
- LCM_Data = 0xFF;
- LCM_RS = 0;
- LCM_RW = 1;
- LCM_E = 0;
- LCM_E = 0;
- LCM_E = 1;
- while (LCM_Data & Busy); //¼ì²âæÐźÅ
- return(LCM_Data);
- }
- /********************LCM³õʼ»¯**********************/
- void LCMInit(void)
- {
- LCM_Data = 0;
- WriteCommandLCM(0x38,0); //Èý´ÎÏÔʾģʽÉèÖ㬲»¼ì²âæÐźÅ
- Delay5Ms();
- WriteCommandLCM(0x38,0);
- Delay5Ms();
- WriteCommandLCM(0x38,0);
- Delay5Ms();
- WriteCommandLCM(0x38,1); //ÏÔʾģʽÉèÖÃ,¿ªÊ¼ÒªÇóÿ´Î¼ì²âæÐźÅ
- WriteCommandLCM(0x08,1); //¹Ø±ÕÏÔʾ
- WriteCommandLCM(0x01,1); //ÏÔʾÇåÆÁ
- WriteCommandLCM(0x06,1); // ÏÔʾ¹â±êÒƶ¯ÉèÖÃ
- WriteCommandLCM(0x0F,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; //Ëã³öÖ¸ÁîÂë
- WriteCommandLCM(X, 1); //·¢ÃüÁî×Ö
- WriteDataLCM(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]>0x19) //Èôµ½´ï×Ö´®Î²ÔòÍ˳ö
- {
- 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.8)/10; //Ëã³öÀ´ÊÇMM
- if((S>=7000)||flag==1) //³¬³ö²âÁ¿·¶Î§ÏÔʾ¡°-¡±
- {
- flag=0;
-
- DisplayOneChar(0, 1, ASCII[11]);
- DisplayOneChar(1, 1, ASCII[10]); //ÏÔʾµã
- DisplayOneChar(2, 1, ASCII[11]);
- DisplayOneChar(3, 1, ASCII[11]);
- DisplayOneChar(4, 1, ASCII[11]);
- DisplayOneChar(5, 1, ASCII[12]); //ÏÔʾM
- }
- else
- {
- disbuff[0]=S/1000;
- disbuff[1]=S/100%10;
- disbuff[2]=S/10%10;
- disbuff[3]=S%10;
- DisplayOneChar(0, 1, ASCII[disbuff[0]]);
- DisplayOneChar(1, 1, ASCII[10]); //ÏÔʾµã
- DisplayOneChar(2, 1, ASCII[disbuff[1]]);
- DisplayOneChar(3, 1, ASCII[disbuff[2]]);
- DisplayOneChar(4, 1, ASCII[disbuff[3]]);
- DisplayOneChar(5, 1, ASCII[12]); //ÏÔʾM
- }
- }
- /********************************************************/
- void zd0() interrupt 1 //T0ÖжÏÓÃÀ´¼ÆÊýÆ÷Òç³ö,³¬¹ý²â¾à·¶Î§
- {
- flag=1; //ÖжÏÒç³ö±êÖ¾
- RX=0;
- }
- /***************************Æô¶¯³¬ÉùÄ£¿é*****************************/
- void StartModule()
- {
- TX=1; //Æô¶¯Ò»´ÎÄ£¿é
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- TX=0;
- }
- void Timer_Count(void)
- {
- TR0=1; //¿ªÆô¼ÆÊý
- while(RX); //µ±RXΪ1¼ÆÊý²¢µÈ´ý
- TR0=0; //¹Ø±Õ¼ÆÊý
- Conut(); //¼ÆËã
- }
- /*********************ÑÓʱº¯Êý**************************/
- void delayms(unsigned int ms)
- {
- unsigned char i=100,j;
- for(;ms;ms--)
- {
- while(--i)
- {
- j=10;
- while(--j);
- }
- }
- }
- //5msÑÓʱ
- void Delay5Ms(void)
- {
- unsigned int TempCyc = 5552;
- while(TempCyc--);
- }
- //400msÑÓʱ
- void Delay400Ms(void)
- {
- unsigned char TempCycA = 5;
- unsigned int TempCycB;
- while(TempCycA--)
- {
- TempCycB=7269;
- while(TempCycB--);
- };
- }
- /*********************Ö÷º¯Êý****************************/
- void ceju(void)
- {
- unsigned int valA;
- unsigned char TempCyc;
- Delay400Ms(); //Æô¶¯µÈ´ý£¬µÈLCM½²È빤×÷״̬
- LCMInit(); //LCM³õʼ»¯
- Delay5Ms(); //ÑÓʱƬ¿Ì(¿É²»Òª)
- DisplayListChar(0, 0, mcustudio);
- DisplayListChar(0, 1, email);
- ReadDataLCM();//²âÊÔÓþäÎÞÒâÒå
- for (TempCyc=0; TempCyc<10; TempCyc++)
- Delay400Ms(); //ÑÓʱ
- DisplayListChar(0, 1, Cls);
- TMOD=0x01; //ÉèT0Ϊ·½Ê½1£¬GATE=1£»
- TH0=0;
- TL0=0;
- ET0=1; //ÔÊÐíT0ÖжÏ
- EA=1; //¿ªÆô×ÜÖжÏ
- delayms(60);
- RX=1;
- StartModule();
- for(valA=7510;valA>0;valA--)
- {
- if(RX==1)
- {
- Timer_Count();
- }
- }
- }
复制代码
结果程序在实际运行的时候1602根本不显示,但是1602的程序是没有问题的,单独拿出来是可以执行的,不懂得问题出在哪里,麻烦大家帮我看一看
那个static已经被我换成了extern ,我去看看程序会被执行到哪一步
一周热门 更多>