Dot Matrix Clock

You can also build the clock by using the latest versions of the required files by downloading the special package after a 10$ donation. The files can only be used for education-hobby – non commercial purposes.

The package includes:

1- Reciprocating clock source code together with compiled HEX and other supporting files.

2- Sliding clock source codes together with compiled HEX and other supporting files.

3- Labcenter Proteus 8.10 simulation project file that also includes the circuit schematic.

4- Improved STL files for the product case for 3d printing.

5- Wider digits for improved reading of the clock data.

Here is the puchase link for the file package.

Your contribution will be used for paying the hosting fees of our site. Thank you for your support. The standard code is freely available below.

#include <12f683.h> 
#fuses intrc_io,noput,nowdt,noprotect,nomclr,nobrownout,noieso,nofcmen 
#device adc=8
#use delay(clock=8M) 
//#use fast_io(b)  
//#use spi(do=pin_b0,clk=pin_b2,bits=16,load_active=1,load=pin_b1,idle=1, STREAM=disp11 ) 
//#use spi(do=pin_b0,clk=pin_b2,bits=16,load_active=1,load=pin_b3,idle=1, STREAM=disp12) 
#use spi(do=pin_a0,clk=pin_a1,bits=16,load_active=1,load=pin_a2,idle=1, STREAM=disp21) 
//#use spi(do=pin_a0,clk=pin_a1,bits=16,load_active=1,load=pin_a4,idle=1, STREAM=disp22) 
//We have to write this directive, you can add stream and change the pin do, clk, load  
//I've used bits 16 'cause max7219 needs 16 bits =) 
//The idle is 1, if you put 0, nothing will appear on your displays <- this is really important 
#define TONE_PIN pin_a4
#include "ds1307.c"  
int sec, min, hrs=100, day, month, yr, dow;
int address, data; 
int16 digit[16];                     //address, data max's variables
                                    //adqnum for 100 samples 
                                    //digit[4] this array keeps 4 digits used in this project 
int16 packetmax;                    //packetmax goes to the max7219 
                                    //result keeps the value used to obtain digits 
 
int16 timescan;
//int1 timescandiv;
int shiftval=8;
int shiftinc=-1;
int al1sounded=0;
int al2sounded=0;
//-------------------------------------
void beep(int16 period){
   while((period--) != 0)
   {
      output_high(TONE_PIN);
      delay_ms(1);
      output_low(TONE_PIN);
      delay_ms(1);
   }
}
//-------------------------------------
void maxsend(){             //routine for max7219 just 
   packetmax=make16(address,data);   //make a 16 bit variable address byte high, data byte low 
   spi_xfer( disp21 , packetmax);  

}                                    //just 5 lines including #use spi. It's really simple right? 


void maxsetup(){                            //configure properly 
   address=0x09, data=0x00, maxsend();      // decode mode
   address=0x0a, data=0x06, maxsend();      // intensity
   address=0x0b, data=0x07, maxsend();      // Scan Limit
   address=0x0f, data=0x00, maxsend();      // Test 
   address=0x0c, data=0x01, maxsend();      // Shutdown mode 1 normal
}

void putpixel(int x, int y, int color){
   if(x>15 || y>15) return;
if (color==1) bit_set(digit[y],x+1);
else          bit_clear(digit[y],x+1);
}  

void cls0(){ 
   digit[0] =0b0000000000000000;
   digit[1] =0b0111111000000000;
   digit[2] =0b0100001000000000;
   digit[3] =0b0101101000000000;
   digit[4] =0b0101101000000000;
   digit[5] =0b0100001000000000;
   digit[6] =0b0111111000000000;
   digit[7] =0b0000000000000000;
} 

void cls(){ 
   digit[0] =0b0000000000000000;
   digit[1] =0b0000000000000000;
   digit[2] =0b0000000000000000;
   digit[3] =0b0000000000000000;
   digit[4] =0b0000000000000000;
   digit[5] =0b0000000000000000;
   digit[6] =0b0000000000000000;
   digit[7] =0b0000000000000000;
} 

reversebyte(unsigned char data)
{
    unsigned char k = 0, rev = 0;

    unsigned char n = data;

    while(n)

    {
        k = n & (~(n - 1));
        n &= (n - 1);
        rev |= (128 / k);
    }
    return rev;
}


void ekrantazele0(){
      address=0x01, data=reversebyte(digit[0]>>8), maxsend(); 
      address=0x02, data=reversebyte(digit[1]>>8), maxsend(); 
      address=0x03, data=reversebyte(digit[2]>>8), maxsend(); 
      address=0x04, data=reversebyte(digit[3]>>8), maxsend(); 
      address=0x05, data=reversebyte(digit[4]>>8), maxsend();
      address=0x06, data=reversebyte(digit[5]>>8), maxsend();
      address=0x07, data=reversebyte(digit[6]>>8), maxsend();
      address=0x08, data=reversebyte(digit[7]>>8), maxsend();          
}

