Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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

Status
Not open for further replies.
Oh, right! I did take those off as inside ISR there would have been anyway when shift registers are controlled, should have just commented them. now that you mention, rc's are pins/inputs so no wonder it doesn't work.
Take your time, I 'aint going nowhere :)
 
Doggy, placed simple test inside ISR and now there's some live in matrix, 1 flashes in all matrises quickly, so seems you're right, ISR we've been ignoring so far (Ian mentioned about it earlier about keeping leds alive?):
C:
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;

char displayPointer=0;           // for interrupt use...
static uint8_t  font [80] =    //numbers stored here
{
  0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
  0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
  0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
  0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
  0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
  0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
  0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
  0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
  0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
  0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
unsigned char buffer[32];          // buffer for screen
unsigned char backbuffer[32];       // Spare screen for drawing on
char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
   {
      for (int i = 0; i < 8; i++)
  {
    PORTD = B00000000;                                  //turn latch low
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << i);          //Send the data #2        (what columns to power)
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << i);          //Send the data #2        (what columns to power)
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << i);          //Send the data #2        (what columns to power)
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << i);          //Send the data #2        (what columns to power)
    shiftOut(dataPin, clockPin, LSBFIRST, font[i + 8]); //Send the data #1       ( what data to draw)
    PORTD = B00001000;
  }
 
   /*
     if(displayPointer == 0 )      // 1st frame..
     PORTB = buffer[displayPointer];   // Move buffer row by row( 4 row sections per row )
     if(++displayPointer==32)      // 32 LED row sections in total
       displayPointer = 0;       // Back to first row..*/
 

   }

void pixel(signed char x,signed char y,int cond)
   {
   int tmp;
   char pix,msk;
   if(x<0 || y<0) return;       // outside drawing limits negative
   if(x>31 || y>7) return;       // outside drawing limits positive
   tmp = (y << 2) + (x>>3);     // Linear position
   pix = x%8;             // pixel required
   pix = power[pix];
   msk = backbuffer[tmp];       // 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[tmp] = pix;       // apply changes
   }

void charput(char ch, signed char x,signed char y)
   {
   signed char x1, y1;    
   const uint8_t* addr2;         // pointer to character
   char disp;
   ch -= 0x20;             // characters starts a 0 not 0x20
   addr2 = &font[0];         // start of font array
   addr2 = addr2 + ((int)ch * 8);   // start place in font array
   for( y1=0;y1<8;y1++)       // eight rows
     {
     disp = *addr2;
     for (x1 = 0; x1<8; x1++)   // eight pixels
       {  
       if(disp & power[x1])
         pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
       }
     addr2++;
     }
   }

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 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 ++)
     {
     buffer[addr] = backbuffer[addr];   // put all data from display buffer
     }                   // to screen buffer
   interrupts();             // enable all interrupts
   }



void displaystring(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
   signed char x=32,y=0;         // I made these signed so I could print
   for(y = 0;y  < 96 ;y++)         // to nowhere so I could produce the scrolling effect
     {
     clr();               // Clear the display buffer
     strput("HELLO WORLD!!",x--,0);   // adjust the scrolling string
     Blit();               // pass to screen buffer
     delay(80);           // time to view
     }
   }

void setup()          //setup runs once
   {
    noInterrupts();           // disable all interrupts during setup
    DDRD = DDRD | B11111100;  //port registers used to set pin directions
   //int sx,sy;   //these two necessary? couldn't see them anywhere else than ball-thingy
   //int xdir=1, ydir=1;
  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
   displaystring();  //prints just hello world at startup

   while(1)         //essentially loop()? but loop is still needed...
     {
     clr();    //clear buffer first
     /*sx += xdir; sy += ydir;     no balls needed so can be omitted
  strput("]",sx,sy);      // this is a ball character for bouncing routine

     if(sx>27) xdir = -1;      /// Wall limits
     if(sy>4) ydir = -1;
     if(sx<0) xdir = 1;
     if(sy<0) ydir = 1;*/
     delay(80);    //delay, but won't effect ISR
     Blit();       //swap buffers
     }
   }   // End main

   void loop() //just sitting here
   {}
 
Last edited:
Thanks for sarcificing time on me Ian :) I owe you a beer...
 
okay Fezder try this one:) I was not ignoring the isr earlier, was just trying to access the buffer connected to it on the pixel level.
(Ian mentioned about it earlier about keeping leds alive?)
i think you are referring to the blit function, so what happens is you write what you want to display in the backbuffer, when you are done editing you call the blit function where it takes the info from backbuffer and passes it to buffer, then when the isr is called it displays all info in buffer. Blit is like the apply button , so the micro displays with proper timing, but giving you the extra time needed to populate your data.

