下面這個馬達正反轉程序是我用論壇里的紅綠燈程序改的,存在以下問題:1.開機直接就啟動了,需求是按下P2^0才啟動,P2^0是點動開關;
2.反轉后停止,現在是直接就停止了,需求在停止需保持1秒再斷開;
另外有點不理解的是
case 1:
start=1;cw=0;ccw=1;stop=1;這里啟動不是關閉的嗎,為什么會通呢。
各位幫忙看看是需要改動哪里。
感謝!
單片機源程序如下:
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit start = P2^0; //啟動
- sbit cw = P2^1; //馬達正轉
- sbit ccw = P2^2; //馬達反轉
- sbit stop = P2^3; //馬達停止
- uchar Time_Count = 0,Flash_Count = 0,Operation_Type = 1;
- void T0_INT() interrupt 1
- {
- TH0 = -50000/256;
- TL0 = -50000%256;
- switch(Operation_Type)
- {
- case 1:
- start=1;cw=0;ccw=1;stop=1;
- if(++Time_Count != 10) return;
- Time_Count=0;
- Operation_Type = 2;
- break;
- case 2:
- start=1;cw=1;ccw=0;stop=1;
- if(++Time_Count != 100) return;
- Time_Count=0;
- Operation_Type = 3;
- break;
- case 3:
- start=1;cw=1;ccw=1;stop=0;
- if(++Time_Count != 100) return;
- Time_Count=0;
- Operation_Type = 4;
- break;
- case 4:
- start=1;cw=1;ccw=1;stop=1;
- if(++Time_Count != 10) return;
- Time_Count=0;
- break;
- }
- }
- void main()
- {
- TMOD = 0x01;
- IE = 0x82;
- TR0 = 1;
- while(1);
- }
復制代碼 |