Hi all! I am learning and trying my best to find out how to efficiently scan rows on and off for a large matrix, 8 x 96 LED's.
For some reason I cannot for the life of me get any port bit manipulation working, I've tried every port to no avail. Any suggestions?
/* Beginings of LED matrix controlled by arduino mega 2560*/
#include "avr/io.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
/*******************************************************************************
************************** Global Variables ************************************
*******************************************************************************/
volatile uint8_t Row; // DO NOT MODIFY!
/*********************************************************************************
************************ Port Settings *******************************************
*********************************************************************************/
//ROW SCANNER INTERRUPT SERVICE ROUTINE
ISR(TIMER1_OVF_vect) {
cli();
TCNT1=0xFD62; // set initial value to remove time error (16bit counter register) FBEF=60?
Row++;
if (Row == 8)
Row = 0; // fixes overlap of transferByte counter
if (Row == 0)
PORTD = B10000000; // Turns on row 1
if (Row == 1)
PORTD = B01000000; // Turns on row 2
if (Row == 2)
PORTD = B00100000; // Turns on row 3
if (Row == 3)
PORTD = B00010000; // Turns on row 4
if (Row == 4)
PORTD = B00001000; // Turns on row 5
if (Row == 5)
PORTD = B00000100; // Turns on row 6
if (Row == 6)
PORTD = B00000010; // Turns on row 7
if (Row == 7)
PORTD = B00000001; // Turns on row 8
sei();
}
void setup()
{
DDRD = B11111111; // sets Arduino pins 0-7 as outputs
Row = 0; //Preparing volatiles
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0xFD62; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
int main()
{
setup();
}
void loop()
{
digitalWrite(11, LOW); //SET OUTPUT ENABLE ON
digitalWrite(10, HIGH); // set Strobe/Latch LOW
digitalWrite(8, HIGH); // set clock LOW
digitalWrite(9, HIGH); // set the data output high
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(9, LOW); // set the data output
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
}