|
單片機(jī)控制的直流電機(jī)測(cè)速,歡迎大家參考.
0.png (31.81 KB, 下載次數(shù): 108)
下載附件
2017-5-29 02:13 上傳
0.png (70.53 KB, 下載次數(shù): 117)
下載附件
2017-5-29 02:13 上傳
單片機(jī)源程序如下:
- #include <reg51.h>
- #include <math.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ON 0
- #define OFF 1
- sbit PWM=P3^5;
- sbit MP=P3^4;
- bit FLAG=0;
- uchar code dispbit[6]=
- {
- 0x20,0x10,0x08,0x04,0x02,0x01
- }
- ;
- uchar code seg[]=
- {
- 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90
- }
- ;
- //0,1,2,3,4,5,6,7,8,9
- uchar disbuf[6]=
- {
- 0,0,0,0,10,10
- }
- ;
- uint temp[6];
- uint discount=0;
- uint timecount=0;
- //定時(shí)的次數(shù)
- uint T0count=0;
- uint hus=0;
- uint k=60;
- uint Vc;
- uint Vs;
- uint tm=3000;
- uint x;
- void t0_serv()interrupt 1
- {
- T0count++;
- }
- void t1_serv()interrupt 3
- {
- PWM=1;
- TH1=(65536-tm)/256;
- TL1=(65536-tm)%256;
- hus++;
- if(hus==tm)
- {
- PWM=0;
- TH1=(25536+tm)/256;
- TL1=(25536+tm)%256;
-
- }
- timecount++;
- if(timecount==250)
- {
- //FLAG=1;
- TR0=0;
- hus=0;
- timecount=0;
- Vc=T0count*65536+TH0*256+TL0;
- Vs=144;
- if(abs(Vc-Vs)>5)
- {
- tm=abs(k*(Vc-Vs));
- T0count=0;
- TR0=1;
- TR1=1;
- ET0=1;
- ET1=1;
- EA=1;
- }
- FLAG=1;
- TR0=0;
- timecount=0;
- }
- P0=dispbit[discount];
- P1=seg[disbuf[discount]];
- discount++;
- if(discount==6)
- {
- discount=0;
- }
- }
- void main()
- {
- uint i;
- TMOD=0x15;
- TH0=0;
- TL0=0;
- TH1=(65536-tm)/256;
- TL1=(65536-tm)%256;
- TR0=1;
- TR1=1;
- ET0=1;
- ET1=1;
- EA=1;
- while(1)
- {
- if(FLAG==1)
- {
- FLAG=0;
- x=T0count*65536+TH0*256+TL0;
- for(i=0;i<6;i++)
- {
- temp[i]=0;
- }
- i=0;
- while(x/10)
- {
- temp[i]=x%10;
- x=x/10;
- i++;
- }
- temp[i]=x;
- for(i=0;i<6;i++)
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
C51直流電機(jī)PWM測(cè)速源程序.rar
(26.37 KB, 下載次數(shù): 101)
2017-5-28 22:42 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|