This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I have slightly corrected the code for Digital clock program using AT892051

#include <AT892051.H>
#include <stdio.h>
#include <intrins.h>



sbit DigitShiftregisterSerialPin=P1^0;                    /* Character to be transfered through thisbit in parallel*/
sbit DigitShiftregisterClockPin=P1^1;                     /* Clock*/
sbit DigitShiftregisterLatchPin=P1^2;                     /* Latch*/
/*sbit DriveMinutes=P1^3;       /* 1st 7-segment Display*/
/*sbit DriveTensMinutes=P1^4;    /* 2nd 7-segment Display*/
/*sbit DriveHours=P1^5;         /* 3rd 7-segment Display*/
sbit DriveTensHours=P1^6;      /* 4th 7-segment Display*/


unsigned char SevenSegmentData;
unsigned char _crol_(unsigned char Temp,unsigned char SevenSegmentData);
char Display_Buffer[1];
int Dispcount;
int mscount;


int Hours=1;
int Minutes=0;
int Seconds=0;

char Temp;

code unsigned char DecimalToSevenSegment[11]=
{
0xEE,0x28,0xCD,0x6C,0x2B,0x67,0xE7,0x2C,0xEF,0x2F
};


void main()
{

 TMOD=0x01;
 TH0=0xF8; /* Initializing timer0 for 1ms*/
 TL0=0x30;
 IE=0x82;
 TR0=1;



do
{

sprintf(Display_Buffer,"%02d%02d",Hours); /* converting integer into character*/

}while(1);

}



void Timer0(void) interrupt 1 /* ISR begins*/
{
    TF0=0;
        TR0=0;
        TH0=0xF8;
        TL0=0x30;
        TR0=1;

  {
                                                /* To transfer bits into byte from port pin onto the shift register*/
                Dispcount++;            /* Dispcount is used to refresh the Hours and Minutes on the LED*/
                mscount++;          /* Generate 1ms Delay*/
        if(++mscount>=1000)
                {
                        mscount=0;
                        Seconds++;


                }
        if(++Seconds>=60)
                {
                        Seconds=0;
                        Minutes++;


                }
    if(++Minutes>=60)
                {
                        Minutes=0;
                        Hours++;


                }
      if(++Hours>=13)
                {
                Hours=1;

                }
   }

// For DriveTensHours LED

{
        int i,j;
          if(Dispcount==29)   /* This code is for refresh rate of DriveTensHours*/
            {
          /*    DriveMinutes=0;
                                DriveTensMinutes=0;
                            DriveHours=0;        */
                DriveTensHours=0;


                        }
                if(Dispcount==30)
                        {
                     if(j<=1)
                                {
                                SevenSegmentData=DecimalToSevenSegment[Display_Buffer[j]-0x30];


                              if(8>i)                  /* For a byte to be read by the port pin*/
                                        {

                                        if (Dispcount==32)
                                                {
                                                                Temp=SevenSegmentData;
                                                }
                                        if (Dispcount==34)
                                                {
                                                        DigitShiftregisterClockPin=1;   /* clock is set high*/
                                                                                                                        /*}*

                                                                                                                        /*if (Dispcount==36)*/
                                                                                                                        /*{*/
                                                DigitShiftregisterSerialPin=Temp^7; /* Taking MSB one at a time, the loop continous till all 8-bits are sent to the portpin*/
                                                                                                                        /*      }
                                                                                                                        if (Dispcount==38)
                                                                                                                        {*/
                                                        DigitShiftregisterClockPin=0; /*clock is made low*/
                                                }
                                        if (Dispcount==40)
                                                {
                                                        SevenSegmentData=_crol_(Temp,1); /* bits are rotated left*/
                                                }
                       DigitShiftregisterLatchPin=0;        /* Data is Latched*/
                                        }


                if(Display_Buffer[0])
                        {
                        DriveTensHours=1;

                        }
}

}
}
}

0