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.
#331, blank, 8-bit fontmap
#334, no change, still showed 7 as blank
All rest codes were blank, but serial monitor showed that it reads at correct places of fontmap
 
no worry , there were code errors in other posts too, I have edited this post: retry post 355
 
Indeed this is harder, still blank screen on both fontmaps AND serial monitor is quiet too :S...
 
Code:
void setdata(unsigned int dat) {
  signed int pos;
  for (pos = 0; pos < Anode_Register_Size; pos++)  //  shift in Anode shift register loop
  //for (pos = Anode_Register_Size; pos > -1; pos--)  // vertical flip
  {
  if (dat & 32768)  // Read MSB first, 0b1000 0000 0000 0000 <--16th bit
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}
 
also these 2 loops plus dont forget to adjust from last post!, I have added serialprint to the pixel function , so now it will output to serial the actual values in each buffer on the ANODE... i think!


Code:
void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return;  // outside drawing limits negative
  if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return;  // outside drawing limits positive
  pix = power[y];  // gets binary position
  msk = backbuffer[x];  // get exsisting data
  if (cond == 2)
  pix ^= msk;  // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk;  // AND data to screen
  }
  if (cond == 0)
  pix |= msk;  // OR data to screen
  backbuffer[x] = pix;  // apply changes
  Serial.println(ob11111111, BIN);     /// change this line so it goes Serial.println("Data in Buffer:", ascii); //I didnt know how to do that properly
  Serial.println(y , BIN);
  Serial.println(pix /256, BIN);
  Serial.println(pix & 0xFF, BIN);
}

Code:
void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  int xa,ya;
for (xa=0;xa<32769;xa=xa*2){
clr();
  pixel(xa,0,0 );
  Blit();
delay(500);
}
for (xa=0;xa<327689;xa=xa*2){
clr();
  pixel(xa,1,0 );
  Blit();
delay(500);
}
}
 
Last edited:
Cool, I'll test these once I get home!
 
Ok, with code #364, small living; segments dot and a blink bit once in a while, but still in pattern,will take shot tomorrow, but with these all, only one dot is lit (16 bit font):
C:
#include "FontMap14Segment.h"

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

unsigned char Display_Buffer_Size =4; // number of rows for buffer
unsigned char Cathode_Register_Size  = 8;  // number of elements in cathode register  (>0)
unsigned int Anode_Register_Size = 16; // number of elements in Anode shift register


unsigned char displayPointer = 0; // for interrupt usefile:///C:/Users/DOGGY-~1/AppData/Local/Temp/FontMap14Segment(16bit).h...
unsigned int buffer1[4]; //2x8 bits
unsigned int backbuffer[4]; // Spare screen for drawing on
//unsigned char power[8] = {1, 2, 4, 8,16,32,64,128}; //B00000001,B00000010,B00000100,B00001000 for digits
unsigned int  power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };


ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
  if (++displayPointer == 2){ displayPointer = 0;}  //  number of cathodes attached, then resets to 0
  }
  TIFR2 = 0; // Clear timer 2 interrupt flag
}



void setcolumn(unsigned char col)  //loop that takes care of column scanning
{
  signed char pos;
  for (pos = Cathode_Register_Size; pos > -1; pos--)  // shift in Cathode shift register loop
  //for (pos = 0; pos < Cathode_Register_Size; pos++)  // going this way flipps the screen horizontal
  {
  if (col == pos)
  {
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);
  }
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}


void setdata(unsigned int dat) {
  signed int pos;
  for (pos = 0; pos < Anode_Register_Size; pos++)  //  shift in Anode shift register loop
  //for (pos = Anode_Register_Size; pos > -1; pos--)  // vertical flip
  {
  if (dat & 32768)  // Read MSB first, 0b1000 0000 0000 0000 <--16th bit
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void clr() //clear
{
  unsigned char addr;
  for (addr = 0; addr < Display_Buffer_Size; addr++)
  backbuffer[addr] = 0;  // clears the buffer array
}

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


void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return;  // outside drawing limits negative
  if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return;  // outside drawing limits positive
  pix = power[y];  // gets binary position
  msk = backbuffer[x];  // get exsisting data
  if (cond == 2)
  pix ^= msk;  // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk;  // AND data to screen
  }
  if (cond == 0)
  pix |= msk;  // OR data to screen
  backbuffer[x] = pix;  // apply changes
  Serial.println(0B11111111, BIN);  /// change this line so it goes Serial.println("Data in Buffer:", ascii); //I didnt know how to do that properly
  Serial.println(y , BIN);
  Serial.println(pix /256, BIN);
  Serial.println(pix & 0xFF, BIN);
}



