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.
Gave errors, currently figuring these out:
C:
Arduino: 1.6.5 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

sketch_jan12a.ino: In function 'void displaystring3()':
sketch_jan12a:172: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
sketch_jan12a:94: error: initializing argument 1 of 'void charput(char, signed char, signed char)' [-fpermissive]
sketch_jan12a:173: error: expected ';' before 'charput'
invalid conversion from 'const char*' to 'char' [-fpermissive]

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
 
Last edited:
ah yes, semicolons, i like to forget those!I have no adruino debugger today , so i will try to focus on small mistakes, but we are over the main hump so feel free to play with code now!

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(0x72, 1,1);
charput(0x73, 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
   {}
 
Last edited:
ah yes, semicolons, i like to forget those!
you're not the only one...:D
How you fixed that conversion error? I looked and couldn't find reason...
No errors now but screen is totally blank, nothing even stationary :/
 
think i did in post , by changing it to hex, if not lemmie kno, and try others, i am bad in reading pointers still, really if you want , just cut out line: displaystring3() in void setup()

EDIT : hmm blank, better cut out displaystring() in void setup() as well,
 
Last edited:
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 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
   displaystring2();  //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
   {}
 
edited those, and here's code, still blank:
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 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(0x72, 1,1);
charput(0x73, 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
   {}
 
Last edited:
Tried your code too, same lerust :/
I mean result lol...
 
I have fear about this pixel() sub, maybe i dont exactly get what hes doing here, Maybe Ian can elaborate to help us with this, in the mean time, i will rewrite it as pixel2(), see if we can get some leeway.



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=31;           // 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<1) { 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 pixel2(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 = y;             // pixel required
   pix = power[pix];


   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[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 displaystring1(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
    clr();               // Clear the display buffer
backbuffer[0] = 2;backbuffer[1] = 2;
backbuffer[2] = 3;backbuffer[3] = 3;
backbuffer[32] = 192;backbuffer[31] = 192;
backbuffer[30] = 224;backbuffer[29] = 224;

     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
backbuffer[0] = 3;backbuffer[1] = 3;
backbuffer[2] = 3;backbuffer[3] = 3;
backbuffer[32] = 2;backbuffer[31] = 2;
backbuffer[30] = 3;backbuffer[29] = 3;
     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
pixel(4, 6,0);
pixel(5, 6,0);
pixel(4, 7,0);
pixel(5, 7,0);

pixel2(6, 7,0);
pixel2(7, 7,0);
pixel2(6, 8,0);
pixel2(7, 8,0);


     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




     Blit();               // pass to screen buffer
     delay(500);           // time to view
   }





void displaystring8(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

   displaystring1();  //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
   {}
 
Last edited:
Still empty, I wonder would it be easier to start from scratch? At least then there are no confusions between hardware differences, just a thought.
 
well, we kinda are, we are getting it all sorted, except the pixel, charput, an strput, i updated last post , try that now

...its what debugging is all about!
 
think you should get nice display from this one,

right now we got the subs working: ISR(almost), blit, clr, which were the main ones, so we are half way anyway!

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=31;           // 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<1) { displayPointer = 31;  }    // 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 pixel2(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 = y;             // pixel required
   pix = power[pix];


   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[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 displaystring1(void)         // this routine prints through the screen buffer
   {                   // moving one pixel at a time
    clr();               // Clear the display buffer
backbuffer[0] = 1;backbuffer[1] = 1;
backbuffer[2] = 3;backbuffer[3] = 3;
backbuffer[30] = 128;backbuffer[31] = 128;
backbuffer[28] = 192;backbuffer[29] = 192;

     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
backbuffer[0] = 128;backbuffer[1] = 128;
backbuffer[2] = 192;backbuffer[3] = 192;
backbuffer[30] = 1;backbuffer[31] = 1;
backbuffer[28] = 3;backbuffer[29] = 3;
     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
pixel(4, 6,0);
pixel(5, 6,0);
pixel(4, 7,0);
pixel(5, 7,0);

pixel2(6, 7,0);
pixel2(7, 7,0);
pixel2(6, 8,0);
pixel2(7, 8,0);


     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




     Blit();               // pass to screen buffer
     delay(500);           // time to view
   }





void displaystring8(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

   displaystring1();  //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
   {}
 
Only two leds from leftmost matrix lights up, left-lower and upper-left but one to the right: better than blank!
 
Doggy, you got patience, I give you that!
 
thanks for yours as well, i find this a fun challenge, and is half learning for me too! I have little experience compared to some here, if i were to have written this on my own it would be less functional(dynamic) and not as good in the long run, also dont forget , we are doing alot here, not only did we fix that hardware prob, but other small incompatibilities, plus when we get this working it will be alot more functional when you want to put random data in to it...usually this would go faster , but the inexp in me causes to miss little things, if anyone else were here it would have gone 3x faster, no matter what the skill lvl, I have noticed that programming is always like this, even the pro's will sometimes write a code, then need to go through it step by step to find that a 1 should be a 0 somewhere...or other small dumb things*

btw how did last code work(i changed again)? you should get all 4 corners lit up to confirm we are done with ISR()
 
btw how did last code work(i changed again)? you should get all 4 corners lit up to confirm we are done with ISR()
result is at post #74, doesn't give output wanted, but at least something! It's all win-win when no smoke is seen ;D
 
I asked this too at arduino's forums but for some reason not much help there :/
 
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=31;  // 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<1) { displayPointer = 31;  }  // 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);}
}}

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);} 
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 pixel2(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 = y;  // pixel required
  pix = power[pix];


  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[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 displaystring1(void)  // this routine prints through the screen buffer
  {  // moving one pixel at a time
  clr();  // Clear the display buffer
backbuffer[0] = 0;
backbuffer[1] = 1;
backbuffer[2] = 2;
backbuffer[3] = 3;
backbuffer[4] = 4;
backbuffer[5] = 5;
backbuffer[6] = 6;
backbuffer[7] = 7;
backbuffer[8] = 8;
backbuffer[9] = 128;
backbuffer[10] = 192;


backbuffer[31] = 0;
backbuffer[30] = 1;
backbuffer[29] = 2;
backbuffer[28] = 3;
backbuffer[27] = 4;
backbuffer[26] = 5;
backbuffer[25] = 6;
backbuffer[24] = 7;
backbuffer[23] = 8;
backbuffer[22] = 192;

  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
backbuffer[0] = 128;backbuffer[1] = 128;
backbuffer[2] = 192;backbuffer[3] = 192;
backbuffer[30] = 1;backbuffer[31] = 1;
backbuffer[28] = 3;backbuffer[29] = 3;
  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
pixel(4, 6,0);
pixel(5, 6,0);
pixel(4, 7,0);
pixel(5, 7,0);

pixel2(6, 7,0);
pixel2(7, 7,0);
pixel2(6, 8,0);
pixel2(7, 8,0);


  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




  Blit();  // pass to screen buffer
  delay(500);  // time to view
  }





void displaystring8(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

  displaystring1();  //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
  {}
 
Thanks again, sadly blank screen. :/
no errors thankfully! :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top