仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- /**********************************************************
- 直流电机正、反转调速控制
- ***********************************************************/
- #include <REGX52.H>
- sbit led_n=P0^0;
- sbit led_r=P0^1;
- sbit led_s=P0^2;
- sbit ZZ=P2^0;
- sbit FZ=P2^1;
- sbit TZ=P2^2;
- sbit IN1=P1^0;
- sbit IN2=P1^1;
- sbit ENA=P1^2;
- int count=0;
- void delayms(unsigned char xms)
- {
- unsigned char i,j;
- for(i=xms;i>0;i--)
- for(j-110;j>0;j--);
- }
- void keyscan()
- {
- if(ZZ==0)
- {
- delayms(10);
- if(ZZ==0)
- {
- while(ZZ==0);
- IN1=1;
- IN2=0;
- led_n=0;
- led_r=1;
- led_s=1;
- }
- }
- if(FZ==0)
- {
- delayms(10);
- if(FZ==0)
- {
- while(FZ==0);
- IN1=0;
- IN2=1;
- }
- }
- if(TZ==0)
- {
- delayms(10);
- if(TZ==0)
- {
- while(TZ==0);
- IN1=0;
- IN2=0;
- }
- }
- }
- void main()
- {
- TMOD=0x01;
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- EA=1;
- ET0=1;
-
- TR0=1;
-
- while(1)
- {
- keyscan();
- }
- }
- void T0_isr() interrupt 1
- {
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- count++;
- if(count>7)
- {
- ENA=0;
- }
- else
- {
- ENA=1;
- }
- if(count>=10)
- {
- count=0;
- }
-
- }
复制代码
所有资料51hei提供下载:
直流电机.zip
(125.68 KB, 下载次数: 88)
|