void charput(unsigned char ch, signed char x, signed char y)
{
  signed char y1;
  unsigned int disp;
  unsigned int disp2;
  disp = font[ch]; //look data from fontmap,
  Serial.println(disp/256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < Anode_Register_Size; y1++)  
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x, y + y1, 0); // OR the pixel to the display buffer
  }
  }


}

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

void setup() //setup runs once
{
  Serial.begin(9600);

  noInterrupts();  // disable all interrupts during setup
  DDRD = DDRD | B11111100;  //port registers used to set pin directions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 520;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
  TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
  TCCR1B |= (0 << CS10);  // 256 prescaler
  TCCR1B |= (0 << CS11);  // 256 prescaler
  TCCR1B |= (1 << CS12);  // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();  // enable all interrupts

} // End main

void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  int xa,ya;
for (xa=0;xa<32769;xa=xa*2){
clr();
  pixel(xa,0,0 );
  Blit();
delay(500);
}
for (xa=0;xa<327689;xa=xa*2){
clr();
  pixel(xa,1,0 );
  Blit();
delay(500);
}
}
 
Doggy, here's output from serial: (pattern isn't worth taking shot of, only dot is lit now for some odd reason, but it does flicker so something is happening) Sorry for delay, got other stuff to do like brand new atmega 328's that were painful to program (no bootloader and google didn't help much, now they all have loader!)
14-segment-serial-output.png
 
oops, 0*2 = 0, plus more bit bangs, should be a little more colourful, may take about 30-60 seconds for full run

Also lets change these back to 8 for now:
unsigned int buffer1[8]; //2x8 bits
unsigned int backbuffer[8]; // Spare screen for drawing on

Code:
void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  int xa,ya;
for (ya=0;ya<8;ya++){
for (xa=1;xa<32769;xa=xa*2){
clr();
  pixel(xa,ya,0 );
  Blit();
delay(500);
}
}
}

I have decided i dont like this, so lets change it back:

void pixel(signed char x, signed char y, int cond)
{
int pix, msk;
if (x < 0 || y < 0) return; // outside drawing limits negative
if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return; // outside drawing limits positive
pix = power[y]; // gets binary position
msk = backbuffer[x]; // get exsisting data
if (cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if (cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

[/code]
and put serprint in the interrupt instead (hope it works!)
Code:
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  Serial.println(0B11111111, BIN);  
  Serial.println(displayPointer , BIN);
  Serial.println(buffer1[displayPointer] /256, BIN);
  Serial.println(buffer1[displayPointer] & 0xFF, BIN);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
}
  if (++displayPointer == 2){ displayPointer = 0;}  //  number of cathodes attached, then resets to 0
  }
  TIFR2 = 0; // Clear timer 2 interrupt flag
}
 
Last edited:
Hmm, I tried to compile but errors rain, here's code(can't see obvious reason for those errors...):
C:
#include "FontMap14Segment.h"

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

unsigned char Display_Buffer_Size = 4; // number of rows for buffer
unsigned char Cathode_Register_Size  = 8;  // number of elements in cathode register  (>0)
unsigned int Anode_Register_Size = 16; // number of elements in Anode shift register


unsigned char displayPointer = 0;
unsigned int buffer1[8]; //2x8 bits
unsigned int backbuffer[8]; // Spare screen for drawing on
//unsigned char power[8] = {1, 2, 4, 8,16,32,64,128}; //B00000001,B00000010,B00000100,B00001000 for digits
unsigned int  power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };


ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  Serial.println(0B11111111, BIN);
  Serial.println(displayPointer , BIN);
  Serial.println(buffer1[displayPointer] / 256, BIN);
  Serial.println(buffer1[displayPointer] & 0xFF, BIN);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
  }
  if (++displayPointer == 2)
  {
  displayPointer = 0;
  }
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
}



