直流电机+PWM+测速显示(1)
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
case '7': { a=110; dprintf(0,96,"120 r/min"); control(); break; }
case '8': { a=130; dprintf(0,96,"135 r/min"); control(); break; }
case '9': { a=150; dprintf(0,96,"150 r/min"); control(); break; }
count++;//每定时中断一次,就加一
k1+=TL0;
if(count==51)
{
sprintf(dsp,"%3d",k1);//转化???
dprintf(0,108,dsp);
dprintf(60,108,"r/min");
count=1;
k1=0;
}
TH1=0x3c;
TL1=0xb0;
TH0=0x00;
}
else
if(key=='*')
{ P1_1=0;
break;
}
else
if(key!=0)
break;//此处跳出循环回到主程序
}
EA=0;
}
TL0=0x00;
TR1=1;
}
void control()
{
EA=1;//开启计数中断,测速用
while(1)
{ if(a>=150)
a=150;
if(a<=10)
a=10;
P1_1=0;//关闭电动机脉冲输出
delay(160-a);
P1_1=1;//开启电动机
delay(a);
key=GeyKey();
if(!P3_1)return '2';
if(!P3_2)return '3';
if(!P3_3)return '-';
P1_4=1;
P1_5=1;
P1_6=1;
P1_7=0;
_nop_();_nop_();
if(!P3_0)return 'c';
if(!P3_1)return '0';
if(!P3_2)return '=';
dprintf(0,12,"键盘+:步长加速");
dprintf(0,24,"键盘-:步长减速");
dprintf(0,36,"键盘=:顺时针转");
dprintf(0,48,"键盘on/c:逆时针转");
dprintf(0,72,"方向:");
dprintf(0,84,"转速:");
TMOD=0x15;//T1为16位计时器,T0为16位计数器2的16次方
if(key=='-') a-=n;//每次调整步长为n=5
else
if(key=='+') a+=n;
else
if(key=='=')
{ P1_0=1;//调整为顺时针
dprintf(0,72,"方向:顺时针");
}
else
if(key=='c')//调整为逆时针
{ P1_0=0;
dprintf(0,72,"方向:逆时针");
case 'c': {P1_0=0;dprintf(0,72,"方向:逆时针");control();break;}
case '/': {dprintf(0,72,"方向:顺时针");break;}
default: break;
}
}
}
uchar GeyKey()
{
P1_4=0;
P1_5=1;
P1_6=1;
#include <showfun.h>
#include <stdio.h>
extern char fnLCMInit(); // LCM初始化
extern void at(unsigned char x,unsigned char y);/*设定文本x,y值*/
extern void cls();//清屏
dprintf(0,96," 5 r/min");
//dprintf(0,96,abc);
dprintf(60,96,"r/min");
control();
break; }
case '2': { a=25;dprintf(0,96," 25 r/min"); control(); break; }
case '3': { a=40; dprintf(0,96," 40 r/min"); control(); break; }
extern void charout(unsigned char *str); //ASCII(8*8)显示函数
extern void fnSetPos(unsigned char urow, unsigned char ucol);//设置当前地址
extern uchar dprintf(uchar x,uchar y,char *fmt);// ASCII(8*16)及汉字(16*16)显示函数
P1_7=1;
P3_0=1;
P3_1=1;
P3_2=1;
P3_3=1;
_nop_();_nop_();
if(!P3_0)return '7';
if(!P3_1)return '8';
if(!P3_2)return '9';
if(!P3_3)return '/';
P1_4=1;
P1_5=0;
P1_6=1;
P1_7=1;
_nop_();_nop_();
ifຫໍສະໝຸດ Baidu!P3_0)return '4';
if(!P3_1)return '5';
if(!P3_2)return '6';
if(!P3_3)return '*';
P1_4=1;
P1_5=1;
P1_6=0;
P1_7=1;
_nop_();_nop_();
if(!P3_0)return '1';
case '+': {
P1_0=1;
dprintf(0,72,"方向:顺时针");
control();
break;
}
case '-': { P1_0=0;
dprintf(0,72,"方向:逆时针");
control();
break;
}
case '=': {P1_0=1;dprintf(0,72,"方向:顺时针");control();break;}
uchar n=5;
uchar count=1;
uint k1=0;
uchar GeyKey();
void delay(uchar i);
void control();
main()
{
P1_1=0;
fnLCMInit();//液晶初始化
fnSetPos(0,0);//液晶设置当前地址
dprintf(0,0,"直流电机加-减速及测速系统");
extern void Pixel(unsigned char PointX,unsigned char PointY, bit Mode);
uchar dsp[10]={0,0,0,0,0,0,0,0,0,0,};
char abc[3]={0,0,0,};
uchar key=0;
uint a=100;
TH1=0x3c;
TL1=0xb0;//没怎么用可删
TH0=0x00;
TL0=0x00;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
P1_1=0;
key=GeyKey();
switch(key)
{ case '1': { a=10;
//sprintf(abc,"%3.2f",a/255.0);
if(!P3_3)return '+';
return 0;
}
void delay(uchar i)
{ uchar j,k;
for(;i>0;i--)
for(j=15;j>0;j--)
for(k=11;k>0;k--);
}
void time()interrupt 3//计时器T1----用于测速
{
TR1=0;
case '4': { a=55; dprintf(0,96," 60 r/min"); control(); break; }
case '5': { a=70; dprintf(0,96," 80 r/min"); control(); break; }
case '6': { a=90; dprintf(0,96,"100 r/min"); control(); break; }
extern uchar fnPR12(uchar uCmd); //写无参数的指令
extern uchar fnPR13(uchar uData); //写数据
extern unsigned int Adc0832(unsigned char channel);
extern void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode);
case '8': { a=130; dprintf(0,96,"135 r/min"); control(); break; }
case '9': { a=150; dprintf(0,96,"150 r/min"); control(); break; }
count++;//每定时中断一次,就加一
k1+=TL0;
if(count==51)
{
sprintf(dsp,"%3d",k1);//转化???
dprintf(0,108,dsp);
dprintf(60,108,"r/min");
count=1;
k1=0;
}
TH1=0x3c;
TL1=0xb0;
TH0=0x00;
}
else
if(key=='*')
{ P1_1=0;
break;
}
else
if(key!=0)
break;//此处跳出循环回到主程序
}
EA=0;
}
TL0=0x00;
TR1=1;
}
void control()
{
EA=1;//开启计数中断,测速用
while(1)
{ if(a>=150)
a=150;
if(a<=10)
a=10;
P1_1=0;//关闭电动机脉冲输出
delay(160-a);
P1_1=1;//开启电动机
delay(a);
key=GeyKey();
if(!P3_1)return '2';
if(!P3_2)return '3';
if(!P3_3)return '-';
P1_4=1;
P1_5=1;
P1_6=1;
P1_7=0;
_nop_();_nop_();
if(!P3_0)return 'c';
if(!P3_1)return '0';
if(!P3_2)return '=';
dprintf(0,12,"键盘+:步长加速");
dprintf(0,24,"键盘-:步长减速");
dprintf(0,36,"键盘=:顺时针转");
dprintf(0,48,"键盘on/c:逆时针转");
dprintf(0,72,"方向:");
dprintf(0,84,"转速:");
TMOD=0x15;//T1为16位计时器,T0为16位计数器2的16次方
if(key=='-') a-=n;//每次调整步长为n=5
else
if(key=='+') a+=n;
else
if(key=='=')
{ P1_0=1;//调整为顺时针
dprintf(0,72,"方向:顺时针");
}
else
if(key=='c')//调整为逆时针
{ P1_0=0;
dprintf(0,72,"方向:逆时针");
case 'c': {P1_0=0;dprintf(0,72,"方向:逆时针");control();break;}
case '/': {dprintf(0,72,"方向:顺时针");break;}
default: break;
}
}
}
uchar GeyKey()
{
P1_4=0;
P1_5=1;
P1_6=1;
#include <showfun.h>
#include <stdio.h>
extern char fnLCMInit(); // LCM初始化
extern void at(unsigned char x,unsigned char y);/*设定文本x,y值*/
extern void cls();//清屏
dprintf(0,96," 5 r/min");
//dprintf(0,96,abc);
dprintf(60,96,"r/min");
control();
break; }
case '2': { a=25;dprintf(0,96," 25 r/min"); control(); break; }
case '3': { a=40; dprintf(0,96," 40 r/min"); control(); break; }
extern void charout(unsigned char *str); //ASCII(8*8)显示函数
extern void fnSetPos(unsigned char urow, unsigned char ucol);//设置当前地址
extern uchar dprintf(uchar x,uchar y,char *fmt);// ASCII(8*16)及汉字(16*16)显示函数
P1_7=1;
P3_0=1;
P3_1=1;
P3_2=1;
P3_3=1;
_nop_();_nop_();
if(!P3_0)return '7';
if(!P3_1)return '8';
if(!P3_2)return '9';
if(!P3_3)return '/';
P1_4=1;
P1_5=0;
P1_6=1;
P1_7=1;
_nop_();_nop_();
ifຫໍສະໝຸດ Baidu!P3_0)return '4';
if(!P3_1)return '5';
if(!P3_2)return '6';
if(!P3_3)return '*';
P1_4=1;
P1_5=1;
P1_6=0;
P1_7=1;
_nop_();_nop_();
if(!P3_0)return '1';
case '+': {
P1_0=1;
dprintf(0,72,"方向:顺时针");
control();
break;
}
case '-': { P1_0=0;
dprintf(0,72,"方向:逆时针");
control();
break;
}
case '=': {P1_0=1;dprintf(0,72,"方向:顺时针");control();break;}
uchar n=5;
uchar count=1;
uint k1=0;
uchar GeyKey();
void delay(uchar i);
void control();
main()
{
P1_1=0;
fnLCMInit();//液晶初始化
fnSetPos(0,0);//液晶设置当前地址
dprintf(0,0,"直流电机加-减速及测速系统");
extern void Pixel(unsigned char PointX,unsigned char PointY, bit Mode);
uchar dsp[10]={0,0,0,0,0,0,0,0,0,0,};
char abc[3]={0,0,0,};
uchar key=0;
uint a=100;
TH1=0x3c;
TL1=0xb0;//没怎么用可删
TH0=0x00;
TL0=0x00;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
P1_1=0;
key=GeyKey();
switch(key)
{ case '1': { a=10;
//sprintf(abc,"%3.2f",a/255.0);
if(!P3_3)return '+';
return 0;
}
void delay(uchar i)
{ uchar j,k;
for(;i>0;i--)
for(j=15;j>0;j--)
for(k=11;k>0;k--);
}
void time()interrupt 3//计时器T1----用于测速
{
TR1=0;
case '4': { a=55; dprintf(0,96," 60 r/min"); control(); break; }
case '5': { a=70; dprintf(0,96," 80 r/min"); control(); break; }
case '6': { a=90; dprintf(0,96,"100 r/min"); control(); break; }
extern uchar fnPR12(uchar uCmd); //写无参数的指令
extern uchar fnPR13(uchar uData); //写数据
extern unsigned int Adc0832(unsigned char channel);
extern void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode);