資源簡(jiǎn)介
基于51的直流電機(jī)pwm控制
pwm波形由軟件生成。
可調(diào)速,控制方向。

代碼片段和文件信息
??/*以下是一段產(chǎn)生占空比為20%的脈沖信號(hào)的c51程序,我想電機(jī)轉(zhuǎn)速*/
??/*對(duì)應(yīng)于一定的占空比,如果你要改變占空比,可能需要建立一個(gè)對(duì)應(yīng)*/
??/*于不同轉(zhuǎn)速的參數(shù)表(如定時(shí)器初值等),查表*/
??/*得到不同參數(shù),以改變占空比和轉(zhuǎn)速。你用什么驅(qū)動(dòng)電路?*/
???
??/*采用6MHz晶振,在P1.0腳上輸出周期為2.5s占空比為20%的脈沖信號(hào)*/???
??/*定時(shí)100ms周期2.5s需25次中斷,高電平0.5s需5次中斷*/???
????
#include??????
??typedef???unsigned???char???uchar;???
??sbit???P0_0=P0^0;
??sbit???P0_1=P0^1;?
??sbit???P0_2=P0^2;
??sbit???P0_3=P0^3;?
??sbit???P2_0=P2^0;
??sbit???P2_1=P2^1;?
??uchar???time=0;???
??uchar???period=25;???
??uchar???high=10;
??uchar???th1=0;
??uchar???tl1=0;
??uchar???th0=0;
??uchar???tl0=0;?????
????
??void???timer0()???interrupt???1???using???1???
??{???
????????????TH0=0x3c;?????/*定時(shí)器初值重裝載*/???
????????????TL0=0xb0;
????????????//TH0=0xc3;/*定時(shí)器初值重裝載*/
//TL0=0x50;??
????????????time++;???
????????????if(time==high)???/*高電平持續(xù)時(shí)間結(jié)束,變低*/???
????????????{???P2_0=tl0;
????P2_1=tl1;
??}???
????????????else???if(time==period)?????/*周期時(shí)間到,變高*/???
??????????????????????{???time=0;???
??????????????????????????P2_0=th0;
??P2_1=th1;
?????
??????????????????????}???
????
??}???
????
??void???main()???
??{???
????????TMOD=0x01;???/*定時(shí)器0方式1*/???
????????TH0=0x3c;?????/*定時(shí)器裝載初值,設(shè)置脈沖信號(hào)的占空比為1/5*/???
????????TL0=0xb0;?
//TH0=0xc3;/*定時(shí)器裝載初值設(shè)置脈沖信號(hào)的占空比為4/5*/
//TL0=0x50;????
????????EA=1;?????/*開CPU中斷*/???
????????ET0=1;???/*開定時(shí)器0中斷*/???
????????TR0=1;/*啟動(dòng)定時(shí)器0*/??
if(P0_2==1)
?{
??th0=1;
??tl0=0;
???? ??th1=0;
??tl1=0;
??????}
??????????if(P0_3==1)
?{
??th0=0;
??tl0=0;
???? ??th1=1;
??tl1=0;
??????}
while(1)?????/*等待中斷*/???
????????{}???
????
??}???
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????113379??2007-08-15?22:52??PWM_motor\Last?Loaded?PWM_motor.DBK
?????文件???????4476??2007-08-15?22:47??PWM_motor\PWM
?????文件????????911??2007-08-15?22:47??PWM_motor\PWM.hex
?????文件?????????50??2007-08-15?22:47??PWM_motor\PWM.lnp
?????文件???????7556??2007-08-15?22:47??PWM_motor\PWM.M51
?????文件???????1496??2007-08-20?10:32??PWM_motor\PWM.Opt
?????文件????????189??2007-08-24?11:46??PWM_motor\PWM.plg
?????文件???????2169??2007-08-15?22:44??PWM_motor\PWM.Uv2
?????文件???????1895??2007-08-14?22:37??PWM_motor\PWM_motor.c
?????文件?????113379??2007-08-15?22:52??PWM_motor\PWM_motor.DSN
?????文件???????4263??2007-08-14?22:37??PWM_motor\PWM_motor.LST
?????文件???????3385??2007-08-14?22:37??PWM_motor\PWM_motor.OBJ
?????文件????????189??2007-08-14?16:56??PWM_motor\PWM_motor.plg
?????文件???????1078??2006-01-29?13:12??PWM_motor\PWM_motor.PWI
?????文件???????2184??2007-08-15?22:47??PWM_motor\PWM_motor_test.c
?????文件???????5808??2007-08-15?22:47??PWM_motor\PWM_motor_test.LST
?????文件???????4332??2007-08-15?22:47??PWM_motor\PWM_motor_test.OBJ
?????文件???????1365??2007-08-18?22:05??PWM_motor\PWM_Opt.Bak
?????文件???????2169??2007-08-15?22:31??PWM_motor\PWM_Uv2.Bak
?????文件???????6376??2005-03-22?15:22??PWM_motor\STARTUP.A51
?????文件??????14062??2007-08-15?22:47??PWM_motor\STARTUP.LST
?????文件????????758??2007-08-15?22:47??PWM_motor\STARTUP.OBJ
?????文件????????138??2007-08-14?22:18??PWM_motor\test.c
?????文件???????1131??2007-08-15?09:50??PWM_motor\test.LST
?????文件???????2293??2007-08-15?09:50??PWM_motor\test.OBJ
?????文件????3237662??2006-01-29?13:12??PWM_motor\電路.bmp
?????目錄??????????0??2009-02-27?13:49??PWM_motor
-----------?---------??----------?-----??----
??????????????3532693????????????????????27
............此處省略0個(gè)文件信息
評(píng)論
共有 條評(píng)論