void setcolumn(unsigned char col)  //loop that takes care of column scanning
{
  signed char pos;
  for (pos = Cathode_Register_Size; pos > -1; pos--)  // shift in Cathode shift register loop
  //for (pos = 0; pos < Cathode_Register_Size; pos++)  // going this way flipps the screen horizontal
  {
  if (col == pos)
  {
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);
  }
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}


void setdata(unsigned int dat)
{
  signed int pos;
  for (pos = 0; pos < Anode_Register_Size; pos++)  //  shift in Anode shift register loop
  //for (pos = Anode_Register_Size; pos > -1; pos--)  // vertical flip
  {
  if (dat & 32768)  // Read MSB first, 0b1000 0000 0000 0000 <--16th bit
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void clr() //clear
{
  unsigned char addr;
  for (addr = 0; addr < Display_Buffer_Size; addr++)
  backbuffer[addr] = 0;  // clears the buffer array
}

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


void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return; // outside drawing limits negative
  if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return; // outside drawing limits positive
  pix = power[y]; // gets binary position
  msk = backbuffer[x]; // get exsisting data
  if (cond == 2)
  pix ^= msk; // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk; // AND data to screen
  }
  if (cond == 0)
  pix |= msk; // OR data to screen
  backbuffer[x] = pix; // apply changes
}



void charput(unsigned char ch, signed char x, signed char y)
{
  signed char y1;
  unsigned int disp;
  unsigned int disp2;
  disp = font[ch]; //look data from fontmap,
  Serial.println(disp / 256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < Anode_Register_Size; y1++)
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x, y + y1, 0); // OR the pixel to the display buffer
  }
  }


}

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

void setup() //setup runs once
{
  Serial.begin(9600);

  noInterrupts();  // disable all interrupts during setup
  DDRD = DDRD | B11111100;  //port registers used to set pin directions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 520;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
  TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
  TCCR1B |= (0 << CS10);  // 256 prescaler
  TCCR1B |= (0 << CS11);  // 256 prescaler
  TCCR1B |= (1 << CS12);  // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();  // enable all interrupts

} // End main

void loop() //just sitting here
{
  int val = millis() / 1000 % 10;
  int xa, ya;
  for (ya = 0; ya < 8; ya++) {
  for (xa = 1; xa < 32769; xa = xa * 2) {
  clr();
  pixel(xa, ya, 0 );
  Blit();
  delay(500);
  }
  }
}
C:
Arduino: 1.6.7 (Windows 7), TD: 1.27, Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

C:\Users\Atte\AppData\Local\Temp\arduino_2c95d8b8a178f3b50e0698535cbfb980\_14-segment-testing.ino: In function 'void __vector_11()':

_14-segment-testing:23: error: 'setcolumn' was not declared in this scope

  setcolumn(displayPointer);  //column scanning

  ^

_14-segment-testing:24: error: 'setdata' was not declared in this scope

  setdata(buffer1[displayPointer]);

  ^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

  from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:88,

  from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

  from sketch\_14-segment-testing.ino.cpp:1:

C:\Users\Atte\AppData\Local\Temp\arduino_2c95d8b8a178f3b50e0698535cbfb980\_14-segment-testing.ino: At global scope:

_14-segment-testing:37: error: expected unqualified-id before 'volatile'

 TIFR2 = 0; // Clear timer 2 interrupt flag

 ^

_14-segment-testing:37: error: expected ')' before 'volatile'

_14-segment-testing:37: error: expected ')' before 'volatile'

_14-segment-testing:38: error: expected declaration before '}' token

 }

 ^

