完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
#include "8051.h"
typedef unsigned char u8; typedef unsigned int u16; u8 smgduan[]= { /*0 1 2 3 4 5 6 7 */ 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, /*8 9 A B C D E F */ 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // P0口为数码管的位选的8位输入引脚 // P0 = 0x00; void Delayms(u16 ms); void shumaguan(u8 n); void DigDisplay(); void main() { while (1) { /* * 不推荐此做法 * 此做法占用内存高 */ if (!K1) { // 软件延时消除抖动 Delayms(10); if (!K1) { LED_1 = !LED_1; } // 确认按键已经按下 while(!K1); } if (!K2) { // 软件延时消除抖动 Delayms(10); if (!K2) { LED_2 = !LED_2; } while(!K2); } if (!K3) { // 软件延时消除抖动 Delayms(10); if (!K3) { LED_3 = !LED_3; } while(!K3); } if (!K4) { // 软件延时消除抖动 Delayms(10); if (!K4) { LED_4 = !LED_4; } while(!K4); } } } void Delayms(u16 ms) { unsigned int i, j; for(i = ms; i > 0; i--) for(j = 110; j > 0; j--); return; } void shumaguan(u8 n) { switch(n) { case 0: LSA = 0;LSB = 0;LSC = 0;break; case 1: LSA = 1;LSB = 0;LSC = 0;break; case 2: LSA = 0;LSB = 1;LSC = 0;break; case 3: LSA = 1;LSB = 1;LSC = 0;break; case 4: LSA = 0;LSB = 0;LSC = 1;break; case 5: LSA = 1;LSB = 0;LSC = 1;break; case 6: LSA = 0;LSB = 1;LSC = 1;break; case 7: LSA = 1;LSB = 1;LSC = 1;break; } } void DigDisplay() { u8 i1 = 0; u8 i2 = 0; u8 i3 = 0; u8 i4 = 0; u8 i5 = 0; u8 i6 = 0; u8 i7 = 0; u8 i8 = 0; for (i8 = 0; i8 < 10; i8++) for (i7 = 0; i7 < 10; i7++) for (i6 = 0; i6 < 10; i7++) for (i5 = 0; i5 < 10; i5++) for (i4 = 0; i4 < 10; i4++) for (i3 = 0; i3 < 10; i3++) for (i2 = 0; i2 < 10; i2++) for (i1 = 0; i1 < 10; i1++) { u16 cnt = 10; while (cnt--) { shumaguan(0); //选中第一个数码管 P0 = smgduan[i1]; //给他送一个数字 Delayms(1); //稍微延时一下下 shumaguan(1); //然后切换到第二个数码管。。。如此进行一直到最后一个数码管。。。最后再改变送入数码管的数值。。。再来一遍 P0 = smgduan[i2]; Delayms(1); shumaguan(2); P0 = smgduan[i3]; Delayms(1); shumaguan(3); P0 = smgduan[i4]; Delayms(1); shumaguan(4); P0 = smgduan[i5]; Delayms(1); shumaguan(5); P0 = smgduan[i6]; Delayms(1); shumaguan(6); P0 = smgduan[i7]; Delayms(1); shumaguan(7); P0 = smgduan[i8]; Delayms(1); P0 = 0x00; } } } |
|
|
|
只有小组成员才能发言,加入小组>>
2597 浏览 0 评论
794浏览 1评论
241浏览 1评论
559浏览 0评论
305浏览 0评论
517浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-24 17:55 , Processed in 1.304748 second(s), Total 79, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号