📄 dcpwm.cpp
字号:
//PWM.CPP
#include<dos.h>
#include<conio.h>
#include<stdio.h>
char *title="Test dc motor use PWM method";
#define PC 0x302
#define CR 0x303
void rotate(float per); /*相当于画波形函数*/
void main()
{
char ch;
outportb(CR,0x90); /*8255状态字,PC低四位输出*/
outportb(PC,0xff); /*PC口各位写1*/
clrscr();
puts(title);
puts("1------>100% duty cycle");
puts("2------>50% duty cycle");
puts("3------>25% duty cycle");
puts("4------>12% duty cycle");
puts("5------>exit");
while(1)
if(kbhit())
{
ch=getch();
switch(ch)
{
case '1': rotate(1.0);
break;
case '2': rotate(0.75);
break;
case '3': rotate(0.5);
break;
case '4': rotate(0.25);
break;
case '5': return ;
default:break;
}
}
outportb(PC,0xff);
}
/*-----------------------------------*/
void rotate(float per)
{
int c,ton,toff;
gotoxy(10,10);
printf("duty: %2.2f ",per);
ton=(int) 100*per;
toff=100-ton;
for(c=0;c<20;c++)
{
outportb(PC,0);
delay(ton);
outportb(PC,1);
delay(toff);
}
delay(200);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -