欢迎来到天天文库
浏览记录
ID:57377552
大小:13.50 KB
页数:3页
时间:2020-08-13
《电机转速调节程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintuintTimer1Val;uintTimer1Val_H;uintTimer1Val_L;uintTimer0Val;uintTimer0Val_H;uintTimer0Val_L;uintpred=520;uintpred_h=258;sbitPin=P2^0;sbitslower=P3^0;sbitfaster=P3^3;voiddelay(void)//误差-0.2us{unsignedchara,b,c;for(c=1;c
2、>0;c--)for(b=254;b>0;b--)for(a=13;a>0;a--);}voidmain(){slower=1;faster=1;TMOD=0x11;//定时器0,1工作方式116位ET0=1;ET1=1;EA=1;Timer1Val=65535-pred_h;Timer0Val=65535-pred;Timer1Val_H=(Timer1Val&0xff00)>>8;Timer1Val_L=Timer1Val&0x00ff;Timer0Val_H=(Timer0Val&0xff00)>>8;Timer0Val_L=Timer0Val&0x
3、00ff;TH0=Timer0Val_H;//十六位TL0=Timer0Val_L;TH1=Timer1Val_H;TL1=Timer1Val_L;TR0=1;while(1){if(slower==0){delay();if(slower==0){slower=1;Timer1Val+=100;//高电平宽度变窄10ms}}if(faster==0){delay();if(faster==0){faster=1;Timer1Val-=100;}}}}voidTimer0()interrupt1{TH0=Timer0Val_H;//十六位的!!!TL0=T
4、imer0Val_L;Pin=1;TR1=1;}voidTimer1()interrupt3{TH1=Timer1Val_H;TL1=Timer1Val_L;Pin=0;TR1=0;}
此文档下载收益归作者所有