Code:
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;

char displayPointer=0;           // for interrupt use...
static char font [80] =    //numbers stored here
{
  0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
  0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
  0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
  0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
  0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
  0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
  0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
  0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
  0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
  0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
unsigned char buffer[32];          // buffer for screen
unsigned char backbuffer[32];       // Spare screen for drawing on
char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
   {
   unsigned char columndata;
   unsigned char columnnumber;

    if(TIFR2)               // Make sure its the timer interrupt.
     {
     columndata= buffer[displayPointer];  // 32 bits of column
     columnnumber = displayPointer;


     setcolumn(columnnumber);
     setdata(columndata);
     storeclock();


     if(++displayPointer==32) { displayPointer = 0;  }    // 32 LED row sections in total
     }
   TIFR2 = 0;               // Clear timer 2 interrupt flag


   }

void setcolumn(unsigned char col){
  unsigned char pos;
for (pos = 0;pos<32;pos++){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);}     // replace PIN1 with DATA pin
shiftclock();
}}

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);}      // Replace PIN1 with DATA pin
dat = dat * 2;
shiftclock();
}}

void shiftclock(void){
digitalWrite(clockPin   ,HIGH);digitalWrite(clockPin  ,LOW);// change PIN2 to SHIFTCLOCK pin, add delay if this is too fast for shift registers
}

void storeclock(void){
digitalWrite(latchPin  ,HIGH);digitalWrite(latchPin , LOW ); // change PIN3 to STORECLOCK, add delay if this is too fast for shift registers
}

void pixel(signed char x,signed char y,int cond)
   {
   int tmp;
   char pix,msk;
   if(x<0 || y<0) return;       // outside drawing limits negative
   if(x>31 || y>7) return;       // outside drawing limits positive
   tmp = (y << 2) + (x>>3);     // Linear position
   pix = x%8;             // pixel required
   pix = power[pix];
   msk = backbuffer[tmp];       // 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[tmp] = pix;       // apply changes
   }

void charput(char ch, signed char x,signed char y)
   {
   signed char x1, y1;   
   const char* addr2;         // pointer to character
   char disp;
   ch -= 0x20;             // characters starts a 0 not 0x20
   addr2 = &font[0];         // start of font array
   addr2 = addr2 + ((int)ch * 8);   // start place in font array
   for( y1=0;y1<8;y1++)       // eight rows
     {
     disp = *addr2;
     for (x1 = 0; x1<8; x1++)   // eight pixels
       { 
       if(disp & power[x1])
         pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
       }
     addr2++;
     }
   }

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 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 ++)
     {
     buffer[addr] = backbuffer[addr];   // put all data from display buffer
     }                   // to screen buffer
   interrupts();             // enable all interrupts
   }



void displaystring(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
   signed char x=32,y=0;         // I made these signed so I could print
   for(y = 0;y  < 96 ;y++)         // to nowhere so I could produce the scrolling effect
     {
     clr();               // Clear the display buffer
     strput("HELLO WORLD!!",x--,0);   // adjust the scrolling string
     Blit();               // pass to screen buffer
     delay(1000);           // time to view
     }
   }

void setup()          //setup runs once
   {
    noInterrupts();           // disable all interrupts during setup
    DDRD = DDRD | B11111100;  //port registers used to set pin directions
   //int sx,sy;   //these two necessary? couldn't see them anywhere else than ball-thingy
   //int xdir=1, ydir=1;
  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
   displaystring();  //prints just hello world at startup

   while(1)         //essentially loop()? but loop is still needed...
     {
     clr();    //clear buffer first
     /*sx += xdir; sy += ydir;     no balls needed so can be omitted
  strput("]",sx,sy);      // this is a ball character for bouncing routine

     if(sx>27) xdir = -1;      /// Wall limits
     if(sy>4) ydir = -1;
     if(sx<0) xdir = 1;
     if(sy<0) ydir = 1;*/
     delay(80);    //delay, but won't effect ISR
     Blit();       //swap buffers
     }
   }   // End main

   void loop() //just sitting here
   {}
:
 
It displayed random sequence of bits, slowly, about once/second, shall I take video clip?
 
well, if I increase ISR interval, there is some pattern to be seen, what it should look like?
 
speed it up a bit so it is comfortable to read:
by changing this, in void displaystring(void):
delay(1000); // time to view
to this:
delay(500); // time to view

it should now be displaying the hello world splash screen , but maybe rotated or flipped , let it fill screen then screenshot right side up(so photo is taken in the direction you want to read it in).
 
Hmm, It doesn't show hello world, I'll upload small clip in a few!
 
Say if you can't see it, delay(500);
 
looks good, somehow, here is edit that will display simpler image better for debugging...

