李祥2332直流电机控制.docx
- 文档编号:25893115
- 上传时间:2023-06-16
- 格式:DOCX
- 页数:22
- 大小:211.38KB
李祥2332直流电机控制.docx
《李祥2332直流电机控制.docx》由会员分享,可在线阅读,更多相关《李祥2332直流电机控制.docx(22页珍藏版)》请在冰豆网上搜索。
李祥2332直流电机控制
信息科学与技术学院
单片机原理及应用
课程设计报告
题目名称:
直流电机控制系统
专业年级:
电子信息工程09级
指导老师:
刘恩博
学生姓名:
李祥
学号:
2009082332
时间:
2012年7月5日
目录
1、题目与要求...................................3
2、设计思路.....................................3
3、系统框图.....................................3
1.系统仿真图.........................................4
2.输入模块...........................................5
3.显示模块...........................................5
4.驱动模块...........................................6
5.系统功能...........................................6
四、源程序.......................................7
一、题目与要求:
题目:
直流电机控制
要求:
1、可控制启动停止;2、可控制旋转角度;3显示状态
二、设计思路
直流电机系统由以下电路模块组成:
振荡器和时钟电路:
这部分电路主要由80C51单片机和一些电容、晶振组成。
设计输入部分:
这一模块主要是利用带中断的独立式键盘来实现。
设计控制部分:
主要由80C51单片机的外部中断扩展电路组成。
设计显示部分:
包括液晶显示部分。
液晶显示部分由LCD液晶显示模块组成。
直流电机PWM控制实现部分:
主要由一些二极管、电机和L298直流电机驱动模块组成。
三、系统框图
以AT89C51单片机为控制核心,由输入模块、显示模块和电机驱动模块组成。
图1.系统框图
系统仿真图
图2.系统仿真图
输入模块
单片机外部中断有两种触发方式,一种是电平触发方式,另一种是脉冲触发方式,单片机外部中断触发方式与TCON的IT位有关。
图3.输入模块
显示模块
图4.显示模块
驱动模块
直流电机由定子和转子两部分组成。
直流电机的转速由回在电枢两端的电压决定,电枢电压越高,电机转速就越快,电枢电压降低到0V时,电机就停止转动;改变电枢电压的极性,电机就反转。
图5.驱动模块
系统功能
直流电机PWM调制控制系统具有加速、减速、开启、停止控制功能。
操作开关通过中断控制直流电机的加速、减速、开启、停止控制功能,并通过LCD液晶显示。
振荡、时钟电路和复位电路由89C51单片机内部给出。
直流电机转动速度由LCD液晶显示。
操作开关状态由液晶显示器显示。
四、源程序:
#include
#include
#include
#defineucunsignedchar
#defineuiunsignedint
#defineLCDPAGE0xB8//设置页指令。
#defineLCDLINE0x40//设置列指令。
sbitE=P3^5;
sbitRW=P3^4;
sbitRS=P3^2;
sbitL=P3^1;//左半平面
sbitR=P3^0;//右半平面
sbitBusy=P2^7;////忙判断位
ucscan_key1,scan_key2;//按键功能选择,00停止,01正转10反转
ucstep1;step2;
staticstep_index;
uicount1,count2;//定时
ucbutter;//按键
staticspeed;//速度参数
uccodeJIANG[]=
{
0xFF,0xFF,0xFF,0xFB,0x00,0x01,0xFD,0xFF,0xFD,0xFF,0xFB,0xFF,0xFB,0xFF,0xF7,0xF7,0xE0,0x03,0xD7,0xF7,0xB7,0xF7,0x77,0xF7,0xF7,0xF7,0xF7,0xF7,0xF0,0x07,0xF7,0xF7
};//石
uccodeXI[]=
{
0xBF,0xFB,0xC0,0x01,0xEF,0xF7,0xFF,0xF7,0x7F,0xB7,0x98,0x17,0xDB,0xB7,0xF3,0xB7,0xEB,0xB7,0xDB,0xB7,0x18,0x37,0xDB,0xB7,0xDF,0xF7,0xDF,0xF7,0xDF,0xD7,0xDF,0xEF
};//河
uccodeLI[]=
{0xFF,0xFF,0xC0,0x0F,0xFF,0xEF,0xFF,0xDF,0xFF,0xBF,0xFE,0x7F,0xFE,0xFB,0x00,0x01,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFA,0xFF,0xFD,0xFF
};//子
ucGONG[]=
{0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFB,0x00,0x01,0xFE,0xFF,0xFD,0x7F,0xFD,0x7F,0xFD,0xBF,0xFB,0xBF,0xFB,0xDF,0xF7,0xEF,0xEF,0xF1,0x9F,0xFB,0xFF,0xFF
};
uccodeDA[]=
{0xFE,0xFF,0xFE,0xFF,0xFD,0x7F,0xFB,0xBF,0xF7,0xDF,0xEE,0xEF,0xDE,0xF1,0x3E,0xFB,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF
};
ucXUE[]=
{0xFE,0xFF,0xFE,0xFF,0xFD,0x7F,0xFB,0xBF,0xF7,0xDF,0xEE,0xEF,0xDE,0xF1,0x3E,0xFB,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF
};
uccodeZI[]=//自动化
{
0x00,0x00,0x00,0xF8,0x48,0x48,0x4C,0x4B,
0x4A,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x44,0x44,0x44,0x44,
0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,
};
uccodeDONG[]=
{
0x20,0x24,0x24,0xE4,0x24,0x24,0x24,0x20,
0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,
0x08,0x1C,0x0B,0x08,0x0C,0x05,0x4E,0x24,
0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,
};
uccodeHUA[]=
{
0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,
0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,
0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,
0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00,
};
uccodeCHANG[]=//常
{
0x20,0x18,0x08,0x09,0xEE,0xAA,0xA8,0xAF,
0xA8,0xA8,0xEC,0x0B,0x2A,0x18,0x08,0x00,
0x00,0x00,0x3E,0x02,0x02,0x02,0x02,0xFF,
0x02,0x02,0x12,0x22,0x1E,0x00,0x00,0x00,
};
uccodeYUN[]=//运
{
0x40,0x41,0xCE,0x04,0x00,0x20,0x22,0xA2,
0x62,0x22,0xA2,0x22,0x22,0x22,0x20,0x00,
0x40,0x20,0x1F,0x20,0x28,0x4C,0x4A,0x49,
0x48,0x4C,0x44,0x45,0x5E,0x4C,0x40,0x00,
};
uccodeXING[]=//行
{
0x10,0x08,0x84,0xC6,0x73,0x22,0x40,0x44,
0x44,0x44,0xC4,0x44,0x44,0x44,0x40,0x00,
0x02,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,
0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
};
uccodeZHENG[]=
{
/*正CD5FD*/
0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0x02,
0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,
0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,
0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
};
uccodeZHUAN[]=
{
/*转CD7AA*/
0xC8,0xA8,0x9C,0xEB,0x88,0x88,0x88,0x40,
0x48,0xF8,0x4F,0x48,0x48,0x48,0x40,0x00,
0x08,0x08,0x04,0xFF,0x04,0x04,0x00,0x02,
0x0B,0x12,0x22,0xD2,0x0E,0x02,0x00,0x00,
};
uccodeFAN[]=
{
/*反CB7B4*/
0x00,0x00,0xFE,0x12,0x72,0x92,0x12,0x12,
0x12,0x11,0x91,0x71,0x01,0x00,0x00,0x00,
0x40,0x30,0x4F,0x40,0x20,0x21,0x12,0x0C,
0x0C,0x12,0x11,0x20,0x60,0x20,0x00,0x00,
};
uccodeTING[]=
{
/*停CCDA3*/
0x80,0x40,0x20,0xF8,0x07,0x02,0x04,0x74,
0x54,0x55,0x56,0x54,0x74,0x04,0x04,0x00,
0x00,0x00,0x00,0xFF,0x00,0x03,0x01,0x05,
0x45,0x85,0x7D,0x05,0x05,0x05,0x03,0x00,
};
uccodeZHI[]=
{
/*止CD6B9*/
0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0xFF,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,
0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
};
uccodeJIA[]=//加
{
0x00,0x08,0x08,0x08,0xFF,0x08,0x08,0xF8,
0x00,0xF8,0x08,0x08,0x08,0xF8,0x00,0x00,
0x40,0x20,0x18,0x07,0x00,0x20,0x40,0x3F,
0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,
};
uccodeSU[]=//速
{
0x40,0x42,0xCC,0x00,0x04,0xE4,0x24,0x24,
0xFF,0x24,0x24,0x24,0xE4,0x04,0x00,0x00,
0x40,0x20,0x1F,0x20,0x48,0x49,0x45,0x43,
0x7F,0x41,0x43,0x45,0x4D,0x40,0x40,0x00,
};
uccodeJIAN[]=//减
{
0x00,0x02,0xEC,0x00,0xF8,0x28,0x28,0x28,
0x28,0x28,0xFF,0x08,0x8A,0xEC,0x48,0x00,
0x02,0x5F,0x20,0x18,0x07,0x00,0x1F,0x49,
0x5F,0x20,0x13,0x0C,0x13,0x20,0x78,0x00,
};//输出空白区域
uccodeBAI[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
uccodeDI[]=//低
{
0x40,0x20,0xF0,0x0C,0x07,0x02,0xFC,0x44,
0x44,0x42,0xFE,0x43,0x43,0x42,0x40,0x00,
0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x20,
0x10,0x28,0x43,0x0C,0x10,0x20,0x78,0x00,
};
//////////////////函数声明**************////////
//************************************************
voidiniLCD(void);
voidchkbusy(void);
voidwcode(uccd);
voidwdata(ucdat);
voiddisrow(ucpage,uccol,uc*temp);
voiddisplay(ucpage,uccol,uc*temp);
voidground(step);//转步
voidrun1();//正转
voidrun2();
voidstop();
voiddelay(uitime);
//************************************
//**************LCD初始化***************
//*********************************
voidiniLCD(void)//初始化
{L=1;R=1;
wcode(0x38);
wcode(0x0f);//开显示设置
wcode(0xc0);//设置显示启动为第一行
wcode(0x01);//清屏
wcode(0x06);//画面不动,光标右移。
}
//******************LCD判断忙的子程序**********
//**********************************************8
voidchkbusy(void)//测LCD忙状态
{
E=1;//使能LCD
RS=0;//读写指令
RW=1;//读
P2=0xff;//读操作前先进行一次空读操作,接下来才能读到数据
while(!
Busy);//等待,不忙退出
}
//*****************************************
//*****************写指令代码*****************
//***********************************************
voidwcode(uccd)//写指令代码
{
chkbusy();//写等待
P2=0xff;//使能LCD
RW=0;//读禁止
RS=0;//输出设置
P2=cd;//写数据代码
E=1;//以下两句产生下降沿
E=0;//
}
//*******************把显示数据写到内存单元中*****************
voidwdata(ucdat)//写显示数据
{
chkbusy();//写等待
P2=0xff;//使能LCD
RW=0;//读禁止
RS=1;//输出设置
P2=dat;//写数据代码
E=1;//以下两句产生下降沿
E=0;//
}
//***********************************************
//****************显示LCD程序********************
//*****************//****************************************************************
//*****************************
///****************************************************
voiddisrow(ucpage,uccol,uc*temp)
{
uci;
if(col<64)//左半平面
{
L=1;R=0;
wcode(LCDPAGE+page);//写指令页
wcode(LCDLINE+col);//写指令行
if((col+16)<64)//如果字在左半平面显示不了,转到右半平面去
{
for(i=0;i<16;i++)//写字
wdata(*(temp+i));
}
else//右半平面
{
for(i=0;i<64-col;i++)//减去左边数,从右半平面第一位开始显示
wdata(*(temp+i));//写字显示
L=0;R=1;//右半平面
wcode(LCDPAGE+page);//写指令页
wcode(LCDLINE);//写指令行
for(i=64-col;i<16;i++)//写字右半平面
wdata(*(temp+i));
}
}
else
{
L=0;R=1;
wcode(LCDPAGE+page);//写指令页
wcode(LCDLINE+col-64);//写指令行
for(i=0;i<16;i++)//写字
wdata(*(temp+i));
}
}
//*********************供调用****子程序*************
//****************************************
voiddisplay(ucpage,uccol,uc*temp)
{
disrow(page,col,temp);//显示上半字
disrow(page+1,col,temp+16);//显示下半字
}
//***********************主***控****程********序********************
voidmain(void)
{
P2=0xff;
iniLCD();//初始化LCD
display(0,0x00,&JIANG);
display(0,0x10,&XI);
display(0,0x20,&LI);
display(0,0x30,&GONG);
display(0,0x40,&DA);display(0,0x50,&XUE);
step2=0;
step1=0;
P1=0xff;
P0=0;
EX1=1;
EA=1;//开中断
speed=2010;
while
(1)
{
if((scan_key1==1)&(scan_key2==0))//正转
{
display(6,0x00,&ZHENG);//LCD显示
display(6,0x10,&ZHUAN);
ground(step_index);
delay(speed);
step_index++;//大于7,从头再来
if(step_index>7)
step_index=0;
}
if((scan_key1==0)&(scan_key2==1))//反转
{
ground(step_index);
display(6,0x00,&FAN);//LCD显示
display(6,0x10,&ZHUAN);
delay(speed);
step_index--;
if(step_index<0)//小于0,从头再来。
step_index=7;
}
if(scan_key1==0&scan_key2==0)
{
display(6,0x00,&TING);//停止
display(6,0x10,&ZHI);
display(6,0x20,&BAI);
display(6,0x30,&BAI);
P0=0xff;
}
if(step1==1&step2==0)
{
speed=speed-100;
if(speed<200|speed==200)//小于话,说明电机的速度不能再提高了。
{speed=200;display(6,0x20,&ZHENG);//正常运行
display(6,0x30,&CHANG);
display(6,0x40,&YUN);
display(6,0x50,&XING);
}
else
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 李祥 2332 直流电机 控制
![提示](https://static.bdocx.com/images/bang_tan.gif)