void ekrantazele(int colshift){
      address=0x01, data=reversebyte(digit[0]>>colshift), maxsend(); 
      address=0x02, data=reversebyte(digit[1]>>colshift), maxsend(); 
      address=0x03, data=reversebyte(digit[2]>>colshift), maxsend(); 
      address=0x04, data=reversebyte(digit[3]>>colshift), maxsend(); 
      address=0x05, data=reversebyte(digit[4]>>colshift), maxsend();
      address=0x06, data=reversebyte(digit[5]>>colshift), maxsend();
      address=0x07, data=reversebyte(digit[6]>>colshift), maxsend();
      address=0x08, data=reversebyte(digit[7]>>colshift), maxsend();          
}

// glcd_line(x0,y0, x1,y1, c) puts line from (x0, y0) to (x1, y1) with c color 
//#separate 
void glcd_line(signed int16 x0, signed int16 y0, 
               signed int16 x1, signed int16 y1 ){ 
   int16 x; 
   int16 y; 
   int i;
   unsigned int16 n; 
   int1 m_case; 
    
   x=abs(x1-x0); 
   y=abs(y1-y0); 
    
   if (y > x){ 
      n=(y1-y0); 
      m_case=1; 
   } else { 
      n=(x1-x0); 
      m_case=0; 
   } 
   for(i=0 ; i<=n ; i++){ 
      if (m_case){ 
         y=i + y0; 
         x=(y*(x1-x0))/(y1-y0) + x0; 
      } else { 
         x=i + x0; 
         y=(x*(y1-y0))/(x1-x0) + y0; 
      } 
      putpixel(x, y, 1); 
   } 
                          
} 

//----------------------------------
void basu(int basx){
   putpixel(basx, 0, 1);
   putpixel(basx, 1, 1);
   putpixel(basx, 2, 1);
   putpixel(basx, 3, 1);
}
//----------------------------------
void basa(int basx){
   putpixel(basx, 4, 1);
   putpixel(basx, 5, 1);
   putpixel(basx, 6, 1);
   putpixel(basx, 7, 1);
}
//----------------------------------
void basno(int numx, int number){
         switch( number ) {
         case 0 : 
                  basu( numx );
                  basa( numx );
                  basu( numx+1 );
                  basa( numx+1 );
         break;
         case 1 : 
                  putpixel(numx,1,1);   
                  basu( numx+1 );
                  basa( numx+1 );
         break;
         case 2 : 
                  putpixel(numx,0,1);
                  basu( numx+1 );
                  basa( numx   );
                  putpixel(numx+1,7,1);
                  putpixel(numx,3,1); 
         break;
         case 3 : 
                  putpixel(numx,0,1);   
                  basu( numx+1 );
                  putpixel(numx,3,1);
                  basa( numx+1 );
                  putpixel(numx,7,1);
         break;
         case 4 : 
                  putpixel(numx+1,2,1); 
                  putpixel(numx+1,3,1); 
                  basu( numx );
                  basa( numx+1 );
         break;
         case 5 : 
                  putpixel(numx+1,0,1); 
                  basu( numx );
                  basa( numx+1 );
                  putpixel(numx,7,1);
                  putpixel(numx+1,3,1); 
         break;
         case 6 : 
                  putpixel(numx+1,0,1); 
                  putpixel(numx+1,3,1); 
                  basu( numx );
                  basa( numx );
                  basa( numx+1 );
                  //putpixel(numx,0,0); 
         break;
         case 7 : 
                  putpixel(numx,0,1);
                  basu( numx+1 );
                  basa( numx+1 );
         break;
         case 8 : putpixel(numx  ,0,1);
                  putpixel(numx+1,0,1);
                  putpixel(numx  ,1,1);
                  putpixel(numx+1,1,1);
                  putpixel(numx  ,2,1);
                  putpixel(numx+1,2,1);
                  basa( numx );
                  basa( numx+1 );
         break;
         case 9 : 
                  basu( numx );
                  basu( numx+1 );
                  basa( numx+1 );
                  putpixel(numx  ,7,1);
         break;
         }
}
//----------------------------------
void yazsaat(signed int sayi){
int yuzler=0, onlar=0, birler=0;

  while(sayi >= 100) {
      sayi -=100;
      yuzler++;
  }
  while(sayi >= 10) {
      sayi -=10;
      onlar++;
  }
birler = sayi;


   /*if( yuzler!= 0) {
     basno(0,yuzler);
     basno(3,onlar);
   }
   else if(onlar!=0) basno(3,onlar);
   basno(6,birler);*/
   
   if(onlar!=0) basno(0,onlar);
   basno(3,birler);
   
   putpixel(6,2,1);
   putpixel(6,5,1); 
   putpixel(7,2,1);
   putpixel(7,5,1);    
}
//----------------------------------
void yazdakika(signed int sayi){
int yuzler=0, onlar=0, birler=0;

  while(sayi >= 100) {
      sayi -=100;
      yuzler++;
  }
  while(sayi >= 10) {
      sayi -=10;
      onlar++;
  }
birler = sayi;

   /*if( yuzler!= 0) {
      basno(8,yuzler);
      basno(11,onlar);
   }
   else if(onlar!=0) basno(11,onlar);
   basno(14,birler);*/
   if(onlar!=0) basno(9,onlar);
   basno(12,birler);
   
   /*putpixel(1,2,1);
   putpixel(0,2,1);
   putpixel(1,5,1);
   putpixel(0,5,1);*/
}
//----------------------------------

