Ich verzweifel schon das ganze Wochenende über an einer Schaltung mit zugehörigem Sketch. Ich hatte das ganze schon mal auf dem Steckbrett zusammengesteckt und es jetzt auf einer Platine zusammengelötet. Ich weiß nicht mehr ob ich noch Änderungen am Sketch unternommen habe, seid dem ich es zusammengesteckt hatte, aber wenn, dann eigentlich nicht an dem Bereich der nicht funktioniert.
Ich habe dich Schaltung schon etliche male überprüft. Das zusammengelötete entspricht dem was ich in Fritzing habe. Ich habe es auch schon wieder auf dem Steckbrett zusammengesteckt und das gleiche Problem.
Das ganze soll eine selbst gebaute LED Matrix steuern. Das funktionierte auch schon sehr gut. Jetzt bekomme ich das Problem, das die erste Zeile auf alle Zeilen darunter gespiegelt wird.
Also ich die erste Zeile nun auf allen 8 Zeilen sehe.
Ja ich weiß, es ist eine etwas umfangreichere Frage, aber ich weiß echt nicht mehr weiter. Eigentlich sollte es so ohne Probleme klappen. Es hatte mal geklappt, und ich kann mich nicht daran erinnern, das ich die Steuerung für die Zeilen verändert hätte.
Fritzing für das Board mit dem Atmega und der Zeilencontroller:
Board für die Spalten lasse ich mal raus, denn dort ist alles in Ordnung. Daran wird es nicht liegen.
Code für den Atmega:
// Pins
const short topRightData = 9; // PORTB |= B00000010;
const short topLeftData = 6; // PORTD |= B01000000;
const short bottomRightData = 7; // PORTD |= B10000000;
const short bottomLeftData = 8; // PORTB |= B00000001;
const short rowData = 3; // PORTD |= B00001000;
const short rowClock = 10; // PORTB |= B00000100;
const short clock = 2; // PORTD |= B00000100;
const short latch = 4; // PORTD |= B00010000;
const short enable = 5; // PORTD |= B00100000;
const short masterReset = 11; // PORTB |= B00001000;
const short displayOnIndicator = 13;
// Pin Bytes
const byte topRightDataByte = B00000010;
const byte topLeftDataByte = B01000000;
const byte bottomRightDataByte = B10000000;
const byte bottomLeftDataByte = B00000001;
const byte rowDataByte = B00001000;
const byte rowClockByte = B00000100;
const byte clockByte = B00000100;
const byte latchByte = B00010000;
const byte enableByte = B00100000;
const byte masterResetByte = B00001000;
// Serial triggers
const char sendClearDisplay = 'c';
const char sendR = 'r';
const char printR = 'R';
const char sendG = 'g';
const char printG = 'G';
const char sendB = 'b';
const char printB = 'B';
const char sendFinish = 'f';
const char sendSwitchOn = 'O';
const char sendSwitchOff = 'F';
const char testOutput = 'T';
// Variables
boolean recieveR = false;
boolean recieveG = false;
boolean recieveB = false;
boolean displayOn = false;
short inRow = 0;
short inCol = 0;
// Matrixdata
boolean r[16][16] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
boolean g[16][16]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 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
void setup() {
pinMode(topRightData, OUTPUT);
pinMode(topLeftData, OUTPUT);
pinMode(bottomRightData, OUTPUT);
pinMode(bottomLeftData, OUTPUT);
pinMode(rowData, OUTPUT);
pinMode(rowClock, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(enable, OUTPUT);
pinMode(masterReset, OUTPUT);
digitalWrite(topRightData, LOW);
digitalWrite(topLeftData, LOW);
digitalWrite(bottomRightData, LOW);
digitalWrite(bottomLeftData, LOW);
digitalWrite(rowData, LOW);
digitalWrite(rowClock, LOW);
digitalWrite(clock, LOW);
digitalWrite(latch, LOW);
digitalWrite(enable, LOW);
digitalWrite(masterReset, HIGH);
pinMode(displayOnIndicator, OUTPUT);
digitalWrite(displayOnIndicator, LOW);
Serial.begin(9600);
}
void loop() {
if (displayOn) {
cli();
while(true) {
for(int row = 0; row < 8; row++) {
PORTB &= ~masterResetByte; // masterReset
PORTB |= masterResetByte; // masterReset
writeRow(row, r);
writeRow(row, g);
writeRow(row, b);
writeRowSopt(row);
PORTD |= latchByte; // latch
PORTD &= ~latchByte; // latch
}
if (UCSR0A & _BV(RXC0)) { // check uart (register name changes per port)
break; // looks like there is data. Break out of loop to handle it
}
}
sei();
}
}
void writeRowSopt(int row) {
for(int col = 0; col < 8; col++){
if(row == col) {
PORTD |= rowDataByte; // rowData
} else {
PORTD &= ~rowDataByte; // rowData
}
PORTB |= rowClockByte; // rowClock
PORTB &= ~rowClockByte; // rowClock
}
}
void writeRow(int row, boolean ar[][16]) {
for(int col = 0; col < 8; col++){
if(ar[row][col]) {
PORTD |= topLeftDataByte; // topLeftData
} else {
PORTD &= ~topLeftDataByte; // topLeftData
}
if(ar[row][col+8]) {
PORTB |= topRightDataByte; // topRightData
} else {
PORTB &= ~topRightDataByte; // topRightData
}
if(ar[row+8][col]) {
PORTB |= bottomLeftDataByte; // bottomLeftData
} else {
PORTB &= ~bottomLeftDataByte; // bottomLeftData
}
if(ar[row+8][col+8]) {
PORTD |= bottomRightDataByte; // bottomRightData
} else {
PORTD &= ~bottomRightDataByte; // bottomRightData
}
PORTD |= clockByte; // clock
PORTD &= ~clockByte; // clock
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
int inByte = Serial.read();
if (recieveR) {
processRecieveR(inByte);
continue;
}
if (recieveG) {
processRecieveG(inByte);
continue;
}
if (recieveB) {
processRecieveB(inByte);
continue;
}
switch (inByte) {
case sendClearDisplay:
clearDisplays();
break;
case sendR:
recieveR = true;
inRow = 0;
inCol = 0;
break;
case sendG:
recieveG = true;
inRow = 0;
inCol = 0;
break;
case sendB:
recieveB = true;
inRow = 0;
inCol = 0;
break;
case printR:
printAr(r);
break;
case printG:
printAr(g);
break;
case printB:
printAr(b);
break;
case sendSwitchOn:
digitalWrite(displayOnIndicator, HIGH);
digitalWrite(enable, LOW);
displayOn = true;
break;
case sendSwitchOff:
digitalWrite(displayOnIndicator, LOW);
digitalWrite(enable, HIGH);
displayOn = false;
disableSinks();
break;
case testOutput:
runTestOutput();
break;
}
}
}
void runTestOutput() {
String redOut = "";
String rowOut = "";
for(int row = 0; row < 8; row++) {
redOut = "";
rowOut = "";
for(int col = 0; col < 8; col++){
if(row == col) {
rowOut += "1";
} else {
rowOut += "0";
}
if(r[row][col]) {
redOut += "1";
} else {
redOut += "0";
}
}
Serial.println("Row: " + String(row));
Serial.println("Red Register: " + redOut);
Serial.println("Row Register: " + rowOut);
}
cli();
writeRow(0, r);
writeRow(0, g);
writeRow(0, b);
writeRowSopt(0);
PORTD |= latchByte; // latch
PORTD &= ~latchByte; // latch
sei();
digitalWrite(enable, LOW);
}
void printAr(boolean ar[][16]) {
for(int row = 0; row < 16; row++){
for(int col = 0; col < 16; col++){
if (ar[row][col]) {
Serial.print("1");
} else {
Serial.print("0");
}
}
Serial.println("");
}
}
void disableSinks() {
for(int row = 0; row < 8; row++){
digitalWrite(rowData, LOW);
digitalWrite(rowClock, HIGH);
digitalWrite(rowClock, LOW);
}
digitalWrite(latch, HIGH);
digitalWrite(latch, LOW);
}
void processRecieveR(int inByte) {
if (inByte == sendFinish) {
recieveR = false;
//Serial.print("Recieved R.");
Serial.println("Y");
return;
}
if (inCol < 0 || inCol > 16 || inRow < 0 || inRow > 16) {
recieveR = false;
return;
}
if ((inByte == 0) || (inByte == '0')) {
r[inRow][inCol] = 0;
} else {
r[inRow][inCol] = 1;
}
inCol++;
if (inCol >= 16) {
inCol = 0;
inRow++;
}
}
void processRecieveG(int inByte) {
if (inByte == sendFinish) {
recieveG = false;
//Serial.print("Recieved R.");
Serial.println("Y");
return;
}
if (inCol < 0 || inCol > 16 || inRow < 0 || inRow > 16) {
recieveG = false;
return;
}
if ((inByte == 0) || (inByte == '0')) {
g[inRow][inCol] = 0;
} else {
g[inRow][inCol] = 1;
}
inCol++;
if (inCol >= 16) {
inCol = 0;
inRow++;
}
}
void processRecieveB(int inByte) {
if (inByte == sendFinish) {
recieveB = false;
//Serial.print("Recieved B.");
Serial.println("Y");
return;
}
if (inCol < 0 || inCol > 16 || inRow < 0 || inRow > 16) {
recieveB = false;
return;
}
if ((inByte == 0) || (inByte == '0')) {
b[inRow][inCol] = 0;
} else {
b[inRow][inCol] = 1;
}
inCol++;
if (inCol >= 16) {
inCol = 0;
inRow++;
}
}
void clearDisplays() {
for(int row = 0; row < 8; row++){
for(int col = 0; col < 8; col++){
r[row][col] = 0;
r[row][col+8] = 0;
r[row+8][col] = 0;
r[row+8][col+8] = 0;
g[row][col] = 0;
g[row][col+8] = 0;
g[row+8][col] = 0;
g[row+8][col+8] = 0;
b[row][col] = 0;
b[row][col+8] = 0;
b[row+8][col] = 0;
b[row+8][col+8] = 0;
}
}
//Serial.print("Display cleared.");
Serial.println("Y");
}
Alles anzeigen