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.
#include <Wire.h>
#include "FontMap.h"

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


const int DS1307 = 0x68; // Address of DS1307 see data sheets

byte second = 0;
byte minute = 0;
byte hour = 0;



unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,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);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
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 ++)
{
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)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) 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;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; 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+=7;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

void setup() //setup runs once
{
signed char cntr;
unsigned char timeout = 0;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
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


clr();
charput(58,1,-1);
Blit();
delay(1000);

Wire.begin();

charput(58,2,0);
Blit();
delay(1000);
Serial.begin(9600);

clr();
charput(58,3,1);
Blit();
delay(1000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();

clr();
charput(58,4,2);
Blit();
delay(1000);
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available() & timeout < 54){ delay(20);timeout++;

clr();
charput(58,5,3);
Blit();

}
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

while(1){
clr();
charput(58,0,0);
Blit();
delay(300);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}}
 
nNthing much changed, only those first leds are lit but nothing moving is happening.
 
hmm... (to be clear, in post 200, 3 columns are lit up) if only 2 columns are lit up then the hang is happening at:

Serial.begin(9600);

not sure what would cause this, is the ds 1307 hooked up proper? and have you tried the source code from the link provided on this current hardware?
maybe we need to include:
#include <Serial.h> //or something like that
but that wasn't on sample code
 
only other thing i can think if this will fix maybe , all or nothin!:

#include <Wire.h>
#include "FontMap.h"

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


const int DS1307 = 0x68; // Address of DS1307 see data sheets

byte second = 0;
byte minute = 0;
byte hour = 0;



unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,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);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
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 ++)
{
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)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) 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;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; 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+=7;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

void setup() //setup runs once
{
signed char cntr;
unsigned char timeout = 0;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt



clr();
charput(58,1,-1);
Blit();
delay(1000);

Wire.begin();

charput(58,2,0);
Blit();
delay(1000);
Serial.begin(9600);

clr();
charput(58,3,1);
Blit();
delay(1000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();

clr();
charput(58,4,2);
Blit();
delay(1000);
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available() & timeout < 54){ delay(20);timeout++;

clr();
charput(58,5,3);
Blit();

}
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");

interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

while(1){
clr();
charput(58,0,0);
Blit();
delay(300);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}}
 
RTC should be hooked correctly, as I can read time out of it. Sadly, in your previous code, no change :(
 
I can set time manually, automatically read from computer and read time without setting it :)
 
but how? is it wired through Adruino to pc, or seperate plug to pc, are you accessing it on a com port, or special software?
if u are seeing this code it should be asking these questions:

Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");

if so what is the last thing it says? (thank-you)?
 
I used arduino IDE as serial port software
 
Why don't you use the RTC library for the DS1307? Is it missing functionality that you require. I've used it in a scheduling sketch using an Arduino Uno or Mega... I haven't read all 12 pages, so perhaps I've missed your reasoning or requirements.

Now that I think of it, I had the same problem with Serial.begin. It was the order that I initialized the peripherals and on the Mega, powering the DS1307 through digital pins did not work (would cause lock ups). This technique worked on the Uno but not the Mega. What pins are the DS1307 connected to?
 
Pins are A4 & A5 from pro mini, never had earlier any trouble with DS1307, this is first time
 
I'd expect A4 and A5 to work. After all, they're the seal data and serial clock pins (SDA & SCO).

But how are you powering the module. That's where I ran into problems. The example for the Uno shows using digital pins powering the module, but that didn't work for me on the Mega.
 
I power RTC directly from vcc & GND rails from pro mini
 
No, I haven't yet tried RTC library, might be well worth shot!
 
pro mini is what you use for led matrix rite?
I would suggest to check by uploading original code from inscrutable to see if it works then.. im suspicious that its my code
 
Yes doggy, pro mini is under use now and setting time with that 'ible works like charm! But, even it's RTC sketch, there isn't libraby used in there either
 
k, lets try again! hopefully i made enough room for memory


Code:
#include <Wire.h>
#include "FontMap.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;


const int DS1307 = 0x68; // Address of DS1307 see data sheets

// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {
Serial.print("Please enter the current year, 00-99. - ");
year = readByte();
Serial.println(year);
Serial.print("Please enter the current month, 1-12. - ");
month = readByte();
Serial.println(month);
Serial.print("Please enter the current day of the month, 1-31. - ");
monthday = readByte();
Serial.println(monthday);
Serial.println("Please enter the current day of the week, 1-7.");
Serial.print("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
weekday = readByte();
Serial.println(weekday]);
Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekday));
Wire.write(decToBcd(monthday));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();
Serial.print(weekday);
Serial.print(" ");
Serial.print(month);
Serial.print(" ");
Serial.print(monthday);
Serial.print(", 20");
Serial.print(year);
Serial.print(" ");
if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,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);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
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 ++)
{
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)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) 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;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; 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+=7;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

void setup() //setup runs once
{
signed char cntr;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt


Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();


interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
Last edited:
Please use code tags when listing code. Otherwise, it makes scrolling difficult. Replace the {} with [] in the following example.
start with {code} or {code=C}, list your program and end with {/code}
Code:
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
See how it works?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top