Code:
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;

char displayPointer=0;           // for interrupt use...
static char font [80] =    //numbers stored here
{
  0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
  0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
  0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
  0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
  0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
  0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
  0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
  0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
  0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
  0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
unsigned char buffer[32];          // buffer for screen
unsigned char backbuffer[32];       // Spare screen for drawing on
char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
   {
   unsigned char columndata;
   unsigned char columnnumber;

    if(TIFR2)               // Make sure its the timer interrupt.
     {
     columndata= buffer[displayPointer];  // 32 bits of column
     columnnumber = displayPointer;


     setcolumn(columnnumber);
     setdata(columndata);
     storeclock();


     if(++displayPointer==32) { displayPointer = 0;  }    // 32 LED row sections in total
     }
   TIFR2 = 0;               // Clear timer 2 interrupt flag


   }

void setcolumn(unsigned char col){
  unsigned char pos;
for (pos = 0;pos<32;pos++){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);}     // replace PIN1 with DATA pin
shiftclock();
}}

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);}      // Replace PIN1 with DATA pin
dat = dat * 2;
shiftclock();
}}

void shiftclock(void){
digitalWrite(clockPin   ,HIGH);digitalWrite(clockPin  ,LOW);// change PIN2 to SHIFTCLOCK pin, add delay if this is too fast for shift registers
}

void storeclock(void){
digitalWrite(latchPin  ,HIGH);digitalWrite(latchPin , LOW ); // change PIN3 to STORECLOCK, add delay if this is too fast for shift registers
}

void pixel(signed char x,signed char y,int cond)
   {
   int tmp;
   char pix,msk;
   if(x<0 || y<0) return;       // outside drawing limits negative
   if(x>31 || y>7) return;       // outside drawing limits positive
   tmp = (y << 2) + (x>>3);     // Linear position
   pix = x%8;             // pixel required
   pix = power[pix];
   msk = backbuffer[tmp];       // 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[tmp] = pix;       // apply changes
   }

void charput(char ch, signed char x,signed char y)
   {
   signed char x1, y1; 
   const char* addr2;         // pointer to character
   char disp;
   ch -= 0x20;             // characters starts a 0 not 0x20
   addr2 = &font[0];         // start of font array
   addr2 = addr2 + ((int)ch * 8);   // start place in font array
   for( y1=0;y1<8;y1++)       // eight rows
     {
     disp = *addr2;
     for (x1 = 0; x1<8; x1++)   // eight pixels
       {
       if(disp & power[x1])
         pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
       }
     addr2++;
     }
   }

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 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 ++)
     {
     buffer[addr] = backbuffer[addr];   // put all data from display buffer
     }                   // to screen buffer
   interrupts();             // enable all interrupts
   }



void displaystring(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
   signed char x=32,y=0;         // I made these signed so I could print
   for(y = 0;y  < 32 ;y++)         // to nowhere so I could produce the scrolling effect
     {
     clr();               // Clear the display buffer
    backbuffer[y] = y/4 + 1;
     Blit();               // pass to screen buffer
     delay(500);           // time to view
     }
   }

void setup()          //setup runs once
   {
    noInterrupts();           // disable all interrupts during setup
    DDRD = DDRD | B11111100;  //port registers used to set pin directions
   //int sx,sy;   //these two necessary? couldn't see them anywhere else than ball-thingy
   //int xdir=1, ydir=1;
  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
   displaystring();  //prints just hello world at startup

   while(1)         //essentially loop()? but loop is still needed...
     {
     clr();    //clear buffer first
     /*sx += xdir; sy += ydir;     no balls needed so can be omitted
  strput("]",sx,sy);      // this is a ball character for bouncing routine

     if(sx>27) xdir = -1;      /// Wall limits
     if(sy>4) ydir = -1;
     if(sx<0) xdir = 1;
     if(sy<0) ydir = 1;*/
     delay(80);    //delay, but won't effect ISR
     Blit();       //swap buffers
     }
   }   // End main

   void loop() //just sitting here
   {}
 
