下面这个马达正反转程序是我用论坛里的红绿灯程序改的,存在以下问题: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);
- }
复制代码 |