三片 595 联级控制双色点阵(共阴)显示
问题:绿色总是少显示一列. 有高手看看代码指出问题. (有谁做过 三片595 控制双色点阵,欢迎交流)
代码:
#include <TimerOne.h>
int latchpin = 8;
int clockpin = 12;
int datapin = 11;
int i;
int j;
int k;
void setup()
{
pinMode (latchpin,OUTPUT);
pinMode (clockpin,OUTPUT);
pinMode (datapin,OUTPUT);
}
void loop(){
//绿色全亮
digitalWrite(latchpin,LOW);
shiftit1(B00000000);
shiftit0(B11111111);
digitalWrite(latchpin,HIGH);
delay(1000);
//红色全亮
digitalWrite(latchpin,LOW);
shiftit2(B00000000);
shiftit0(B11111111);
digitalWrite(latchpin,HIGH);
delay(1000);
}
//阴极 595
void shiftit0(byte dataout){
int i=0;
boolean pinstate;
digitalWrite (datapin,LOW);
digitalWrite(clockpin,LOW);
for (i = 0;i < 8;i ++){
digitalWrite(clockpin,LOW);
if(dataout &(1 << i)){pinstate = HIGH;}else{pinstate = LOW;}
digitalWrite(datapin,pinstate);
digitalWrite(clockpin,HIGH);
digitalWrite(datapin,LOW);
}
digitalWrite(clockpin,LOW);
}
//绿色 595
void shiftit1(byte dataout){
int j=0;
boolean pinstate;
digitalWrite (datapin,LOW);
digitalWrite(clockpin,LOW);
for (j = 8;j < 16;j ++){
digitalWrite(clockpin,LOW);
if(dataout &(1 << j)){pinstate = HIGH;}else{pinstate = LOW;}
digitalWrite(datapin,pinstate);
digitalWrite(clockpin,HIGH);
digitalWrite(datapin,LOW);
}
digitalWrite(clockpin,LOW);
}
//红色 595
void shiftit2(byte dataout){
k=0;
boolean pinstate;
digitalWrite (datapin,LOW);
digitalWrite(clockpin,LOW);
for (k = 16;k < 32;k ++){
digitalWrite(clockpin,LOW);
if(dataout &(1 << k)){pinstate = HIGH;}else{pinstate = LOW;}
digitalWrite(datapin,pinstate);
digitalWrite(clockpin,HIGH);
digitalWrite(datapin,LOW);
}
digitalWrite(clockpin,LOW);
}
|