OK, now it showed sequence of couple lit leds, starting from right and going to left, hard to explain so time for another small clip, stay tuned...
 
 
Thanks! Rows are driven with 74595 (470 ohm resistors) and columns are octal transistor arrays uln2804 (which are driven by 74595's)
 
So far I've been happy with them; cheap, easy to use (only this problem has been biggest so far!), fast and good current output.
 
going by that pixel 1,1 is in the top right , so first we change it to left (not sure if we should start at top/bottom though, may need to flip that too,will test later)
try this one, i adjusted to print now from right to left, also have cloned displaystring() to test the other functions:

Code:
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;




char displayPointer=0;           // for interrupt use...
static char font [80] =    //numbers stored here
{
  0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
  0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
  0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
  0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
  0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
  0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
  0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
  0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
  0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
  0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
unsigned char buffer[32];          // buffer for screen
unsigned char backbuffer[32];       // Spare screen for drawing on
char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
   {
   unsigned char columndata;
   unsigned char columnnumber;

    if(TIFR2)               // Make sure its the timer interrupt.
     {
     columndata= buffer[displayPointer];  // 32 bits of column
     columnnumber = displayPointer;


     setcolumn(columnnumber);
     setdata(columndata);
     storeclock();


     if(--displayPointer==0) { displayPointer = 32;  }    // 32 LED row sections in total
     }
   TIFR2 = 0;               // Clear timer 2 interrupt flag


   }

void setcolumn(unsigned char col){
  unsigned char pos;
for (pos = 0;pos<32;pos++){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);}     // replace PIN1 with DATA pin
shiftclock();
}}

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);}      // Replace PIN1 with DATA pin
dat = dat * 2;
shiftclock();
}}

void shiftclock(void){
digitalWrite(clockPin   ,HIGH);digitalWrite(clockPin  ,LOW);// change PIN2 to SHIFTCLOCK pin, add delay if this is too fast for shift registers
}

void storeclock(void){
digitalWrite(latchPin  ,HIGH);digitalWrite(latchPin , LOW ); // change PIN3 to STORECOCK, add delay if this is too fast for shift registers
}

void pixel(signed char x,signed char y,int cond)
   {
   int tmp;
   char pix,msk;
   if(x<0 || y<0) return;       // outside drawing limits negative
   if(x>31 || y>7) return;       // outside drawing limits positive
   tmp = (y << 2) + (x>>3);     // Linear position
   pix = x%8;             // pixel required
   pix = power[pix];
   msk = backbuffer[tmp];       // 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[tmp] = pix;       // apply changes
   }

void charput(char ch, signed char x,signed char y)
   {
   signed char x1, y1;     
   const char* addr2;         // pointer to character
   char disp;
   ch -= 0x20;             // characters starts a 0 not 0x20
   addr2 = &font[0];         // start of font array
   addr2 = addr2 + ((int)ch * 8);   // start place in font array
   for( y1=0;y1<8;y1++)       // eight rows
     {
     disp = *addr2;
     for (x1 = 0; x1<8; x1++)   // eight pixels
       {   
       if(disp & power[x1])
         pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
       }
     addr2++;
     }
   }

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 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 ++)
     {
     buffer[addr] = backbuffer[addr];   // put all data from display buffer
     }                   // to screen buffer
   interrupts();             // enable all interrupts
   }



void displaystring(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
   signed char x=32,y=0;         // I made these signed so I could print
   for(y = 0;y  < 96 ;y++)         // to nowhere so I could produce the scrolling effect
     {
     clr();               // Clear the display buffer
     strput("HELLO WORLD!!",x--,0);   // adjust the scrolling string
     Blit();               // pass to screen buffer
     delay(500);           // time to view
     }
   }


void displaystring2(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
    clr();               // Clear the display buffer
pixel(1,1,0);
pixel(2,2,0);
pixel(32,8,0);
pixel(31,8,0);
     Blit();               // pass to screen buffer
     delay(500);           // time to view
   }


void displaystring3(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
     clr();               // Clear the display buffer
charput("H", 1,1)
charput("I", 12,12)
     Blit();               // pass to screen buffer
     delay(500);           // time to view
   }


void displaystring4(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
     clr();               // Clear the display buffer
     strput("WOOF",0,0);   // adjust the scrolling string
     Blit();               // pass to screen buffer
     delay(500);           // time to view

   }

void setup()          //setup runs once
   {
    noInterrupts();           // disable all interrupts during setup
    DDRD = DDRD | B11111100;  //port registers used to set pin directions
   //int sx,sy;   //these two necessary? couldn't see them anywhere else than ball-thingy
   //int xdir=1, ydir=1;
  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
   displaystring();  //prints just hello world at startup
   displaystring2();  //prints just hello world at startup
   displaystring3();  //prints just hello world at startup
   displaystring4();  //prints just hello world at startup

   while(1)         //essentially loop()? but loop is still needed...
     {
     clr();    //clear buffer first
     /*sx += xdir; sy += ydir;     no balls needed so can be omitted
  strput("]",sx,sy);      // this is a ball character for bouncing routine

     if(sx>27) xdir = -1;      /// Wall limits
     if(sy>4) ydir = -1;
     if(sx<0) xdir = 1;
     if(sy<0) ydir = 1;*/
     delay(80);    //delay, but won't effect ISR
     Blit();       //swap buffers
     }
   }   // End main

   void loop() //just sitting here
   {}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top