int buffer1[4]; // buffer for screen,4x8=32
int backbuffer[4]; //Spare screen for drawing on, 4x8=32
int power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
int pix, msk;
void charput(unsigned char ch, signed char x, signed char y)
{
signed char x1, y1;
int disp;
int disp2;
disp = font[ (ch)]; //look data from fontmap,
Serial.println(disp/256, BIN);
Serial.println(disp & 0xFF, BIN);
for (y1 = 0; y1 < 16; y1++) // eight pixels
{
disp2 = disp & power[y1];
if (disp2 > 0)
{
pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
}
}
}
//MSB
static unsigned int font [125] = //numbers stored here
{ //Position, Character
// B (null) M L K J I H G2, B G1 F E D C B A DOT
B0001100001111110, // 0 0
B0000000000001100, // 1 1
B0000000110110110, // 2 2
B0000000110011110, // 3 3
B0000000111001100, // 4 4
B0000000111011010, // 5 5
B0000000111111010, // 6 6
B0000000000001110, // 7 7
B0000000111111110, // 8 8
B0000000111011110, // 9 9
Arduino: 1.6.7 (Windows 7), TD: 1.27, Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"
In file included from C:\Users\Atte\AppData\Local\Temp\arduino_2c95d8b8a178f3b50e0698535cbfb980\_14-segment-testing.ino:1:0:
FontMap14Segment.h:5: error: 'B0001100001111110' was not declared in this scope
B0001100001111110, // 0 0
#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 displayPointer = 0; // for interrupt use...
unsigned char buffer1[4]; //2x8 bits
unsigned char 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
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);
//digitalWrite(latchPin ,HIGH);
//digitalWrite(latchPin , LOW ); // STORECLOCK
if (++displayPointer == 4) //4 because there are two digits, each need 2x8 bits
{ displayPointer = 0;
} // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
void setcolumn(unsigned char col) //loop that takes care of column scanning
{
signed char pos;
for (pos =8; pos > -1; pos--) //was pos=32, but again, only 4 columns now so pos=4
{
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 char dat) {
unsigned char pos;
for (pos = 0; pos < 16; pos++)
{
if (dat & 32768) //these dat were 128, but changed them to 16 as 16=128/8
{
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
{
int addr;
for (addr = 0; addr < 4; addr++) // Empty display buffer, reduced from 32 to 4
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 < 4; addr ++) //here also changed 32 to 4
{
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 > 1 || y > 15) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data
if (cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if (cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}
void charput(unsigned char ch, signed char x, signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
disp = font[ch]; //look data from fontmap,
Serial.println(disp/256, BIN);
Serial.println(disp & 0xFF, BIN);
for (y1 = 0; y1 < 16; y1++) // eight pixels
{
disp2 = disp & power[y1];
if (disp2 > 0)
{
pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
}
}
}
/*
void strput(const char* ch, signed char x, signed char y)
{
int addr;
while (*ch )
{
charput(*ch++, x, y); // write a string to the display buffer
x += 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;
clr();
charput(5, 0, 0);
Blit()
}
The flicker I mean is overall refresh rate; it's smaller when ISR rate is decreased->refresh rate increases so it's "normal" flicker. At OCR1A value 100 it's barely noticeable. But screen shows nothing like in post 336, only segments that are controlled fromn second shifter are lit. YES we are using 14 segment, but I tried to hook up 7 segment to matrix as daisy chained, as it too used 8-bit values, and I ahve working code for both 7-segment as well as matrix. If we run out of memory we can use teensy, I found solution how interrupts can be used with it and tested with matrix scrolling text+real time FFT, took about 40% of program storage and 25% RAM. So the final project in any way is some-digit 7-segment, OLED 128x32 that shows FFT and matrx that scrolls some random text, perhaps "good morning" and stuff like that.post 347 should display 1 pixel at a time, should... ...pls elaborate of flickering, do you mean just like in your post 336? also i edited post 347, pls retry
wait, i thought we were using 14 seg... pls post new schematic if you have them all hooked up, may as well hook up vu meter too if that is what you want to do, also vu datasheet/partno required, we may need to be careful here, since i recall we were short on memory using the 32x8 fontmap alone...
void loop() //just sitting here
{
int val = millis()/1000 % 10;
clr();
charput(val, 0, 0);
Blit();
}
#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 char 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 (xa=0;xa<14;xa++){
clr();
pixel(xa,0,0 );
Blit();
delay(500);
}
for (xa=0;xa<14;xa++){
clr();
pixel(xa,1,0 );
Blit();
delay(500);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?