void main(){ 

   //unsigned int xval,yval,xana,yana;
   //int depox, depoy;
   
   //signed int xcoord,ycoord,xart,yart;

   //int eskisec;
   
   setup_comparator(nc_nc_nc_nc);         //no comparator module 
   //setup_adc(adc_clock_internal);         //Tad = 4.0us 
   //setup_adc_ports(sAN0 | sAN1);         //gpio4 as analog input, u can choose your favorite pin 
   SETUP_ADC(ADC_OFF);
   //set_tris_b(0b11000000);               //set port 
   delay_ms(100);                     //wait just for relaxing =), this line is not that important 
   maxsetup();                        // 
   delay_ms(100);  
   ds1307_init(); 
   
   ds1307_get_date(day,month,yr,dow); 
   
   cls();
//ekrantazele(12);
   beep(10); 
   /*
   putpixel(0,0,1);
   putpixel(7,0,1);
   putpixel(0,7,1);
   putpixel(7,7,1);
   ekrantazele(0);
   while(TRUE){ 
   }*/
   
   while(TRUE){ 
   
   /*if(timescan == 0) {  
      //timescan = 15000;
      ds1307_get_time(hrs,min,sec);
      cls();
      //if(sec % 2 == 0) putpixel(0,0,1);
      //else putpixel(0,7,1);
      yazsaat(hrs);
      //yazdakika(min);
      ekrantazele(8);
   }   */
   
   if(timescan == 0) {  
      //timescan=20000;
      ds1307_get_time(hrs,min,sec);
      cls();

      yazsaat(hrs);
      yazdakika(min);
      ekrantazele(shiftval);
   
      shiftval = shiftval + shiftinc;
      if(shiftval == 0) shiftinc= 1; 
      if(shiftval >= 8) shiftinc=-1;

      if(min==30){
         if (al1sounded == 0) 
         {
            beep(5); 
            al1sounded=1;  
         }
      }
      else al1sounded=0;
      
      if(min==0) {
         if (al2sounded == 0) 
         {
            beep(5); 
            delay_ms(200);
            beep(5); 
            al2sounded=1;  
         }
      }
      else al2sounded=0;
   }   
//if(timescandiv-- == 0) timescan--;
timescan--;
  
   if(input(pin_a3) == 0){
      beep(4);
      while(input(pin_a3) == 0);
      hrs++;
      if(hrs==24)hrs=0;
      sec=0;
      ds1307_set_date_time(day, month, yr, dow, hrs, min, sec);
      timescan=65000;
      shiftval = 0;
      shiftinc=1;
      
      cls();
      yazsaat(hrs);
      yazdakika(min);
      ekrantazele(shiftval);
   }
   if(input(pin_a5) == 0){
      beep(4);
      while(input(pin_a5) == 0);
      min++;
      if(min==60)min=0;
      sec=0;
      ds1307_set_date_time(day, month, yr, dow, hrs, min, sec);
      timescan=65000;
      shiftval = 8;
      shiftinc=-1;
      
      cls();
      yazsaat(hrs);
      yazdakika(min);      
      ekrantazele(shiftval);
   }
   }  
} 


//////////////////////////////////////////////////////////////////////////////// 
///                               DS1307.C                                   /// 
///                     Driver for Real Time Clock                           /// 
///                                                                          /// 
/// ds1307_init() - Enable oscillator without clearing the seconds register -/// 
///                 used when PIC loses power and DS1307 run from 3V BAT     /// 
///               - Disable squarewave output                                /// 
///                                                                          /// 
/// ds1307_set_date_time(day,mth,year,dow,hour,min,sec)  Set the date/time   /// 
///                                                                          /// 
/// ds1307_get_date(day,mth,year,dow)               Get the date             /// 
///                                                                          /// 
/// ds1307_get_time(hr,min,sec)                     Get the time             /// 
///                                                                          /// 
//////////////////////////////////////////////////////////////////////////////// 

