|
智能小車,紅外加超聲波避障加測速里程,內加算法,用上51的4個中斷優先級了,
- #include <reg52.h>
- #include "lcd1602.h"
- #include "IRLED.h"
- #include "CarControl.h"
- #include "SuperWave.h"
- #include "SysTicks.h"
- #include "MeasureSpeed.h"
- sfr IPH = 0XB7;//優先級配置寄存器
- #define uchar unsigned char
- #define uint unsigned int
- sbit IRIN = P3^3; //紅外接收器數據線
- extern uchar IRLedValue ;//紅外遙控器值
- /***************************************
-
- 定時器0:計數器模式,用于計算碼盤脈沖個數
- 定時器1:定時器模式,用于計算超聲波距離
- 定時器2:定時器模式,用于系統滴答計時,與產生PWM波
- 外部中斷1:紅外接收中斷
-
- 優先級:
- 外部中斷1 > 定時器2 > 定時器1 > 定時器0
- *****************************************/
- bit IsCarRunning=0;//車是否在跑
- void main()
- {
- uchar i;
- PT0=1; //提升外部中斷1高于定時器0
- IPH|=0x22;//提升定時器2優先級僅次于外部中斷1
-
- LCD1602_Init();
- IRLED_Init();
- Car_Init();
- SuperWave_Init();
- SysTicks_Init();
- MeasureSpeed_Init();
- LCD1602_ShowString(0,0,"Num:");
- while(1)
- {
- SuperWave_GetCount();
-
- Delay_ms(10);
- }
- }
- #include <reg52.h>
- #include "lcd1602.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define LCD1602_DATA P0
- sbit lcden=P2^7; //使能控制
- sbit lcdrs=P2^5; //命令數據輸入
- sbit lcdrw=P2^6; //命令數據輸入
-
- void Delay_ms(unsigned int ms)
- {
- unsigned int x,y;
- for(x=ms;x>0;x--)
- for(y=110;y>0;y--);
- }
-
- bit LCD1602_Busy()
- {
- bit busy;
- lcdrs=0;
- lcdrw=1;
- lcden=1;
- Delay_ms(2);
- busy=(bit)(LCD1602_DATA&0x80);
- lcden=0;
- return(busy);
- }
-
- void LCD1602_Wcmd(unsigned char buffer)
- {
- while(LCD1602_Busy());
- lcdrs = 0;
- lcdrw = 0;
- lcden = 0;
- LCD1602_DATA = buffer;
- lcden = 1;
- Delay_ms(5); //1ms 3ms
- lcden = 0;
- }
- void LCD1602_Wdata(unsigned char dat)
- {
- while(LCD1602_Busy());
- lcdrs = 1;
- lcdrw = 0;
- lcden = 0;
- LCD1602_DATA = dat;
- lcden = 1;
- Delay_ms(5);
- lcden = 0;
- }
- void LCD1602_Init()
- {
- LCD1602_Wcmd(0x38);//數據8位
- Delay_ms(5);
- LCD1602_Wcmd(0x0e);//開啟顯示屏及光標
- Delay_ms(5);
- LCD1602_Wcmd(0x06);//輸入模式:位增,不移
- Delay_ms(5);
- LCD1602_Wcmd(0x01);//清零
- Delay_ms(5);
- }
- void LCD1602_ShowString(unsigned char x,unsigned char y,unsigned char dat[])
- {
- uchar i=0;
- if(y==0)
- LCD1602_Wcmd(0x80+x);//0x80+1
- else if(y==1)
- LCD1602_Wcmd(0xc0+x);//0xc0+1
- while(dat[i]!='\0')
- {
- LCD1602_Wdata(dat[i]);
- Delay_ms(2);
- i++;
- }
- }
- #include <reg52.h>
- #include "ultrasonic.h"
- #include "delay.h"
- #include "lcd.h"
- void getsuper(void)
- {
- trig = 1;
- DelayUs2x(5);
- trig = 0;
- while(!echo);
- TR1 = 1;
- while(echo);
- TR1 = 0;
- time = TH1*256 + TL1;
- TH1 = 0;
- TL1 = 0;
-
- sss=(time*1.7)/100;
- LCD1602_Dis_OneChar(1, 1, sss%1000/100+0x30);
- LCD1602_Dis_OneChar(2, 1, sss%100/10+0x30);
- LCD1602_Dis_OneChar(3, 1, sss%10+0x30);
- LCD1602_Dis_OneChar(4, 1, 'c');
- LCD1602_Dis_OneChar(5, 1, 'm');
-
- }
復制代碼 |
-
-
超聲波避障+藍牙遙控智能小車.zip
2019-11-16 23:50 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
44.76 KB, 下載次數: 16, 下載積分: 黑幣 -5
|