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.
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==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);}
}}

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
  {}
 
Still same result, blank :/. This thread reminds of that peak detector what I tackled with AG. That was resilient problem too...
 
its hard to get help for full pages of code, specifically since it's hard to find the small issues, when i first got my cube going i had a problem with a spi eeprom, where i confused the size value of a sector and a page, so i was trying to erase a whole page , but it was only erasing sector, this caused a few problems, but took a long time to figure out that i should have used instruction 50, not 51 , but when debugging, you think its ok, so you look over it , ect...

found problem, again a doggy mistake,, somewhere in there i deleted the instruction to shiftclock() in the setcolomn() sub... would cause blank for shure!
 
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);}
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);}
dat = dat * 2;
shiftclock();
}}

void shiftclock(void){
digitalWrite(clockPin  ,HIGH);digitalWrite(clockPin  ,LOW);
}

void storeclock(void){
digitalWrite(latchPin  ,HIGH);digitalWrite(latchPin , LOW );
}

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;



  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
unsigned char cntr3;
  clr();  // Clear the display buffer

for (cntr3=0;cntr3<32;cntr3++){
backbuffer[cntr3] = cntr3;
}



  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
  {}
 
I find when i get no response it cause i ask:
1)too big
2)too confusing
3)does not make sense
4)not technical enough
5)too technical :)
of questions
 
Hehe, it doesn't matter, I think I can solve this in here, that thread in there is oldie so not feeling like resurrecting it anyway, but here it is(in fact, it's not that old what i recalled...)
https://forum.arduino.cc/index.php?topic=369981.0
Tested that code and no avail, one led blinks once at start in rightmost matrix
 
here's result from last code:
 
it s times like this I revert back to the last working code, good to do backups now and then!, dont know what i did, but going to revert to code on post 51 and edit from there!

AlSO % means get the remainder of, so x=19%4 , x would be 3 cause 19/4=4 remainder 3 but in this it drops the 3

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 = 32;pos>0;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
      clr();
for(y = 0;y  < 32 ;y++)         // to nowhere so I could produce the scrolling effect
     {
                 // 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
   {}
 
Cool, modulos in the soup!
Didn't help though :D Blank screen
 
*was something here, wrong topic*
 
*another was something here, wrong topic*
 
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*

I must admit... It does get easier.... BUT!!! when you have more than two projects on the go it gets a bit daunting... Debugging code will always be a tough cookie and no amount of experience will make the job any easier... When you get to six or seven pages of code... There comes a point where you stuff code into libraries... But that brings more heartache... It seems the problems just get bigger as you move along... The problem here is.. You become accustomed to bigger and bigger issues...

I have a bit of an issue at the moment!!! As progress "progresses" so to speak newer chips replace older chips... I now find that code that run perfectly well on a pic18f4520 doesn't run as well on the slightly newer pic18f45k22 ( k22 because the k20 is 3v3 only ) Who knew!!!! Days and days of debugging to find out stuff.. searching through addendum's... searching through workaround sheets.... Pain in the Harris, I can tell you!!

Still! If I didn't enjoy it, it would be in the skip!!!
 
or when you need both to communicate with each other! yes, the fun never ends, this is also a core reason why i don't really like to update windows things unless i need to.

I am worried about this blank screen i cannot see error that would do that, please try code from post 51, to verify. Also the funny pattern you mentioned(post 55) is what counting in binary looks like (1-8).
 
Ian! You changed bottle I see :).
Code in post 51 gives result seen in post #55.
 
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 = 31;pos>0;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
   {}
 
Slight progress, I have feeling this is how you imagined it look?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top