电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

单片机三相脉冲触发C程序VIP专享VIP免费

单片机三相脉冲触发C程序_第1页
单片机三相脉冲触发C程序_第2页
单片机三相脉冲触发C程序_第3页
//整个控制过程为先键入所要的控制角,控制角被计算成相应的触发延时时间,//并等待当单片机检测到外部中断信号。当检测到外部中断信号后启动定时器1延时相应的时间,//之后接着启动定时器0并产生发出六脉冲信号经过变换放大触发相应的晶闸管导通,以获得相应的电压#include//#include#include#defineuintunsignedint#defineucharunsignedcharucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};uchartemp;ucharnum;//键盘返回值ucharjishu;ucharge;ucharshi;ucharshijian;floatdingshi;uintdingshi_1;sbitdula=P2^6;sbitwela=P2^7;//sbitA_1=P2^6;//sbitB_1=P2^7;sbitug_1=P1^2;//脉冲输出引脚定义1.2-7sbitug_2=P1^3;sbitug_3=P1^4;sbitug_4=P1^5;sbitug_5=P1^6;sbitug_6=P1^7;ucharjs=0;//六脉冲计数器voidinit()//定时器、中断初始化函数{TMOD=0x11;EA=1;ET0=1;ET1=1;TR1=0;TR0=0;IP=0x08;//T1weigaoyouxianjiIP=0x09?//IPH=0x01;IT0=1;//外中断0为下降沿触发TCON中设置TH0=(65536-1667)/256;//定时时间,即脉冲宽度TL0=(65536-1667)%256;}voiddelay(uintz)//1ms延时{uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voiddisplay(ucharshi,ucharge){dula=1;P0=table[shi];dula=0;P0=0xff;wela=1;P0=0xfe;wela=0;delay(5);dula=1;P0=table[ge];dula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delay(5);}ucharKeyboard(){P3=0xfe;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){jishu++;temp=P3;switch(temp){case0xee:num=1;break;case0xde:num=2;break;case0xbe:num=3;break;case0x7e:num=4;break;}while(temp!=0xf0)//松手检测{temp=P3;temp=temp&0xf0;}}}P3=0xfd;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){jishu++;temp=P3;switch(temp){case0xed:num=5;break;case0xdd:num=6;break;case0xbd:num=7;break;case0x7d:num=8;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xfb;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){jishu++;temp=P3;switch(temp){case0xeb:num=9;break;case0xdb:num=10;break;case0xbb:num=11;break;case0x7b:num=12;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xf7;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){jishu++;temp=P3;switch(temp){case0xe7:num=13;break;case0xd7:num=14;break;case0xb7:num=15;break;case0x77:num=16;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}returnnum;}voidmain(){init();EX0=1;dula=1;P0=0x3f;dula=0;P0=0xff;wela=1;P0=0xfc;wela=0;delay(5);while(1){Keyboard();if(jishu==1)//按键一次shiwei{shi=num;}if(jishu==2)//按键两次gewei{ge=num;jishu=0;}shijian=shi*10+ge;dingshi=((shijian+30)/360)*20;//*1000;F=50HZ,工频电源,T=20MSdisplay(shi-1,ge-1);}}/*从同步电压跳跃点算起经控制角α+30°的延时,将α+30°转化为C/T1的时间常数,在同步电压跳跃点开始定时,C/T1溢出时,在中断中置入新的时间常数,其数据对应的定时时间为工频交流电的30°脉宽时间,并且启动T0,在T0中断中输出6路脉冲。*///3最后进入的中断voidzhongduan()interrupt1//定时器t0中断函数{js++;//js为6脉冲计数值,执行完该语句JS=1TH0=(65536-1667)/256;TL0=(65536-1667)%256;if(js==1){ug_6=0;ug_1=0;}if(js==2){ug_1=1;ug_2=1;}if(js==3){ug_1=0;ug_2=0;}if(js==4){ug_2=1;ug_3=1;}if(js==5){ug_2=0;ug_3=0;}if(js==6){ug_3=1;ug_4=1;}if(js==7){ug_3=0;ug_4=0;}if(js==8){ug_4=1;ug_5=1;}if(js==9){ug_4=0;ug_5=0;}if(js==10){ug_5=1;ug_6=1;}if(js==11){ug_5=0;ug_6=0;}if(js==12){ug_6=1;ug_1=1;js=0;}}//2其次进入的中断voidT1_dingshi()interrupt3{TR1=0;TH0=(65536-1667)/256;//脉宽定时时间为脉冲宽度30°所对应的时间约1.667MS,其中晶振12MHZ,工频f=50HZTL0=(65536-1667)%256;TR0=1;//启动定时器0}//1首先进入的中断同步脉冲为矩形脉冲(经变换过的)且为反向(经过反相器,因为触发方式为下降沿触发)voidINT0_tongbu()interrupt0{dingshi_1=dingshi;TH1=(65536-dingshi_1)/256;TL1=(65536-dingshi_1)%256;TR1=1;//T1在同步信号到来后才启动的,初始化中未启动!T1控制α角的大小!}

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部