直流电机仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
直流电机正反转单片机源程序如下:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit IN1 = P2^0;
- sbit IN2 = P2^1;
- sbit PWM = P2^2;
- sbit Key1 = P1^7;
- sbit Key2 = P1^6;
- sbit Key3 = P1^5;
- sbit Key4 = P1^4;
- sbit Key5 = P1^3;
- uint t = 46082;
- void delay_ms(uchar t)
- {
- uchar x,y;
- for(x = t;x > 0;x--)
- for(y = 110;y > 0;y--);
- }
- void Timer0_Init()
- {
- TMOD = 0X01;
- TH0 = (65536 - 46082)/256;
- TL0 = (65536 - 46082)%256;
- EA = 1 ;
- ET0 = 1;
- TR0 = 1;
- }
- void Positive_Rotation()
- {
- IN1 = 0;
- IN2 = 1;
- }
- void Reverse_Rotation()
- {
- IN1 = 1;
- IN2 = 0;
- }
- void Stop_Rotation()
- {
- IN1 = 1;
- IN2 = 1;
- }
- void Key_Scan()
- {
- if(Key1 == 0)
- {
- delay_ms(20);
- if(Key1 == 0)
- {
- Positive_Rotation();
- }
- }
- else if(Key2 == 0)
- {
- delay_ms(20);
- if(Key2 == 0)
- {
- Reverse_Rotation();
- }
- }
- else if(Key3 == 0)
- {
- delay_ms(20);
- if(Key3 == 0)
- {
- Stop_Rotation();
- }
- }
复制代码
所有资料51hei提供下载:
直流电机Keil Proteus仿真.zip
(80.07 KB, 下载次数: 43)
|