(Solved)Again problem with matrix, this time 8x32

Status
Not open for further replies.
Thanks doggy, all leds are lit now with this current code:
C:
#include "FontMap.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR0) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR0 = 0; // Clear timer 2 interrupt flag


}

void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}

void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}

void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}

void pixel(signed char x,signed char y,int cond)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data


if(cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if(cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

void charput(unsigned char ch, signed char x,signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if(disp2 > 0)
{
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
}

}
}

void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}

void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions


// Set the Timer Mode to CTC
TCCR0A |= (1 << WGM01);

// Set the value that you want to count to
OCR0A = 0xF9;

// start the timer
TCCR0B |= (1 << CS01) | (1 << CS00);
// set prescaler to 64 and start the timer

while ( (TIFR0 & (1 << TOV0) ) > 0) // wait for the overflow event
{
}

TIFR0 &= ~(1 << TOV0);
// reset the overflow flag
interrupts(); // enable all interrupts
} // End main

void loop() //just sitting here
{
clr();
pixel(0,0,0);
pixel(31,8,0);
strput("WOOF",1,0);
Blit();
delay(500);
}
 
Last edited:
try


void loop() //just sitting here
{
clr();
pixel(0,0,0);
pixel(31,8,0);
charput( 1,1,0);//(unsigned char ch, signed char x,signed char y)
charput( 2,7,0);
strput("OF",15,0);
Blit();
delay(500);
}
 
Yes, every single led is lit, not even flicker seen, tested with that new loop() you gave.
 
oh, copied wrong code, also change this line:
ISR (TIMER0_COMPA_vect)



void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions


// Set the Timer Mode to CTC
TCCR0A |= (1 << WGM01);

// Set the value that you want to count to
OCR0A = 0xF9;

TIMSK0 |= (1 << OCIE0A); //Set the ISR COMPA vect

sei(); //enable interrupts


TCCR0B |= (1 << CS02);
// set prescaler to 256 and start the timer



TIFR0 &= ~(1 << TOV0);
// reset the overflow flag
interrupts(); // enable all interrupts
} // End main
 
hmm, still same result, all leds lit:
C:
#include "FontMap.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR (TIMER0_COMPA_vect){
if(TIFR0) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR0 = 0; // Clear timer 2 interrupt flag


}

void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}

void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}

void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}

void pixel(signed char x,signed char y,int cond)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data


if(cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if(cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

void charput(unsigned char ch, signed char x,signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if(disp2 > 0)
{
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
}

}
}

void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}

void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions


// Set the Timer Mode to CTC
TCCR0A |= (1 << WGM01);

// Set the value that you want to count to
OCR0A = 0xF9;

TIMSK0 |= (1 << OCIE0A); //Set the ISR COMPA vect

sei(); //enable interrupts


TCCR0B |= (1 << CS02);
// set prescaler to 256 and start the timer



TIFR0 &= ~(1 << TOV0);
// reset the overflow flag
interrupts(); // enable all interrupts
} // End main

void loop() //just sitting here
{
clr();
pixel(0,0,0);
pixel(31,8,0);
charput( 1,1,0);//(unsigned char ch, signed char x,signed char y)
charput( 2,7,0);
strput("OF",15,0);
Blit();
delay(500);
}
 
Last edited:
void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions


TCCR0A = 0b00000010;
TCCR0B = 0b00000001;

TIMSK0 = ob00000001;

TIFR0 = 0;;// reset the overflow flag
TCNT0 = 0;
OCR0A = 5;

interrupts(); // enable all interrupts
} // End main
 
lets take step back.. two paragraphs to change this time:


ISR (TIMER1_COMPA_vect){
if(TIFR1) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR1 = 0; // Clear timer 2 interrupt flag
}


void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 31250; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
} // End main
 
With that there is more living on matrix, quite random sequence, I'll post a shot in a few.
 
Last edited:
oops, nvm!there came something now to screen, made typo in code, will post a pic in a few!
 
Doggy, here's output for that new FontMap:


and full code:
C:
#include "FontMap.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag


}

void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}

void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}

void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}

void pixel(signed char x,signed char y,int cond)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data


if(cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if(cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

void charput(unsigned char ch, signed char x,signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if(disp2 > 0)
{
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
}

}
}

void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}

void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
} // End main

void loop() //just sitting here
{
clr();

pixel(0,0,0);
pixel(31,8,0);

charput( 0,1,0);

charput( 1,11,0);




Blit();
delay(500);
}
 
Last edited:
cant see the 1,
lets change: charput( 1,11,0);
to: charput( 1,7,0);

plus this:
 

Attachments

  • FontMap.h
    8.5 KB · Views: 298
this map should work! lookin good now!
btw , are we still doing a rolling clock with this circuit?
.....for that all we need to do is rewrite the main a bit!
 

Attachments

  • FontMap.h
    8.5 KB · Views: 284
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…