基于Proteus和Keil的单片机仿真实验系统设计后续源码附件.docx
- 文档编号:8223443
- 上传时间:2023-01-30
- 格式:DOCX
- 页数:20
- 大小:20KB
基于Proteus和Keil的单片机仿真实验系统设计后续源码附件.docx
《基于Proteus和Keil的单片机仿真实验系统设计后续源码附件.docx》由会员分享,可在线阅读,更多相关《基于Proteus和Keil的单片机仿真实验系统设计后续源码附件.docx(20页珍藏版)》请在冰豆网上搜索。
基于Proteus和Keil的单片机仿真实验系统设计后续源码附件
参考文献
【1】杜伟略.80C51单片机及接口技术.北京:
化学工业出版社,2008.
【2】于晓东,吴博,秦柏,狄海延.80C51单片机原理、开发与应用实例.中国电力出版社,2008
【3】张一斌,余建坤.单片机原理课程设计.长沙:
中南大学出版社,2009
【4】李朝青.单片机学习指导.北京:
北京航空航天出大学版社,2008
【5】赵巍,冯娜.单片机基础及应用.北京:
清华大学出版社,2011
【6】汪文你,陈林.单片机原理及应用.武昌:
华中科技大学出版社,2007
【8】刘同发,陈忠平,眭仁武.单片机基础与最小实践.北京:
北京航空航天大学出版社,2007
【9】楼然苗,李光飞.51系列单片机原理及设计实例.北京:
北京航空航天大学出版社,2006
【10】高锋.单片微型计算机原理与接口技术.科学出版社,2003年
【11】阎石.数字电子技术基础[M].北京:
高等教育出版社,1998.12
【12】[12]许珉.单片机原理及应用[M].北京:
中国电力出版社,2007.8
【13】曾屹.单片机原理与应用(第一版)[M].中南大学出版社,2009
【14】何立民.单片机高级教程(应用与设计).北京:
北京航空航天大学出版社,2000
【15】涂时亮,张友德.单片微机控制技术.清华大学出版社,1994
原先上传计算书设置了不能下载不会改,如果有付费的可以联系发你一份原文档
附录
主程序main.c源码:
#include
#include
#include
#include
#include
#include
#include<16.c>
ke(void)
{
charke;
P0=0x32;
addr=1;
P0=0x7a;
addr=0;
P0=led_mod[0];
while
(1)
{
ke=getkey();
if(ke!
=-1)
{
P0=led_mod[ke];
switch(key_buf[ke])
{
case0x21:
{liu();break;}
case0x41:
{key();break;}
case0x81:
{lcd();break;}
case0x12:
{ji();break;}
case0x22:
{led();break;}
case0x42:
{qiang();break;}
case0x82:
{dian();break;}
}
}
delay(10);
}
}
voidmain()
{
ke();
}
流水灯子程序文件liu.c:
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitLED=P1^0;
voiddelayms(uintx)//延时
{
uchari;
while(x--)
{
for(i=0;i<120;i++);
}
}
voidliu()
{
addr=1;//选址开始
delay(10);
P0=0x56;
delay(10);
addr=0;//选址结束
P0=0xfe;
while(K==1)
{
P0=_crol_(P0,1);//P0端口的值向左循环移动一位
delayms(150);
}
ke();
}
键盘源程序文件key.c如下:
#include
sbitaddr=P3^0;
//LED字模
Charled_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};
//键值
Charkey_buf[]={0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88};
chargetkey(void);
sbitK=P3^7;
voiddelay(unsignedinttime)
{
unsignedintj=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
voidkey(void)
{
charkey=0;
addr=1;
P0=0x00;
delay(10);
P0=0x7a;
addr=0;
delay(10);
while(K==1)
{
key=getkey();
if(key!
=-1)
{
P0=led_mod[key];
}
delay(10);
}
P0=led_mod[key];
ke();
}
//检测按键
//返回-1表示没有检测到按键按下
chargetkey(void)
{
chark1=0,k2=0,i=0;
P2=0xf0;
delay(10);
if(P2!
=0xf0)
{
k1=P2;
if(P2==k1)
{
P2=0x0f;
delay(10);
k2=P2&k1;
for(i=0;i<16;i++)
{
if(key_buf[i]==k2)
{
returni;
}
}
}
}
return-1;
}
中断计数子程序文件ji.c代码:
#include
typedefunsignedcharuint8;
typedefunsignedintuint16;
sbitK2=P3^5;
voiddelay1(uint16x)
{
uint16i,j;
for(i=x;i>0;i--)
for(j=200;j>0;j--);
}
Codeuint8LED_CODE[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};
uint8Buffer_Counts[]={0,0,0};
uint16Count=0;
voidShow_Counts()
{
uint8i;
Buffer_Counts[2]=Count/100;
Buffer_Counts[1]=Count%100/10;
Buffer_Counts[0]=Count%10;
if(Buffer_Counts[2]==0)
{
Buffer_Counts[2]=10;
if(Buffer_Counts[1]==0)
Buffer_Counts[1]=10;
}
for(i=0;i<3;i++)
{
P0=0xFF;
P1=0x80>>i;
P0=LED_CODE[Buffer_Counts[i]];
delay1(5);
}
}
voidji()
{
addr=1;
P0=0x42;
addr=0;
delay
(1);
IP=0x01;
IT0=1;
IE=0x81;
while(K==1)
{
if(K2==0)Count=0;
Show_Counts();
}
ke();
}
voidISR0()interrupt0
{
Count++;
}
液晶显示的文件lcd.c代码:
#include
#include
sbitRS=P1^0;//寄存器选择位,将RS位定义为P1.0引脚
sbitRW=P1^1;//读写选择位,将RW位定义为P1.1引脚
sbitE=P1^2;//使能信号位,将E位定义为P1.2引脚
sbitBF=P0^7;//忙碌标志位,,将BF位定义为P0.7引脚
voiddelay1ms()
{
unsignedchari,j;
for(i=0;i<10;i++)
for(j=0;j<33;j++)
}
voiddelay11(unsignedcharn)
{
unsignedchari;
for(i=0;i delay1ms(); } unsignedcharBusyTest(void) { bitresult; RS=0;//根据规定,RS为低电平,RW为高电平时,可以读状态 RW=1; E=1;//E=1,才允许读写 _nop_();//空操作 _nop_(); _nop_(); _nop_();//空操作四个机器周期,给硬件反应时间 result=BF;//将忙碌标志电平赋给result E=0; returnresult; } voidWriteInstruction(unsignedchardictate) { while(BusyTest()==1);//如果忙就等待 RS=0;//根据规定,RS和R/W同时为低电平时,可以写入指令 RW=0; E=0;//就是让E从0到1发生正跳变,所以应先置"0" _nop_(); _nop_();//空操作两个机器周期,给硬件反应时间 P0=dictate;//将数据送入P0口,即写入指令或地址 _nop_(); _nop_(); _nop_(); _nop_();//空操作四个机器周期,给硬件反应时间 E=1;//E置高电平 _nop_(); _nop_(); _nop_(); _nop_();//空操作四个机器周期,给硬件反应时间 E=0;//当E由高电平跳变成低电平时,液晶模块开始执行命令 } voidWriteAddress(unsignedcharx) { WriteInstruction(x|0x80);//显示位置的确定方法规定为"80H+地址码x" } 函数功能: 将数据(字符的标准ASCII码)写入液晶模块入口参数: y(为字符常量) voidWriteData(unsignedchary) { while(BusyTest()==1); RS=1;//RS为高电平,RW为低电平时,可以写入数据 RW=0; E=0;//E置低电平(根据表8-6,写指令时,E为高脉冲,就是让E从0到1发生正跳变,所以应先置"0" P0=y;//将数据送入P0口,即将数据写入液晶模块 _nop_(); _nop_(); _nop_(); _nop_();//空操作四个机器周期,给硬件反应时间 E=1;//E置高电平 _nop_(); _nop_(); _nop_(); _nop_();//空操作四个机器周期,给硬件反应时间 E=0;//当E由高电平跳变成低电平时,液晶模块开始执行命令 } 函数功能: 对LCD的显示模式进行初始化设置 voidLcdInitiate(void) { delay11(1500);//延时15ms,首次写指令时应给LCD一段较长的反应时间 WriteInstruction(0x38);//显示模式设置: 16×2显示,5×7点阵,8位数据接口 delay11(500);//延时5ms WriteInstruction(0x38); delay11(500); WriteInstruction(0x38); delay11(500); WriteInstruction(0x0f);//显示模式设置: 显示开,有光标,光标闪烁 delay11(500); WriteInstruction(0x06);//显示模式设置: 光标右移,字符不移 delay11(500); WriteInstruction(0x01);//清屏幕指令,将以前的显示内容清除 delay11(500); } 这个函数是用来在指定位置开始输入多个字符的 voidshow(intx,inty,char*str) { registeri=0; if(str[i]! =0) { if(y==0) { for(i=0;i<=16;i++) { WriteAddress(0x00+x); WriteData(str[i]); x++; delay11(100); } x=0x00; for(i=16;i<=32;i++) { WriteAddress(0x40+x); WriteData(str[i]); x++; delay11(100); } } if(y==1) { for(i=0;i<=16;i++) { WriteAddress(0x40+x); WriteData(str[i]); x++; delay11(100); } } } } voidLCD(void)//主函数 { while(K==1) { addr=1; P0=0x50; delay (1); addr=0; P0=0x00; P1=0x00; LcdInitiate();//调用LCD初始化函数 delay11(100); show(0x00,0,"abcdefghijklmnopqrstuvwxyz123456"); delay11(100); LcdInitiate(); delay11(100); show(0x00,0,"ABCDEFGHIJKLMNOPQRSTUVWXYZ! "); LcdInitiate(); } delay11(100); show(0x00,0,"upthereturnbutton"); LcdInitiate(); ke(); } 16x16点阵子程序文件为16.c代码: #include #include #defineucharunsignedchar #defineuintunsignedint sbitds=P1^1;//数据打入口C1 sbitshcp=P1^0;//移位数据脉冲C0 sbitstcp=P1^3;//数据打出脉冲C3 uchartemp,j=0,i,k=0; voidhang(); voiddelay500ms(void); voiddelay16(intx) { intl; for(l=0;l { delay500ms(); } } unsignedcodesw[16]={0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67}; unsignedcodehangzi[]={/*阴码逐行顺向取反16x16*/ 0x00,0x00,0x00,0x0C,0xFF,0xF8,0x30,0x18,0x30,0x03,0x37,0xC6,0x36,0xC6,0x36,0xD8,0x36,0xD8,0x36,0xCC,0x37,0xCF,0x36,0xCC,0x30,0x0C,0x30,0x0C,0x3C,0x0C,0x18,0x00,//*"河",0 0x06,0x60,0x06,0x60,0x06,0x60,0x66,0x60,0x36,0x60,0x1E,0x7E,0x0E,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0xC6,0x60,0xC6,0x78,0xC6,0x6F,0xFC,0x66,0x00,0x60,//*"北",1 0x06,0x00,0x06,0x00,0x3F,0xFF,0x36,0x30,0xFF,0xF8,0x36,0x18,0x3F,0xCC,0x06,0x3E,0x3F,0xF0,0x06,0x30,0x06,0x36,0x7F,0xFC,0x06,0x18,0x06,0x7C,0xFF,0xC6,0x00,0x03,//*"建",2 0x06,0x18,0x06,0x18,0xFF,0xFC,0x1B,0x36,0x31,0xE3,0x00,0x00,0x1F,0xFE,0x19,0x98,0x19,0x98,0x1B,0x98,0x1F,0x98,0xD9,0xF8,0xD8,0xCF,0xD8,0xC6,0xF0,0x60,0x00,0x30,//*"筑",3 0x00,0x00,0x00,0x00,0x7F,0xFE,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0xFF,0xFF,0x00,0x00,0x00,0x00,//*"工",4 0x00,0x30,0x7F,0xF8,0x61,0x9F,0x61,0x98,0x61,0x98,0x7F,0xFF,0x00,0x18,0x00,0x1C,0xFF,0xBC,0x0C,0x7E,0x0C,0x7E,0x7F,0x9B,0x0C,0x18,0x0C,0x18,0xFF,0xD8,0x00,0x18,//*"程",5* 0x30,0xCC,0x31,0x98,0x19,0x98,0x0C,0x00,0xFF,0xFE,0xC0,0x06,0x60,0x03,0x0F,0xF8,0x06,0x00,0x03,0x80,0xFF,0xFF,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0xE0,0x00,0xC0,//*"学",6* 0x06,0x00,0x0C,0x3E,0xFF,0xF6,0xC0,0xDE,0x60,0x7E,0x3F,0x8E,0x00,0x1E,0x00,0x36,0xFF,0xF6,0x1B,0x36,0x1B,0x3E,0x1B,0x1E,0xD9,0x86,0xD9,0x86,0xF0,0xC6,0x00,0x66,//*"院",7 /*0x00,0x18,0x1F,0x98,0x19,0x98,0x19,0x98,0x19,0xFF,0x19,0x98,0x19,0x9C,0x19,0xBC,0x19,0xFE,0x19,0xFE,0x19,0x9B,0xD9,0x98,0xD9,0x98,0xD8,0xD8,0xF0,0xD8,0x00,0x78,//*"机",8* 0x18,0x18,0x78,0x18,0xD8,0x18,0x18,0x18,0xFF,0xFF,0x18,0x18,0x1F,0x9C,0x7F,0xBC,0x7F,0xFE,0x7F,0x9E,0x7F,0x9B,0x37,0x98,0xF6,0xD8,0xFE,0xD8,0xEC,0x78,0xC6,0x18,//*"械",9* 0x01,0x80,0x01,0x80,0x01,0x80,0x3F,0xFC,0x31,0x8C,0x31,0x8C,0x31,0x8C,0x3F,0xFC,0x31,0x8C,0x31,0x8C,0x31,0x8C,0x3F,0xFC,0xF1,0x8C,0xC1,0x80,0xC1,0x80,0xFF,0x00,//*"电",10* 0x00,0x00,0x3F,0xFE,0x18,0x00,0x0C,0x00,0x06,0x00,0x03,0x80,0x01,0x80,0xFF,0xFF,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0xE0,0x00,0xC0,//*"子",11* 0x00,0x00,0x00,0x00,0x7F,0xFE,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0xFF,0xFF,0x00,0x00,0x00,0x00,//*"工",12* 0x00,0x30,0x7F,0xF8,0x61,0x9F,0x61,0x98,0x61,0x98,0x7F,0xFF,0x00,0x18,0x00,0x1C,0xFF,0xBC,0x0C,0x7E,0x0C,0x7E,0x7F,0x9B,0x0C,0x18,0x0C,0x18,0xFF,0xD8,0x00,0x18,//*"程",13* 0x01,0x80,0x01,0x80,0x01,0x80,0x3F,0xFC,0x00,0xC0,0x00,0xC0,0xFF,0xFF,0x00,0x60,0x00,0x30,0x1F,0xF0,0x18,0x00,0x0C,0x00,0x06,0xE0,0x03,0x80,0x06,0x00,0x0C,0x00,//*"专",14* 0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x66,0x66,0x66,0x6C,0x36,0x6C,0x36,0x78,0x1E,0x78,0x0E,0x78,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0xFF,0xFF,0x00,0x00,//*"业",15* 0x03,0x0C,0x33,0x0C,0x1F,0x0C,0x07,0xFC,0x03,0x0C,0x63,0x0C,0x63,0xEC,0x7E,0x3C,0x01,0x8C,0x01,0x80,0xFF,0xFF,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,//*"毕",16* 0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x66,0x66,0x66,0x6C,0x36,0x6C,0x36,0x78,0x1E,0x78,0x0E,0x78,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0xFF,0x
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 Proteus Keil 单片机 仿真 实验 系统 设计 后续 源码 附件
![提示](https://static.bdocx.com/images/bang_tan.gif)