51单片机+3片74HC595联级流水灯+Proteus仿真

51单片机+3片74HC595联级流水灯+Proteus仿真


  • Proteus仿真
    在这里插入图片描述

实例代码

#include <reg52.h>
#include  <intrins.h>
#define  nop
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
三个共阳数码管被三个74hc595控制的程序如下: ```c++ #include <SPI.h> // Define the pins used for the 74HC595 shift registers #define SR_CLOCK_PIN 13 #define SR_LATCH_PIN 10 #define SR_DATA_PIN 11 // Define the values for the digits 0-9 on the common-anode 7-segment display const byte DIGIT_VALUES[] = { B11111100, // 0 B01100000, // 1 B11011010, // 2 B11110010, // 3 B01100110, // 4 B10110110, // 5 B10111110, // 6 B11100000, // 7 B11111110, // 8 B11110110, // 9 }; // Define the pins used to select each digit on the 7-segment display const byte DIGIT_PINS[] = { 2, 3, 4 // Change these to the pins you are using for your display }; // Define the number of digits on the 7-segment display const byte NUM_DIGITS = sizeof(DIGIT_PINS) / sizeof(byte); // Define the current value to display on each digit byte digitValues[NUM_DIGITS] = {0}; void setup() { // Set the shift register pins as outputs pinMode(SR_CLOCK_PIN, OUTPUT); pinMode(SR_LATCH_PIN, OUTPUT); pinMode(SR_DATA_PIN, OUTPUT); // Set the digit pins as outputs for (byte i = 0; i < NUM_DIGITS; i++) { pinMode(DIGIT_PINS[i], OUTPUT); } // Set the SPI clock frequency to 4 MHz (maximum for 74HC595) SPI.setClockDivider(SPI_CLOCK_DIV16); } void loop() { for (byte i = 0; i < NUM_DIGITS; i++) { // Select the current digit digitalWrite(DIGIT_PINS[i], LOW); // Shift out the current digit value to the shift registers shiftOut(SR_DATA_PIN, SR_CLOCK_PIN, MSBFIRST, DIGIT_VALUES[digitValues[i]]); shiftOut(SR_DATA_PIN, SR_CLOCK_PIN, MSBFIRST, 0); // Latch the shift register values to the outputs digitalWrite(SR_LATCH_PIN, HIGH); digitalWrite(SR_LATCH_PIN, LOW); // Deselect the current digit digitalWrite(DIGIT_PINS[i], HIGH); } // Increment the value on the first digit every second static unsigned long lastIncrementTime = 0; if (millis() - lastIncrementTime >= 1000) { lastIncrementTime = millis(); digitValues[0]++; if (digitValues[0] > 9) { digitValues[0] = 0; } } } ``` 在这个程序中,我们使用3个74HC595移位寄存器来控制三个共阳数码管。我们使用SPI接口来与移位寄存器通信,并将每个数码管的值作为8位二进制值发送到移位寄存器。然后,我们使用一个循环来选择每个数码管,并将其值发送到移位寄存器。最后,我们使用一个计时器来每秒增加第一个数码管的值,以模拟一个实际的计数器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值