极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18848|回复: 4

8位数码管 电路图及代码..

[复制链接]
发表于 2012-10-21 00:49:32 | 显示全部楼层 |阅读模式
在网上找到的一个例子
要8个74H595 !
还可以往后最叠加更多...


// # Editor     : Lauren from DFRobot
// # Date       : 30.12.2011

// # Update the library and sketch to compatible with IDE V1.0 and earlier


// #
// # Editor     : Lauren from DFRobot
// # Date       : 17.01.2012

// # Product name: SPI lED Module(Arduino Compatible)
// # Product SKU : DFR0090
// # Version     : 1.0


//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 3;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 9;
byte Tab[]={
  0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("reset");
  for(int i = 0;i < 10; i++){
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, Tab[i]);
    digitalWrite(latchPin, HIGH);
    delay(500);
  }
}
void loop() {
  if (Serial.available() > 0) {
    // ASCII '0' through '9' characters are
    // represented by the values 48 through 57.
    // so if the user types a number from 0 through 9 in ASCII,
    // you can subtract 48 to get the actual value:
    int bitToSet = Serial.read() - 48;
    // write to the shift register with the correct bit set high:
    digitalWrite(latchPin, LOW);
    // shift the bits out:
    shiftOut(dataPin, clockPin, MSBFIRST, Tab[bitToSet]);
    // turn on the output so the LEDs can light up:
    digitalWrite(latchPin, HIGH);
  }
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2012-10-21 00:57:43 | 显示全部楼层
手头上有一个用2个595 控制8位数码管,
由于接线不一样,
试了N个代码,
显示出来也是乱码~~!
{:soso_e127:}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-10-21 01:17:26 | 显示全部楼层
本帖最后由 pww999 于 2012-10-21 01:34 编辑

4位数码管 引脚图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-10-21 01:24:51 | 显示全部楼层
只找到AVR  M16 的代码~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 19:30 , Processed in 0.040444 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表