电工电子实验程序清单包含液晶和电机等.docx
- 文档编号:8183965
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:16
- 大小:58.91KB
电工电子实验程序清单包含液晶和电机等.docx
《电工电子实验程序清单包含液晶和电机等.docx》由会员分享,可在线阅读,更多相关《电工电子实验程序清单包含液晶和电机等.docx(16页珍藏版)》请在冰豆网上搜索。
电工电子实验程序清单包含液晶和电机等
电工电子实验
实现的功能
简略流程图
程序清单
/头文件在此
#include
#include
#include"CONFIG.H"
#include"LCM_DRIVE.H"
#include"GRAPHICS.H"
#include
#include
//主程序全局变量
ucharcounter0=1;//菜单选择计数器
//函数在此声明
voidSquare_Disp(uint8x,uint8y,char*dd);//显示16*16字模
voidChoose_Disp(ucharcounter0);//菜单选择
voidBee_start(void);//报警
ucharTLC549ADC(void);//模数转换
voidInt_initial();//外部中断初始化
voidLight_Task();//小灯交替闪亮
voidK1CHECK();//检查K1是否按下
voidK2CHECK();//检查K2是否按下
voidDelayS(uint16delayno);//延时
//字码表在此
/*--文字:
准--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab1[32]={
0x00,0x02,0x1C,0xC8,0x20,0x10,0xFF,0x4A,0x48,0x49,0xFE,0x48,0x68,0x4C,0x08,0x00,
0x02,0x02,0x7E,0x01,0x00,0x00,0x7F,0x22,0x22,0x22,0x3F,0x22,0x23,0x32,0x20,0x00};
/*--文字:
备--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab2[32]={
0x00,0x20,0x10,0x08,0x87,0x8A,0x52,0x22,0x22,0x52,0x8E,0x82,0x00,0x00,0x00,0x00,
0x02,0x02,0x01,0xFF,0x4A,0x4A,0x4A,0x7E,0x4A,0x4A,0x4A,0xFF,0x01,0x03,0x01,0x00};
/*--文字:
模--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab3[32]={
0x00,0x20,0xA0,0xFF,0x50,0x90,0xE8,0xBF,0x94,0x54,0x5C,0xF7,0x04,0x04,0x00,0x00,
0x04,0x03,0x00,0x7F,0x00,0x48,0x2B,0x1A,0x0A,0x07,0x0D,0x15,0x64,0x44,0x40,0x00};
/*--文字:
数--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab4[32]={
0x00,0x20,0xA4,0x68,0xFF,0x20,0x58,0x96,0x60,0xB8,0x27,0xE0,0x10,0x10,0x00,0x00,
0x40,0x45,0x24,0x2C,0x13,0x2E,0x42,0x40,0x20,0x19,0x06,0x19,0x60,0x40,0x40,0x00};
/*--文字:
小--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab5[32]={
0x00,0x00,0x00,0xC0,0x30,0x00,0x00,0xFE,0x00,0x10,0x20,0xC0,0x00,0x00,0x00,0x00,
0x08,0x04,0x03,0x00,0x00,0x10,0x20,0x7F,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00};
/*--文字:
灯--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab6[32]={
0x10,0x60,0x00,0xFF,0x40,0x30,0x00,0x08,0x08,0x08,0xF8,0x04,0x04,0x04,0x04,0x00,
0x40,0x20,0x18,0x07,0x02,0x04,0x08,0x00,0x10,0x20,0x7F,0x00,0x00,0x00,0x00,0x00};
/*--文字:
电--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab7[32]={
0x00,0x00,0xF0,0x10,0x90,0x90,0xFF,0x48,0x48,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0x04,0x04,0x04,0x1F,0x22,0x22,0x22,0x23,0x20,0x20,0x38,0x00,0x00};
/*--文字:
机--*/
/*--仿宋12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab8[32]={
0x00,0x20,0xA0,0xFF,0x50,0x90,0x00,0xFC,0x04,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,
0x08,0x06,0x01,0x7F,0x00,0x41,0x38,0x07,0x00,0x00,0x1F,0x20,0x20,0x20,0x3C,0x00};
/*--文字:
转--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab9[32]={
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};
/*--文字:
向--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab10[32]={
0x00,0x00,0xFC,0x04,0x04,0xE6,0x25,0x24,0x24,0x24,0xE4,0x04,0x04,0xFC,0x00,0x00,
0x00,0x00,0x7F,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x0F,0x20,0x40,0x3F,0x00,0x00};
/*--文字:
★--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab[32]={
0x40,0x40,0xC0,0xC0,0xC0,0xE0,0xFC,0xFF,0xFC,0xE0,0xC0,0xC0,0xC0,0x40,0x40,0x00,
0x00,0x00,0x40,0x39,0x3F,0x1F,0x1F,0x0F,0x1F,0x1F,0x3F,0x39,0x40,0x00,0x00,0x00};
/*--文字:
--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--*/
uint8codemytab0[32]={
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};
//16*16显示程序
voidSquare_Disp(uint8x,uint8y,char*dd)
{
uint8i=0;
for(i=0;i<16;i++)//输出上半部分
LCM_WriteByte(x++,y,*(dd++));
for(i=0;i<5;i++);//延时
x=x-16;//调整转出位置
for(i=0;i<16;i++)//输出下半部分
LCM_WriteByte(x++,y+8,*(dd++));
}
//菜单选择
voidChoose_Disp(ucharcounter0)
{
if(counter0!
=1)
{
Square_Disp(0,16*(counter0-2),mytab0);
Square_Disp(0,16*(counter0-1),mytab);
}
else
{
Square_Disp(0,48,mytab0);
Square_Disp(0,0,mytab);
}
}
//蜂鸣器
sbitBuzz=P1^7;
voidBee_start(void)
{
Buzz=0;
DelayS
(1);
Buzz=1;
DelayS
(1);
}
//TLC549,TLC549是串行8位ADC,使用的接口/CS=P1.2,DAT=P1.1,CLK=P1.0
sbitCLK=P1^0;
sbitDAT=P1^1;
sbitCS=P1^2;
ucharbdataADCdata;
sbitADbit=ADCdata^0;
//模拟量采集
ucharTLC549ADC(void)
{
uchari;
CLK=0;
DAT=1;
CS=0;
for(i=0;i<8;i++)
{
CLK=1;
_nop_();
_nop_();
ADCdata<<=1;
ADbit=DAT;
CLK=0;
_nop_();
}
return(ADCdata);
}
//开关采集(P3.2接K3控制counter++)
sbitP3_2=P3^2;
voidInt_initial()//中断初始化
{
EX0=1;//允许中断EA,EX0,EX1
IT0=1;//边沿触发
PX0=1;//中断优先级设定
PT0=0;
EA=1;//开总中断
}
voidint_0()interrupt0using0//外部中断0程序决定选择菜单
{
uchari;
EX0=0;
if(P3_2==0)
{
for(i=0xff;i>0;i--)//延时
_nop_();
if(P3_2==0)
{
if(counter0==4)
{
TR0=0;
ET0=0;
}
if(counter0<4)
counter0++;
elseif(counter0==4)
counter0=1;
}
}
while(!
P3_2);
EX0=1;
}
//小灯齐闪
voidLight_Task()
{
P0=0xAA;
DelayS(15);
P0=0x55;
DelayS(15);
}
//直流电机
sbitP1_3=P1^3;
sbitP1_4=P1^4;
sbitP1_5=P1^5;
sbitP1_6=P1^6;
sbitP3_0=P3^0;
unsignedcharPWMH;//高电平脉冲宽度
unsignedcharPWM;//PWM周期宽度
unsignedcharCOUNTER;
//直流电机
voidtime_0()interrupt1using1//定时器0中断程序,产生一个占空比为PWMH/PWM的方波
{
COUNTER++;//计数值加1
if((COUNTER!
=PWMH)&&(COUNTER==PWM))//如果等于高电平脉冲数
{
COUNTER=1;//计数器复位
P1_3=1;//P1.3为高电平
}
elseif(COUNTER==PWMH)
P1_3=0;//P1.3变为低电平
}
//K1接P1.4,K2接P1.5,P1.3接ZDJ_A,P1.6接ZDJ_B,GND连线,K1,K2改变占空比改变转速,SW1接P3.0控制转向,B10区JP18的电源路线(短路时使用此电路)
voidK1CHECK()//扫描是否按下K1
{
while(P1_4==0);
if(PWMH!
=PWM)
{
PWMH++;
if(PWMH==PWM)
{
TR0=0;
P1_3=1;
}
else
{
if(PWMH==0x02)
{
TR0=1;
}
}
}
}
voidK2CHECK()//扫描K2是否按下
{
while(P1_5==0);
if(PWMH!
=0x01)
{
PWMH--;
if(PWMH==0x01)
{
TR0=0;
P1_3=0;
}
else
{
if(PWMH==PWM)
{
TR0=1;
}
}
}
}
//定时中断初始化
voidTime0_intial(void)
{
PWMH=0x02;
COUNTER=0x01;
PWM=0x15;
TMOD=0x02;//定时器0在模式2下工作
TL0=0x38;//定时器每200us产生一次溢出
TH0=0x38;//自动重装的值
ET0=1;//使能定时器0中断
TR0=1;//开始计时
}
//长软件延时
voidDelayS(uint16delayno)
{
uint16i;
for(;delayno>0;delayno--)
{
for(i=0;i<500;i++);
}
}
//主函数
main()
{
uchari;
ucharAD_DATA;
longend_data;
uchard[3];
Int_initial();//中断初始化
LCM_DispIni();//LCD初始化
P0=0;
P1_3=0;
P1_6=0;
Square_Disp(16,0,mytab1);//显示出菜单
Square_Disp(32,0,mytab2);
Square_Disp(16,16,mytab3);
Square_Disp(32,16,mytab4);
Square_Disp(16,32,mytab5);
Square_Disp(32,32,mytab6);
Square_Disp(16,48,mytab7);
Square_Disp(32,48,mytab8);
while
(1)
{switch(counter0)//选菜单项实现相应功能
{
case1:
//选中“准备”,并显示“initial”
Choose_Disp(counter0);
LCM_DispStr(7,12,"");
LCM_DispStr(7,13,"");
Square_Disp(64,48,mytab0);
Square_Disp(80,48,mytab0);
DelayS
(2);
while(counter0==1)
LCM_DispStr(1,8,"initial");
break;
case2:
//选中“数模”,并实时采集数据,并响应相应功能
LCM_DispStr(1,8,"");
Choose_Disp(counter0);
DelayS
(2);
while(counter0==2)
{
TLC549ADC();
for(i=0xff;i>0;i--)//延时
{_nop_();}
AD_DATA=ADCdata;//将采集的数据转换为实际数值
end_data=(long)AD_DATA*2;
d[0]=(long)end_data/100;
d[2]=(long)end_data%10;
d[1]=(long)(end_data-d[0]*100)/10;
LCM_DispChar(3,8,d[0]+'0');//在屏幕显示采集的模拟量
LCM_DispChar(3,9,'.');
LCM_DispChar(3,10,d[1]+'0');
LCM_DispChar(3,11,d[2]+'0');
LCM_DispChar(3,12,'v');
if(end_data>400)//越限报警
{
LCM_DispChar(3,14,'H');
Bee_start();
}
elseif(end_data<100)
{
LCM_DispChar(3,14,'L');
Bee_start();
}
else
LCM_DispChar(3,14,'M');
}
break;
case3:
//选中“小灯”,小灯闪烁
Choose_Disp(counter0);
LCM_DispStr(3,8,"");
LCM_DispStr(5,8,"Spark!
");
DelayS(5);
while(counter0==3)
Light_Task();
break;
case4:
//选中“电机”,实现相应按键功能
Choose_Disp(counter0);
LCM_DispStr(5,8,"");
DelayS
(2);
Time0_intial();
P1_3=0;//选择电机选项时,电机启动
P1_6=1;
while(counter0==4)
{
LCM_DispStr(5,8,"");
Square_Disp(64,48,mytab9);
Square_Disp(80,48,mytab10);
if(P3_0==0)//SW1接P3.0控制转向
{
P1_3=1;//正转
LCM_DispStr(7,12,"");
LCM_DispStr(7,12,"+");
}
elseif(P3_0==1)
{
P1_3=0;//反转
LCM_DispStr(7,12,"");
LCM_DispStr(7,12,"-");
}
if(P1_4==0)
{
K1CHECK();//扫描KEY1,K1,K2控制占空比控制转速,K1加速
LCM_DispStr(7,13,"");
LCM_DispStr(7,13,"K1");
}
if(P1_5==0)
{
K2CHECK();//扫描KEY2,如果按下KEY2,跳转到KEY2处理程序,K2减速
LCM_DispStr(7,13,"");
LCM_DispStr(7,13,"K2");
}
}
P1_3=0;//选中其他菜单时停止电机
P1_6=0;
break;
}
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电工 电子 实验 程序 清单 包含 液晶 电机
![提示](https://static.bdocx.com/images/bang_tan.gif)