exit status 1
'setcolumn' was not declared in this scope
[/code
 
lol, oops, had too many brackets in the interrupt loop:

Code:
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  Serial.println(0B11111111, BIN);
  Serial.println(displayPointer , BIN);
  Serial.println(buffer1[displayPointer] / 256, BIN);
  Serial.println(buffer1[displayPointer] & 0xFF, BIN);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
  if (++displayPointer == 2)  {  displayPointer = 0;  }
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
 
Doggy, here's serial output, no error now, and leftside digit dot is lit flickering.
14-segment-serial-output.png
 
ok here is another test that should give results, the trick is to count how many lights on each segment, should be consistent, i think the problem here is that we have one of the buffers/registers reversed, also in the mean time I'm thinking about another arduio for myself, but before i do , and for us here, ima try to get this atml studio for vb working, i hear roomer that with it we will be able to debug the arduino, which helps alot...

Code:
#include "FontMap14Segment.h"

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

unsigned char Display_Buffer_Size =8; // number of rows for buffer
unsigned char Cathode_Register_Size  = 8;  // number of elements in cathode register  (>0)
unsigned int Anode_Register_Size = 16; // number of elements in Anode shift register


unsigned char displayPointer = 0; // for interrupt usefile:///C:/Users/DOGGY-~1/AppData/Local/Temp/FontMap14Segment(16bit).h...
unsigned int buffer1[16]; //2x8 bits
unsigned int backbuffer[16]; // Spare screen for drawing on
//unsigned char power[8] = {1, 2, 4, 8,16,32,64,128}; //B00000001,B00000010,B00000100,B00001000 for digits
unsigned int  power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
  Serial.println(0B11111111, BIN);  /// change this line so it goes Serial.println("Data in Buffer:", ascii); //I didnt know how to do that properly
  Serial.println(displayPointer , BIN);
  Serial.println(buffer1[displayPointer] /256, BIN);
  Serial.println(buffer1[displayPointer] & 0xFF, BIN);
  if (++displayPointer == 8){ displayPointer = 0;}  //  number of cathodes attached, then resets to 0
  }
  TIFR2 = 0; // Clear timer 2 interrupt flag
}



void setcolumn(unsigned char col)  //loop that takes care of column scanning
{
  signed char pos;
  for (pos = Cathode_Register_Size; pos > -1; pos--)  // shift in Cathode shift register loop
  //for (pos = 0; pos < Cathode_Register_Size; pos++)  // going this way flipps the screen horizontal
  {
  if (col == pos)
  {
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);
  }
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}


void setdata(unsigned int dat) {
  signed int pos;
  //for (pos = 0; pos < Anode_Register_Size; pos++)  //  shift in Anode shift register loop
  for (pos = Anode_Register_Size; pos > -1; pos--)  // vertical flip
  {
  if (dat & 32768)  // Read MSB first, 0b1000 0000 0000 0000 <--16th bit
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void clr() //clear
{
  unsigned char addr;
  for (addr = 0; addr < Display_Buffer_Size; addr++)
  backbuffer[addr] = 0;  // clears the buffer array
}

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


void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return;  // outside drawing limits negative
  if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return;  // outside drawing limits positive
  pix = power[y];  // gets binary position
  msk = backbuffer[x];  // get exsisting data
  if (cond == 2)
  pix ^= msk;  // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk;  // AND data to screen
  }
  if (cond == 0)
  pix |= msk;  // OR data to screen
  backbuffer[x] = pix;  // apply changes
}



void charput(unsigned char ch, signed char x, signed char y)
{
  signed char y1;
  unsigned int disp;
  unsigned int disp2;
  disp = font[ch]; //look data from fontmap,
  Serial.println(disp/256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < Anode_Register_Size; y1++)
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x, y + y1, 0); // OR the pixel to the display buffer
  }
  }


}

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

void setup() //setup runs once
{
  Serial.begin(9600);

  noInterrupts();  // disable all interrupts during setup
  DDRD = DDRD | B11111100;  //port registers used to set pin directions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 520;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
  TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
  TCCR1B |= (0 << CS10);  // 256 prescaler
  TCCR1B |= (0 << CS11);  // 256 prescaler
  TCCR1B |= (1 << CS12);  // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();  // enable all interrupts

} // End main

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

  int  ya;
  for (ya = 0; ya < 16; ya++) {
backbuffer[ya] = power[ya] - 1;
  Blit();
  delay(500);

}
 
Last edited:
hmm, all is empty, on screen as well as serial monitor
 
Odd, still left dot flickers, but now it also stops too, need video? it flickers about 6-7 seconds,then 1 second off, repeat
 
Indeed it shows data now, dot doesn't flicker now however: (sorry, it does flicker, it just took a while....)
14-segment-serial-output.png
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top