单片机项目实践教程刘燎原-项目三手动计数器

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

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

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

资源描述

微控制器系统设计与应用刘燎原江苏建筑职业技术学院实验1.KEIL使用步骤2.单片机开发板使用方法,烧录程序步骤3.K1按下,8个流水灯从上到下逐个点亮,若K1断开,8个流水灯从下到上逐个点亮,然后依次循环#includereg51.H//包含AT89X52.H头文件sbitk1=P3^4;unsignedcharcodesz1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};voidDelay(unsignedintt){unsignedinti,j;for(i=0;it;i++){for(j=0;j120;j++);}}voidmain(){unsignedcharm;while(1){if(k1==0){for(m=0;m8;m++){P1=sz1[m];Delay(200);}}else{for(m=0;m8;m++){P1=sz1[7-m];Delay(200);}}}}循环完8次后再响应按键#includeAT89X52.H//包含AT89X52.H头文件#includeintrins.Hsbitk1=P3^4;voidDelay(unsignedintt){unsignedinti,j;for(i=0;it;i++){for(j=0;j120;j++);}}voidmain(void){P1=0xfe;while(1){if(k1==0){P1=_crol_(P1,1);Delay(200);}else{P1=_cror_(P1,1);Delay(200);}}}随时响应按键手动计数器按键控制数码管显示控制手动计数器PROTEUS仿真PROTEUS仿真项目三手动计数器--------单片机控制数码管静态显示知识目标:1.掌握数码管的动态、静态显示不同、电路连接2.掌握查表指令3.掌握按键的编程4.掌握单片机的外部中断技能目标:1.掌握PROTEUS中数码管的共阴、共阳的不同2.掌握数码管和单片机的连接方法1.LED数码管简介(1)结构、工作原理由LED发光二极管组合显示字符的显示器件。它使用了8个LED发光二极管,其中7个用于显示字符,1个用于显示小数点,故通常称之为7段(也有称作8段)发光二极管数码显示器。abcdefgdpabcdefgdp“8”字型LED数码管结构及原理abcdefgdp共阴极+5V共阳极D7D6D5D4D3D2D1D0abcdefgdpD7D6D5D4D3D2D1D0abcdefgdp字型码的定义共阴极共阳极110110105BH00100101COMCOM(2)LED的编码方式表十六进制数及空白字符与P的显示段码(3)LED数码管的显示方式a.静态LED显示器电路数码管的COM端接不变的高/低电平,每位数码管的a~g和h端与一个8位的I/O相连。要在某一位数码管上显示字符时,只要从对应的I/O口输出其显示代码即可特点为:数码管恒定地亮,显示某个数值,直到显示字符改变为止适用场合:由于太占据I/O线,所以用于1个或较少数码管显示的场合。b.动态LED显示器电路每个数码管的COM端和不同的I/O口相连,每位数码管的a~g和h端接在一起,与一个8位的I/O相连。要在某一位数码管上显示字符时,首先和该数码管COM端相连的I/O口有效,然后从对应的I/O口输出其显示代码即可特点为:数码管轮流点亮适用场合:由于可以节省I/O线,所以用于多个数码管显示的场合。2.应用例1:设计电路,程序,使1位数码管(共阳)依次显示0~F,每个数字的显示时间是1s.电路:XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC130pC230pR910kC31uFR2300R3300R4300R5300R6300R7300程序清单:#includeREG51.hunsignedcharcodesz1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};voiddelay(unsignedinta){unsignedchari;while(a--){for(i=0;i120;i++);}}voidmain(){unsignedcharj;while(1){for(j=0;j16;j++){P2=sz1[j];delay(1000);}}}看仿真效果XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC130pC230pR910kC31uFR2300R3300R4300R5300R6300R7300例2:用开关控制LED显示设计电路程序,用8个开关作为输入,8个发光二极管作为输出,显示8位开关的二进制数。XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C5112345678161514131211109D1LED-GREEND2LED-GREEND3LED-GREEND4LED-GREEND5LED-GREEND6LED-GREEND7LED-GREENX1CRYSTALC130pC230pR910kC31uFD8LED-GREEN#includereg51.hvoiddelay(unsignedinta){unsignedchari;while(a--){for(i=0;i120;i++);}}voidmain(){unsignedcharm;while(1){m=P2;P1=m;delay(1000);}}XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C5112345678161514131211109D1LED-GREEND2LED-GREEND3LED-GREEND4LED-GREEND5LED-GREEND6LED-GREEND7LED-GREENX1CRYSTALC130pC230pR910kC31uFD8LED-GREEN例3:用开关控制数码管显示设计电路和程序,用开关作为输入元件,用数码管显示4位开关的二进制数。(例如4个开关都闭合,则4个开关状态0000,则数码管显示0。以此类推)XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC130pC230pR910kC31uFR2300R3300R4300R5300R6300R7300程序清单:#includeREG51.hunsignedcharcodesz1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};voiddelay(unsignedinta){unsignedchari;while(a--){for(i=0;i120;i++);}}voidmain(){unsignedcharm;P1=0xff;while(1){m=P1;m=m&0x0f;P2=sz1[m];delay(1000);}}XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC130pC230pR910kC31uFR2300R3300R4300R5300R6300R7300例4:设计计数器(0~99),两位数码管显示静态显示XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.

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

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

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

×
保存成功