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 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);
}
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);
}
}
#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);
}
}
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);
}
}
}
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
}
#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);
}
}
}
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
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
}
#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);
}
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?