#define RTC_SDA  PIN_A0
#define RTC_SCL  PIN_A1

#use i2c(master, sda=RTC_SDA, scl=RTC_SCL) 

BYTE bin2bcd(BYTE binary_value); 
BYTE bcd2bin(BYTE bcd_value); 

void ds1307_init(void) 
{ 
   BYTE seconds = 0; 

   i2c_start(); 
   i2c_write(0xD0);      // WR to RTC 
   i2c_write(0x00);      // REG 0 
   i2c_start(); 
   i2c_write(0xD1);      // RD from RTC 
   seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307 
   i2c_stop(); 
   seconds &= 0x7F; 

   delay_us(3); 

   i2c_start(); 
   i2c_write(0xD0);      // WR to RTC 
   i2c_write(0x00);      // REG 0 
   i2c_write(bin2bcd(seconds));     // Start oscillator with current "seconds value 
   i2c_start(); 
   i2c_write(0xD0);      // WR to RTC 
   i2c_write(0x07);      // Control Register 
   i2c_write(0x80);     // Disable squarewave output pin 
   i2c_stop(); 

} 

void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec) 
{ 
  sec &= 0x7F; 
  hr &= 0x3F; 

  i2c_start(); 
  i2c_write(0xD0);            // I2C write address 
  i2c_write(0x00);            // Start at REG 0 - Seconds 
  i2c_write(bin2bcd(sec));      // REG 0 
  i2c_write(bin2bcd(min));      // REG 1 
  i2c_write(bin2bcd(hr));      // REG 2 
  i2c_write(bin2bcd(dow));      // REG 3 
  i2c_write(bin2bcd(day));      // REG 4 
  i2c_write(bin2bcd(mth));      // REG 5 
  i2c_write(bin2bcd(year));      // REG 6 
  i2c_write(0x80);            // REG 7 - Disable squarewave output pin 
  i2c_stop(); 
} 

void ds1307_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow) 
{ 
  i2c_start(); 
  i2c_write(0xD0); 
  i2c_write(0x03);            // Start at REG 3 - Day of week 
  i2c_start(); 
  i2c_write(0xD1); 
  dow  = bcd2bin(i2c_read() & 0x7f);   // REG 3 
  day  = bcd2bin(i2c_read() & 0x3f);   // REG 4 
  mth  = bcd2bin(i2c_read() & 0x1f);   // REG 5 
  year = bcd2bin(i2c_read(0));            // REG 6 
  i2c_stop(); 
} 

void ds1307_get_time(BYTE &hr, BYTE &min, BYTE &sec) 
{ 
  i2c_start(); 
  i2c_write(0xD0); 
  i2c_write(0x00);            // Start at REG 0 - Seconds 
  i2c_start(); 
  i2c_write(0xD1); 
  sec = bcd2bin(i2c_read() & 0x7f); 
  min = bcd2bin(i2c_read() & 0x7f); 
  hr  = bcd2bin(i2c_read(0) & 0x3f); 
  i2c_stop(); 

} 

BYTE bin2bcd(BYTE binary_value) 
{ 
  BYTE temp; 
  BYTE retval; 

  temp = binary_value; 
  retval = 0; 

  while(TRUE) 
  { 
    // Get the tens digit by doing multiple subtraction 
    // of 10 from the binary value. 
    if(temp >= 10) 
    { 
      temp -= 10; 
      retval += 0x10; 
    } 
    else // Get the ones digit by adding the remainder. 
    { 
      retval += temp; 
      break; 
    } 
  } 

  return(retval); 
} 


// Input range - 00 to 99. 
BYTE bcd2bin(BYTE bcd_value) 
{ 
  BYTE temp; 

  temp = bcd_value; 
  // Shifting upper digit right by 1 is same as multiplying by 8. 
  temp >>= 1; 
  // Isolate the bits for the upper digit. 
  temp &= 0x78; 

  // Now return: (Tens * 8) + (Tens * 2) + Ones 

  return(temp + (temp >> 2) + (bcd_value & 0x0f)); 
} 
Pages: 1 2 3 4 5

Comments are closed.

indian porn sexnxxx.cc xvideos Amateur Porn video porno amatoriali filmeporno.top lupoporno film porno gratuit porno mature xnxx film porno gratuit
bisexuel gay porno gay porno video porno देसी सेक्स एचडी पॉर्न ऊपर ऊपर से चुदाई Големи цици only fans free porn videos filme porno gratis