仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include "reg52.h"
- sbit HC138_A = P2^5;
- sbit HC138_B = P2^6;
- sbit HC138_C = P2^7;
- void Delay(unsigned int time)
- {
- while(time--);
- while(time--);
- }
- /*=======================================================
- *通过HC138译码器控制HC573锁存器
- *参数:n--HC138译码器低电平引脚
- 4:Y4输出低电平
- 5:Y5输出低电平
- 6:Y6输出低电平
- 7:Y7输出低电平
- 8:Y4~Y7全部输出高电平
- *·返回值:无。
- =======================================================*/
- void LEDRunning()
- {
- char i = 0;
- HC138_A = 0;
- HC138_B = 0;
- HC138_C = 1;
- P0 = 0x55;
- Delay(10000);
- Delay(10000);
- P0 = 0xaa;
- Delay(10000);
- Delay(10000);
- for(i = 0; i < 3; i++)
- {
- P0 = 0xff;
- Delay(10000);
- P0 = 0x00;
- Delay(10000);
- }
- P0 = 0x01;
- Delay(10000);
- for(i = 0; i < 8; i++)
- {
- P0 <<= 1;
- P0 |= 1;
- Delay(10000);
- }
- P0 = 0xff;
- for(i = 0; i < 8; i++)
- {
- P0=(P0 << 1);
- Delay(10000);
- }
-
- }
- main()
- {
-
- while(1)
- {
- LEDRunning();
- }
- }
Proteus7.5仿真,代码51hei附件下载:
【蓝桥杯单片机】LED的基本控制.zip (24.3 KB, 下载次数: 7)
2021-12-13 13:36 上传
点击文件名下载附件
下载积分: 黑币 -5