Oct182009

8x8 Dot Matrix Digital Clock using AT89S51

This project displays a clock over a 8x8 dot matrix display. The AT89S51 microcontroller is used and the software timer is used for the clock function.

You can also download the proteus simulation file of this project.

Circuit Diagram:

8x8-dot-matrix-clock

How to operate:

  • The Mode button is used to change the clock to edit mode for changing the Hour & Minutes
  • Press the Up botton to change the Hour/Minute

Program:

/*8x8 Dot matrix clock*/
#include <REGX51.H>
#include <intrins.h>
unsigned char timecount=0,oldP1=0xff,setting=0;
unsigned char sec=0,min=0,hou=12;
sbit  SET=P2^2;  
sbit  UP=P2^4;
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code dis_code[40]={0x07c,0x082,0x082,0x07c,0x000,0x084,0x0fe,0x080, //0 and 1
                                 0x0c4,0x0a2,0x092,0x08c,0x044,0x082,0x092,0x06c, //2 and 3
                                 0x078,0x044,0x0fe,0x040,0x04e,0x08a,0x08a,0x072, //4 and 5
                                 0x07c,0x092,0x092,0x064,0x006,0x002,0x0f2,0x00e, //6 and 7
                                 0x06c,0x092,0x092,0x06c,0x04c,0x092,0x092,0x07c, //8 and 9
                                
                                };

bit    set_old;
bit up_old;
bit    date_flag=1;
void time50ms(void);
void delay2ms(void);
void timedeal(void);

void main(void)
{
unsigned char offset=0,dis_p,scantimes=0;
unsigned char xian,disnum,x,y;    
    IE=0x82;     //Enable interrupts
    TMOD=0x01;   //timer0 in mode 1
    TR0=1;       //start timer
    TH0 = 0x3c;
    TL0 = 0x0b;
    do
    {
        if(setting==0){   //display clock
        for(x=0;x<8;x++){
            dis_p=x+offset;
            if(dis_p>26)
                dis_p-=27;
            if(dis_p==0 || dis_p==5 || dis_p==10 || dis_p==12 || dis_p==17 || dis_p>21){    //row
                y=0;
            }else if(dis_p<=4){                    
                xian=hou/10;
                if(xian>0)
                    y=dis_code[xian*4+dis_p-1];
                else
                    y=0;
             }else if(dis_p<=9){            
                 xian=hou%10;
                y=dis_code[xian*4+dis_p-6];
             }else if(dis_p==11){                
                 if(date_flag)
                    y=0x24;
                else
                    y=0;
             }else if(dis_p<=16){                
                 xian=min/10;
                y=dis_code[xian*4+dis_p-13];
             }else{                                
                 xian=min%10;
                y=dis_code[xian*4+dis_p-18];
             }
            P0=0;
            P1=tab[x];
             P0=y;
            delay2ms();
            
        }
        scantimes++;
        if(scantimes>=8){
            scantimes=0;
            offset++;
            if(offset>26)
                offset=0;
        }}
          else{            //display time to change
                for(x=0;x<8;x++)
                {
                if(setting==1)
                    disnum=min;
                else
                    disnum=hou;
            
                if(x<4)                    
                {     xian=disnum/10;
                     y=dis_code[xian*4+x];     }
                else 
                 {        
                    xian=disnum%10;    
                    y=dis_code[xian*4+x-4];     
                     
                }
                    
                P0=0;
                P1=tab[x];
                P0=y;
                delay2ms();
            }
        
        }
    }while(1);
    
}

void delay2ms(void)
{
    unsigned char i,j;
    for(i=0;i<4;i++)
        for(j=0;j<120;j++);
}


void time50ms(void) interrupt 1
{
    TH0 = 0x3c;
    TL0 = 0x0b;
    timecount++;
    if(timecount==10)
    {
        timecount=0;
        date_flag=!date_flag;
        if(date_flag)
        {
            sec++;
            timedeal();
        }

    }

    if(!SET && SET!=set_old)    //check the set key
    {
        setting++;
        if(setting==3)
            setting=0;
    }

    if(!UP && UP!=up_old)   //check the up key
        {
            if(setting==1)
            {
                min++;
                sec=0;
                timedeal();
            }else if(setting==2)
            {
                hou++;
                timedeal();
            }
         }
    set_old=SET;
    up_old=UP;

}

void timedeal(void)
{
    if(sec>=60)
    {
        sec=0;
        min++;
    }
    if(min>=60)
    {
        min=0;
        hou++;
    }
    if(hou>=24)
        hou=0;
}                                                                          

 

Download the code from here: 8x8-dot-matrix-clock.zip (30.72 kb)


Tags: , , , , ,

E-mail | Permalink | Trackback | Post RSSRSS comment feed tweet this 9 Responses

Comments


basil

Response by basil on 10/19/2009 8:45:43 AM

well i appreciate the project but can you please tell me how would you display hours and minutes on the same 8x8 matrix?.. secondly can u send me its assembly code?...it would b very kind of you.
THANK YOU




binu

Response by binu on 10/19/2009 9:10:56 PM

The time will scroll over the 8x8 dot matrix display.




Mohammed Shahid

Response by Mohammed Shahid on 10/20/2009 6:16:15 AM

well !,i appreciate the project but can you please tell me how would you display hours and minutes on the same 8x8 matrix?.. secondly can u send me its assembly code?...it would b very kind of you.iam willing to purchase this project.
THANK YOU




AUGUSTINE DANJA LAUFUN

Response by AUGUSTINE DANJA LAUFUN on 12/15/2009 2:09:23 AM

Iam an undergraduate student in my final year.I want to design and contruct 4-digit clock with a decimal point using 8051 microcontroller or processor.I need circuit diagram and guid for implementation of project.




intan

Response by intan on 12/15/2009 6:15:55 PM

good idea....but...how to altough use dotmatrix 8x8 10 chracter




Hazwer

Response by Hazwer on 12/31/2009 12:02:19 PM

Please can you send me the coding in assembly language i would be thankful.




kashif

Response by kashif on 1/27/2010 9:28:39 PM

sir can u tell me that i use which kind of lcd screen i mean what mumber.




syafirah

Response by syafirah on 4/29/2010 10:57:54 PM

how to make a program to greeting form..??? can u tell me..? it,s use 5x7.. help me....




ishak

Response by ishak on 5/9/2010 8:06:49 AM

hello

ı want to asm code..
please help



Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading