51单片机控制直流电机PWM调速C语言程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includereg52.h#defineucharunsignedchar#defineuintunsignedintsbitKEY1=P3^4;sbitKEY2=P3^5;sbitKEY3=P3^6;sbitIN1=P1^0;sbitIN2=P1^1;sbitENA=P1^2;sfrldata=0x80;sbitdula=P2^6;sbitwela=P2^7;//sbitlcden=P3^4;//uchartimer,ms,t_set=1;ucharT_N=100;ucharT_N1=100;ucharT_H_N=50;ucharT_H_N1=50;voidmsplay(uchar,uchar);ucharcodex1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//ucharcodex2[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};ucharcodex3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//ucharcodex4[]={0x01,0x02,0x04,0x08,0x10,0x20};voiddelay(uintz)//延时函数{uintx;for(x=z;x0;x--);}voidKey_Scan(){if(KEY1==0){delay(20);while(!KEY1);T_H_N++;if(T_H_N=99){T_H_N=99;}}if(KEY2==0){delay(20);while(!KEY2);T_H_N--;if(T_H_N=1){T_H_N=1;}}if(KEY3==0){delay(15);while(!KEY3);IN1=~IN1;IN2=~IN2;}}voidMotor_Init(){ENA=0;IN1=1;IN2=0;}voidTimer0_Init(){TMOD=0X12;TH0=(256-50);TL0=(256-50);//TH1=(65535-T_H)/256;//TL1=(65535-T_H)%256;EA=1;ET0=1;TR0=1;}voidmain(){uchark3,k2,k1,k0;Timer0_Init();Motor_Init();while(1){k2=T_H_N/10;k3=T_H_N%10;k1=0;k0=0;msplay(k0,2);msplay(k1,3);msplay(k2,4);msplay(k3,5);Key_Scan();}}voidtimer0()interrupt1{TR0=0;//TH0=(65536-50)/256;//TL0=(65536-50)%256;T_H_N1--;if(0==T_H_N1){ENA=0;T_H_N1=1;}T_N1--;if(T_N1==0){ENA=1;T_N1=100;T_H_N1=T_H_N;}TR0=1;}voidmsplay(uchary1,uchary2){ldata=x1[y1];dula=1;dula=0;delay(1);ldata=x3[y2];wela=1;wela=0;delay(1);ldata=0x00;dula=1;dula=0;delay(1);ldata=0x0ff;wela=1;wela=0;delay(1);}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功