|
以下是我參照論壇內(nèi)大佬的代碼寫的單片機(jī)代碼,在仿真上出現(xiàn)了以下錯誤
1.在沒有信號時,其不能完全停止。motor仍顯示在轉(zhuǎn)動,但較為緩慢。(void stop)不知道是仿真的問題還是程序的問題。(全部給的反轉(zhuǎn),速度全部為0)
2.我寫的六個運(yùn)動方式,分別為:停止(stop),直走zhizou)、左大轉(zhuǎn)(dazhuan1)、右大轉(zhuǎn)(dazhuan2)、左微調(diào)(weitiao1)、右微調(diào)(weitiao2)
現(xiàn)在的問題是除左大轉(zhuǎn)外,其余的運(yùn)轉(zhuǎn)方式都成功,左大轉(zhuǎn)的左電機(jī)管腳出出現(xiàn)閃爍,疑似信號沖突,但我沒有找到?jīng)_突的點(diǎn)在哪?
3.我嘗試過將左大轉(zhuǎn)的正反轉(zhuǎn)函數(shù)將0換成1,結(jié)果其運(yùn)行正常,求解
請求各位大佬的幫助,搞了幾天,真的看不到?jīng)_突的點(diǎn)在哪里.(還有,模擬紅外傳感器的按鈕松開表示有信號1,按下默認(rèn)為0)
程序?qū)懙暮軄y,但是希望各位大佬能耐心看完,指出問題所在。急需。
在此,感激不盡。祝生活愉快,萬事如意。- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- extern void Motor_Left_Q(bit ReverOrCoro, unsigned char DutyCycle); //????????
- extern void Motor_Left_H(bit ReverOrCoro, unsigned char DutyCycle);
- extern void Motor_Right_Q(bit ReverOrCoro, unsigned char DutyCycle); //????????
- extern void Motor_Right_H(bit ReverOrCoro, unsigned char DutyCycle);
- extern void stop(void);
- void Timer0Config(); // ?????0
- void zhizou();
- void dazhuan1();
- void dazhuan2();
- void weitiao1();
- void weitiao2();
- sbit ENA1 = P1^5; //???????
- sbit ENB1= P1^6;
- sbit ENA2 = P2^5; //???????
- sbit ENB2= P2^6;
- sbit led = P2^4;//???
- uchar a;
- uchar Infrared; //??P0????? ?????
- void scan(void);
- sbit inputL1=P0^0; //?1
- sbit inputL2=P0^1; //?2
- sbit inputR1=P0^2; //?2
- sbit inputR2=P0^3; //?1
- void main()
- {
- Timer0Config();
- ENA1 = 1;
- ENB1 = 1;
- ENA2 = 1;
- ENB2 = 1;
- while(1)
- {
- scan();
- }
- }
- void scan()
- {
- if(inputL1==0&&inputR1==0&&inputL2==0&&inputR2==0) //0000
- {
- stop();
- }
- if(inputL1==1&&inputL2==0&&inputR1==0&&inputR2==0) //1000
- {
- dazhuan1();
- }
- if(inputL1==0&&inputL2==1&&inputR1==0&&inputR2==0) //0100
- {
- weitiao1();
- }
- if(inputL1==0&&inputL2==0&&inputR1==1&&inputR2==0) //0010
- {
- weitiao2();
- }
- if(inputL1==0&&inputL2==0&&inputR1==0&&inputR2==1) //0001
- {
- dazhuan2() ;
- }
- else
- {
- zhizou();
- }
- }
- void zhizou()
- {
- Infrared = inputL1==1&&inputL2==1&&inputR1==1&&inputR2==1;
- Motor_Left_Q(1, 100), Motor_Right_Q(1, 100);
- Motor_Left_H(1, 100), Motor_Right_H(1, 100);
-
- }
- void dazhuan1() //左大轉(zhuǎn)/ 1000
- {
- Motor_Left_Q(0, 200); Motor_Right_Q(1, 200);
- Motor_Left_H(0, 200); Motor_Right_H(1, 200);
-
- }
- void dazhuan2() //右大轉(zhuǎn)/ 0001
- {
-
- Motor_Left_Q(1, 200); Motor_Right_Q(0, 200);
- Motor_Left_H(1, 200); Motor_Right_H(0, 200);
- }
- void weitiao1() //左微調(diào)/ 0100
- {
-
- Motor_Left_Q(1, 10); Motor_Right_Q(1, 100);
- Motor_Left_H(1, 10); Motor_Right_H(1, 100);
- Infrared = inputL1==0&&inputL2==1&&inputR1==0&&inputR2==0;
-
- }
- void weitiao2()//右微調(diào)/ 0010
- {
- Motor_Left_Q(1, 100); Motor_Right_Q(1, 10);
- Motor_Left_H(1, 100); Motor_Right_H(1, 10);//60
- Infrared = inputL1==0&&inputL2==0&&inputR1==1&&inputR2==0;
- }
- void stop()
- {
- Motor_Left_Q(1, 0), Motor_Right_Q(1, 0);
- Motor_Left_H(1, 0), Motor_Right_H(1, 0);
- }
- void Timer0Config()
- {
- TMOD &= 0xF0;
- TMOD |= 0x01;
- TH0 = 0xFF;
- TL0 = 0x7E;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
復(fù)制代碼 |
-
-
motor,test.zip
2024-4-10 13:36 上傳
點(diǎn)擊文件名下載附件
25.55 KB, 下載次數(shù): 4
仿真
-
-
程序測試.zip
2024-4-11 12:46 上傳
點(diǎn)擊文件名下載附件
106.07 KB, 下載次數(shù): 4
其中的個人嘗試為原文件
|