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

Digital clock program using AT892051

Hi, I'm writing a code for digital clock in Keil C, but I'm not getting the expected results. Can anybody please help me with the program? The code is as follows..

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

sbit PIN_P10=P1^0;/* Character to be transfered through this bit in parallel*/
sbit PIN_P11=P1^1;/* Clock*/
sbit PIN_P12=P1^2;/* Latch*/
sbit CS4=P1^3; /* 1st 7-segment Display*/
sbit CS3=P1^4; /* 2nd 7-segment Display*/
sbit CS2=P1^5; /* 3rd 7-segment Display*/
sbit CS1=P1^6; /* 4th 7-segment Display*/

unsigned char DataWrite;
unsigned char _crol_(unsigned char Temp,unsigned char DataWrite);
char Display_Buffer[6];
unsigned char Dispcount;
unsigned char mscount;

int Hours=1;
int Minutes=0;
int Seconds=0;
int i=0;
char Temp;

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

void main()
{

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

do
{

sprintf(Display_Buffer,"%02d%02d",Hours,Minutes); /* converting int into char*/

}while(1);

}

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

{ mscount++; Dispcount++; if(mscount>=1000) { mscount=0; Seconds++; } if(Seconds>=59) { Seconds=0; Minutes++; } if(Minutes>=59) { Minutes=0; Hours++; } if(Hours>=12) { Hours=1; }
}

{ if(Dispcount==29) /* This code is for refresh rate*/ { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==30) {

DataWrite=Lookup[Display_Buffer[0]-0x30];

}

if(8>i) { i++; if (Dispcount==34) { Temp=DataWrite; } if (Dispcount==32) { PIN_P11=1; }

if (Dispcount==36) { PIN_P10=Temp^7; } if (Dispcount==38) { PIN_P11=0; } if (Dispcount==40) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0;

if(Dispcount==48) { CS1=1; }
}

{ if(Dispcount==49) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==50) {

DataWrite=Lookup[Display_Buffer[1]-0x30];

}

{

if(8>i)

{ i++; if (Dispcount==54) { Temp=DataWrite; } if (Dispcount==52) { PIN_P11=1; }

if (Dispcount==56) { PIN_P10=Temp^7; } if (Dispcount==58) { PIN_P11=0; } if (Dispcount==60) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==68) { CS2=1; }
}

{ if(Dispcount==69) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==70) {

DataWrite=Lookup[Display_Buffer[2]-0x30];

}

{

if(8>i) { i++; if (Dispcount==74) { Temp=DataWrite; } if (Dispcount==72) { PIN_P11=1; }

if (Dispcount==76) { PIN_P10=Temp^7; } if (Dispcount==78) { PIN_P11=0; } if (Dispcount==80) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==88) { CS3=1; }
}

{ if(Dispcount==89) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==90) {

DataWrite=Lookup[Display_Buffer[3]-0x30];

}

{

if(8>i) { i++; if (Dispcount==94) { Temp=DataWrite; } if (Dispcount==92) { PIN_P11=1; }

if (Dispcount==96) { PIN_P10=Temp^7; } if (Dispcount==98) { PIN_P11=0; } if (Dispcount==100) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==108) { CS4=1; }
}

if(Dispcount==821) { CS1,CS2,CS3,CS4=0;

}
} RETI;

Parents
  • sbit PIN_P10=P1^0; /* Character to be transfered through thisbit in parallel*/
    sbit PIN_P11=P1^1; /* Clock*/
    sbit PIN_P12=P1^2; /* Latch*/
    sbit DriveMinutes=P1^3; /* 1st 7-segment Display*/
    sbit DriveTenMinutes=P1^4; /* 2nd 7-segment Display*/
    sbit DriveHours=P1^5; /* 3rd 7-segment Display*/
    sbit DriveTenHours=P1^6; /* 4th 7-segment Display*/

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

    int Hours=1;
    int Minutes=0;
    int Seconds=0;
    int i=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,Minutes); /* converting integer into character*/
    
    }while(1);
    
    }
    
    
    
    void Timer0(void) interrupt 1 /* ISR begins*/
    {
        TF0=0;
            TR0=0;
            TH0=0xF8;
            TL0=0x30;
            TR0=1;
    
      {
                    i++;
                    Dispcount++;            /* Dispcount is used to refresh the Hours and Minutes on the LED*/
                    mscount++;
            if(++mscount>=1000)
                    {
                            mscount=0;
                            Seconds++;
    
    
                    }
            if(++Seconds>=59)
                    {
                            Seconds=0;
                            Minutes++;
                            Seconds++;
    
                    }
        if(++Minutes>=59)
                    {
                            Minutes=0;
                            Hours++;
                            Seconds++;
                            Minutes++;
    
                    }
          if(++Hours>=12)
                    {
                    Hours=1;
                            Seconds++;
                            Minutes++;
                            Hours++;
                    }
       }
    
    // For DriveHours LED
    
    {
              if(Dispcount==29)   /* This code is for refresh rate of LED1*/
                {
                    DriveMinutes=0;
                                    DriveTenMinutes=0;
                                DriveHours=0;
                    DriveTenHours=0;
    
    
                            }
                    if(Dispcount==30)
                            {
    
                            SevenSegmentData=DecimalToSevenSegment[Display_Buffer[0]-0x30];
    
                            }
    
    
    
                                  if(8>++i)                         /* For a byte to be read by the port pin*/
                                            {
    
                                            if (Dispcount==32)
                                                    {
                                                                    Temp=SevenSegmentData;
                                                    }
                                            if (Dispcount==34)
                                                    {
                                                            PIN_P11=1;   /* clock is set high*/
                                                    }
    
                                            if (Dispcount==36)
                                                    {
                                                            PIN_P10=Temp^7; /* Taking MSB one at a time, the loop continous till all 8-bits are sent to the portpin*/
                                                    }
                                            if (Dispcount==38)
                                                    {
                                                            PIN_P11=0; /*clock is made low*/
                                                    }
                                            if (Dispcount==40)
                                                    {
                                                            SevenSegmentData=_crol_(Temp,1); /* bits are rotated left*/
                                                    }
                           PIN_P12=0;
                                            }
    
    
                    if(Dispcount==48)
                            {
                            DriveTenHours=1;
    
                            }
    }
    

Reply
  • sbit PIN_P10=P1^0; /* Character to be transfered through thisbit in parallel*/
    sbit PIN_P11=P1^1; /* Clock*/
    sbit PIN_P12=P1^2; /* Latch*/
    sbit DriveMinutes=P1^3; /* 1st 7-segment Display*/
    sbit DriveTenMinutes=P1^4; /* 2nd 7-segment Display*/
    sbit DriveHours=P1^5; /* 3rd 7-segment Display*/
    sbit DriveTenHours=P1^6; /* 4th 7-segment Display*/

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

    int Hours=1;
    int Minutes=0;
    int Seconds=0;
    int i=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,Minutes); /* converting integer into character*/
    
    }while(1);
    
    }
    
    
    
    void Timer0(void) interrupt 1 /* ISR begins*/
    {
        TF0=0;
            TR0=0;
            TH0=0xF8;
            TL0=0x30;
            TR0=1;
    
      {
                    i++;
                    Dispcount++;            /* Dispcount is used to refresh the Hours and Minutes on the LED*/
                    mscount++;
            if(++mscount>=1000)
                    {
                            mscount=0;
                            Seconds++;
    
    
                    }
            if(++Seconds>=59)
                    {
                            Seconds=0;
                            Minutes++;
                            Seconds++;
    
                    }
        if(++Minutes>=59)
                    {
                            Minutes=0;
                            Hours++;
                            Seconds++;
                            Minutes++;
    
                    }
          if(++Hours>=12)
                    {
                    Hours=1;
                            Seconds++;
                            Minutes++;
                            Hours++;
                    }
       }
    
    // For DriveHours LED
    
    {
              if(Dispcount==29)   /* This code is for refresh rate of LED1*/
                {
                    DriveMinutes=0;
                                    DriveTenMinutes=0;
                                DriveHours=0;
                    DriveTenHours=0;
    
    
                            }
                    if(Dispcount==30)
                            {
    
                            SevenSegmentData=DecimalToSevenSegment[Display_Buffer[0]-0x30];
    
                            }
    
    
    
                                  if(8>++i)                         /* For a byte to be read by the port pin*/
                                            {
    
                                            if (Dispcount==32)
                                                    {
                                                                    Temp=SevenSegmentData;
                                                    }
                                            if (Dispcount==34)
                                                    {
                                                            PIN_P11=1;   /* clock is set high*/
                                                    }
    
                                            if (Dispcount==36)
                                                    {
                                                            PIN_P10=Temp^7; /* Taking MSB one at a time, the loop continous till all 8-bits are sent to the portpin*/
                                                    }
                                            if (Dispcount==38)
                                                    {
                                                            PIN_P11=0; /*clock is made low*/
                                                    }
                                            if (Dispcount==40)
                                                    {
                                                            SevenSegmentData=_crol_(Temp,1); /* bits are rotated left*/
                                                    }
                           PIN_P12=0;
                                            }
    
    
                    if(Dispcount==48)
                            {
                            DriveTenHours=1;
    
                            }
    }
    

Children
  • Are you reading anything we post here? Anything at all?

    Still off-by-one error for your time variables. How will the clock ever show 59 for seconds if you reset it at 59?

    Still stepping seconds and minutes and hours every ms.

    Still random indents - your "if (8 > 8)" has same logic indent level as "if (Dispcount == 29)". Doesn't look like that in your code - are you mixing tabs and spaces?

    Still no logic that takes care of "i" when it reaches 8. And "i" may be an acceptable temp name for a locally used loop variable - you have "i" as a global variable that is processed in by a state machine. So why isn't it named BitPosition or something?

    And you tick "i" outside the state machine that needs multiple steps to process a single bit - how do you think the state machine can work if you reverse inside and outside of the loop?

    By the way - you still claim "the loop continous till all 8-bits are sent to the portpin". Maybe you should describe exactly what you think your look like. It does not look like you think it does, unless it was your intention to have a broken "loop".

    Why do you think you need both a SevenSegmentData and a Temp? What is Temp storing that can't be stored in SevenSegmentData?

    PIN_P11=1;   /* clock is set high*/
    


    Why do you have a variable name that requires you to write a comment to tell that the clock is set high? Wouldn't it have been better to define the variable so the name had told the function? Why not:

    DigitShiftregisterClockPin = 1;
    


    This would also allow you to redesign the hw and move the signal to another processor pin without renaming a variable all over the code.

    You still haven't come back with an explanation why you think you need 2ms between each pin toggle - does that really correspond with the hardware requirements? Isn't the shift register capable of running at many MHz, having all times specified in ns and not in ms? Do you need a huge state machine for emitting the 8 bits of a digit?

    And you haven't given any feedback why you think you should update the display every 256ms (which is the speed Dispcount will turn around if an 8-bit variable. Remember that you are only displaying hours and minutes. You don't even seem to have a colon flashing every second. Wouldn't it be enough if the output state machine is only run the first time, and every time the clock has been changed, and every time the minute counter has been changed? If the minute counter hasn't changed - what change do you want to emit to the 7-segment digits?

    Why use the magic constant 0x30 if you want to subtract the offset of the ASCII character '0'? Didn't you think it was better to write '0'? Did you have to look at an ASCII table to figure out the numeric value of '0'?

    C has an operator for bit shift. Not an operator for bit rotate. Any reason why you need to rotate the data?

    Look at the following code:

    SevenSegmentData=DecimalToSevenSegment[Display_Buffer[0]-0x30];
    


    Why can't you use a state machine that steps through the digit positions 0..3 and then reuse the same code for emitting the data? How much code does it take to figure out the bitmap combination for the four select lines based on a DigitPosition variable that steps 0..3?

    How about you spending a full day walking through all the information you have received in this thread and rewrite the code based on the suggestions? Just reposting the code with microscopic changes between each post will not take you to a working solution this year. If you fix _at most_ 1 bug every post and have 100 bugs, it will take a huge number of posts to get to the finish line...

    Another thing - why don't you think the variable declarations should be posted as code too?

  • Yes I'm reading your post in every minute detail. I did not understand the seconds, minutes, hours changing every ms. I'm using the mscount variable to increment it ecery 1ms which after counting 1000 will give me 1sec.

     if(++mscount>=1000)
    


    After i reaches 8, the DigitShiftregisterLatchPin will latch the byte data in the shift register.
    I don't know what a state machine is, can u please help me to know what a state machine is or how does it work?
    SevenSegmentData is a byte and I need to transfer it to the shift register using only a portpin, so I'm using the Temp variable to send it bit by bit. Doesn't C has rotate function? So what do I use instead of rotate. What command can be used for shifting a byte?
    The below is the modified code but only for Hours..

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

  • If that is true, then why are you not acting on what you read?

    Did you actually check how you code looks in the Preview?

    Do you think that is really clear and easy to read?

    Have you thought about that 'C' language construct for choosing one of many discrete values?

    etc, etc,...

  • Are you saying that you can't see that the variables "mscount" and "Seconds" are updated in two independant code blocks? Both blocks will be run on every call to the interrupts, so both variables will - independantly - be updated every millisecond.

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


    It really doesn't matter at what value you restart mscount, since the next if statement neither looks at mscount or is nested inside the previous if statement.

    Compare with:

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


    Notice any difference to the logic?

    But the question here - are you saying that your debugging of your code have not shon you this strange behaviour that mscount, seconds, minutes and hours are all getting updated like crazy? How could you have missed it?

    Another thing - do not write code with nested comments - don't assume that a compuler supports it.

    /* inside a comment
       /* inside nested comment */
       back to first comment.
    */
    


    Many compilers don't handle nested comments, so "back to first comment" may no longer be inside any comment at all. Your teacher has not told you that it is ok to use nested comments!

    And your state machine is still broken. If you only enter a code block when the state is 30, and the state isn't changed inside the code block, then you will never manage to run the statements that tests for state = 32.

    // For DriveTensHours LED
    /* ***** How can your comment claim "DriveTenHours LED"?
     * Is the LED named DriveTenHours? Strange name for a digit.
     * ***** Next thing - you have introduced a variable to index
     * which digit to pick up data for - why, if you claim that
     * the block is only for a single digit? If your comments
     * don't match the code, then your comments are lying.
     */
    {
        int i,j;
        if (Dispcount==29) {
            /* This code is for refresh rate of DriveTensHours*/
            /* *****
             * NO IT ISN'T - it is not for "refresh rate". The code isn't there
             * for the variable "DriveTenHours" but for handling the external
             * hardware associated with a specific digit of the clock. */
            /*    DriveMinutes=0;
                  DriveTensMinutes=0;
                  DriveHours=0;        */
            DriveTensHours=0;
        }
        if( Dispcount==30) {
            /* ***** How can you use the variable "j" when "j" has never been
             * receiving a value? Is your code intended to be some form of
             * random generator??? And exactly what is the meaning of:
             * "random uninitialized variable less than one"? You added the
             * test just for fun, or did you have any plan with it? Is this
             * random variable "j" ever expected to get any assign or change
             * in your code?
             */
            if (j<=1) {
                SevenSegmentData=DecimalToSevenSegment[Display_Buffer[j]-0x30];
                /* ***** Why do you so constantly think 0x30 is a good choice
                 * instead of '0' in above statement? You haven't motivated why
                 * you want to introduce "magic" constants in your code.
                 * ***** So "j" should now magically be the digit - but how
                 * can you have a state machine that updates the data during
                 * many calls of this interrupt, but keeping the state in a
                 * variable that gets thrown away between each interrupt tick?
                 * And who is stepping the "j" variable?
                 */
                if (8>i) { /* For a byte to be read by the port pin*/
                    /* ***** Yet another variable that hasn't received any
                     * value (was global before, so then zero-initialized).
                     * But when is this variable intended to change? And how
                     * is that change inter-related to the updating of Dispcount
                     * every millisecond?
                     */
                    if (Dispcount==32) {
                        /* ***** If you have already established a couple of
                         * lines above that you should only enter this section
                         * when Dispcount == 30 - how do you now suddenly think
                         * that Dispcount should have managed to change to 32?
                         * Your code is like: "If I have exactly 30 pounds in
                         * my picket, I'll take these 32 pounds and buy some
                         * thing for.
                         */
                        Temp=SevenSegmentData;
                    }
                    if (Dispcount==34) {
                        /* ***** Suddenly your 30 pounds in the pocket have
                         * managed to become 34 - how?
                         */
                        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) {
                        /* ***** And how could the 30 pounds in your pocket
                         * suddenly have become 40, without any action by
                         * you?
                         */
                        SevenSegmentData=_crol_(Temp,1); /* bits are rotated left*/
                    }
                    DigitShiftregisterLatchPin=0;        /* Data is Latched*/
                }
    
    
                if(Display_Buffer[0]) {
                    /* **** When is the above statement expected to not be true?
                     * What did you expect to accomplish? Will you? If sprintf()
                     * hasn't been run before the first timer interrupt: should
                     * you then even let the timer tick shift out any data?
                     * Think twice about your code to perform a lookup - what
                     * entry will you try to lookup?
                     */
                    DriveTensHours=1;
                }
            }
        }
    }
    

  • So - still no debugging from you.

    Still not thinking about - and trying to explain - how you think a variable can have multiple different values at the same time.

    Still not explained how you think your magic loop will handle "i" and "Dispcount" and have them step through everything exactly as many times as your hardware requires. If Dispcount steps up time once - how will you at the same time manage to step out 8 data bits to the shift register. And not only that - but to manage to do it once for every shift register?

    Still not looked at the datasheets and figured out why a chip with ns speed should be handled by a statemachine with ms delays. Have you even located the datasheets for the components? Can you even quote the timing figures?

    Still not [insert large number of other things you still haven't responded to, thought about, fixed, ...]

    Back to the beginning of this thread. Read the earlier comments yet again. Return with answers to the questions - posting new code with the same errors clearly shows that you have ignored the comments you have received.

    The comments are valid, and your code will remain buggy until you have an asnwer to every one of them. The compiler and processor don't care if you make more posts to this forum. Your hardware will not produce the correct output whatevery you post here, as long as you haven't closed all (!) open issues.

    The hardware doesn't have any "his thought was good" feature. It does what you instruct it to do. One single little error in your code and the hardware will behave according to that erroneous instruction. So details are vital. And you have clearly shown that you don't spend time bothering with details.

    If you were a tailor, then misfitting clothes would still be clothes. That mentality does not work with programming. No "almost correct".

    And how about indent with spaces? And make sure each indent is a fixed number of spaces, so the code blocks do align? Neither you nor we can read code that isn't properly indented. Many of the bugs are not evident without correct indenting, since the indenting is the visual way of showing interrelations between comparison operators and the code that is executed based on the result of the comparisons.

    And how come you always manages to get a couple of source code lines that are outside the code block?

  • I still did not come to know what a state machine is..
    Is the following a state machine?

    if(Dispcount==30)
            {
                     if(j<=4)
               {
                            j++;
                    SevenSegmentData=DecimalToSevenSegment[Display_Buffer[j]-'0'];
                    {
                                            Temp=SevenSegmentData;
                        DigitShiftregisterClockPin=1;
    
                         {
                                  if(8>=i)                                   /* For a byte to be read by the port pin*/
                            {
    
                                            i++;
                                        DigitShiftregisterSerialPin=Temp^7;
                                            DigitShiftregisterClockPin=0;       /*clock is made low*/
                                            SevenSegmentData=_crol_(Temp,1);    /* bits are rotated left*/
                                    }
                                      DigitShiftregisterLatchPin=0;             /* Data is Latched*/
                      }
                    }
    
               }
            }
    

  • You will never just "come to know" stuff - you need to put some effort into finding out:

    www.lmgtfy.com/

    Because we live in a finite world, practical applications are usually Finite State Machines - or "FSMs" for short:

    www.lmgtfy.com/

  • Thank you Mr. Neil for your valuable links.

  • #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[2];
    int Dispcount;
    int mscount;
    
    
    int Hours=0;
    int Minutes=0;
    int Seconds=0;
    
    char Temp;
    
    code unsigned char DecimalToSevenSegment[11]=
    {
    0xEE,0x28,0xCD,0x6C,0x2B,0x67,0xE7,0x2C,0xEF,0x2F
    };
    
    
    
    // Main function begins
    void main()
    {
    
     TMOD=0x01;
     TH0=0xF8; /* Initializing timer0 for 1ms*/
     TL0=0x30;
     IE=0x82;
     TR0=1;
    
    
    
    do
    {
    
    sprintf(Display_Buffer,"%02d%02d",Hours,Minutes); /* 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 LED's
    
    {
            int i=0,j=1;
              if(Dispcount==25)   /* This code is for refresh rate */
                {
                    DriveMinutes=0;
                                    DriveTensMinutes=0;
                                DriveHours=0;
                    DriveTensHours=0;
    
    
    
            if(Dispcount==30)
                    {
                     if(j<=4)
                     {
                            j++;
                    SevenSegmentData=DecimalToSevenSegment[Display_Buffer[4]-'0'];
                            {
                                            Temp=SevenSegmentData;
                        DigitShiftregisterClockPin=1;
    
                   {
                                  if(8>=i)                                   /* For a byte to be read by the port pin*/
                                            {
    
                                            i++;
                                        DigitShiftregisterSerialPin=Temp^7;
                                            DigitShiftregisterClockPin=0;       /*clock is made low*/
                                            SevenSegmentData=_crol_(Temp,1);    /* bits are rotated left*/
                                    }
                                      DigitShiftregisterLatchPin=0;             /* Data is Latched*/
                   }
                            }
    
              }
                    }
    }
    
            if (Dispcount==50)
                    {
                    if(Display_Buffer[1])
                            {
                            DriveTensHours=1;
    
                            }
         if(Display_Buffer[2])
                            {
                            DriveHours=1;
    
                            }
                    if(Display_Buffer[3])
                            {
                            DriveTensMinutes=1;
    
                            }
                    if(Display_Buffer[4])
                            {
                            DriveMinutes=1;
    
                            }
                      }
    
                    }
          }
      }
    

  •         TR0=1;
    
      {
    


    what is this '{' doing? sprefluous stuff is extremely confusing

    now that you finally have figured out to use pre, convert the tabs to spaces to make your code more legible

  • No reason to continue answering until he have made one single post showing that he is reading all we write - every new post seems to just be an attemt at fixing one single thing out of maybe 50 wrongs, and the changes seems to be trial-and-error. Change the code so it looks different and then post the changes.

    Now nested statements but no sign that indentation has changed.

    Still local loop variables in a block that doesn't contain a loop.

    Still nested code that relies on a variable being able to store two different values at the same time.

    Still out-of-bounds array accesses.

    Still too small target buffers.

    Still thinking that there can be magic end-of-string characters anywhere.

    Still thinking that logic capable of many MHz needs 2ms delays.

    Thinking C has one-based indices.

    Setting a lot of select lines but not clearing the other lines at the correct place.

    Still comments saying either someting meaningless or something directly wrong.

    Still having the main loop busy-loop widly most of the time redoing what it has already done - but no explanation why the main loop can't emit the time.

    Still a temporary variable without any explanation what it is needed for - why the other variable isn't good enough.

    Still a bit rotation when the data don't need to be rotated.

    Code performs xor where it should extract a single bit.

    Still no code even close to have been tested - possibly sent through the compiler.

    ...

    Exactly what does the comment "For LED's" tell a reader? That LEDs are involved? Yes, but what about them?

  • Everybody over here must have got the idea of what I'm tryin to do here, so can you please take out your time and write the code for me. I know how precious your time is. But I really need this project done. I will really appreciate your help. Thanx

  • Everybody over here must have got the idea of what I'm tryin to do here, so can you please take out your time and write the code for me

    http://www.keil.com/condb/search.asp

    Erik

  • Isn't the goal with school to learn?

    Or am I wrong - maybe the goal with school is to turn in other peoples jobs as your own?

    Are you a person with pride in your work, or someone who leeches others time and work? What kind of life do you want to live? Who do you want to be? Now is the time to decide if you should invest your time into programming or if you should switch to some other courses. A professional developer just can't ask someone else to do their job.

  • I came to that conclusion close to the start!