0
\$\begingroup\$

I have actually 2 issue in code.

1) variable declaration. I have declare variable unsigned int Top_Display=0; if assign Top_Display=0123 display shows 0083 if assign Top_Display=123 display shows 0123 Some of the variable it take properly and some are not. if i assign value Top_Display=0129 it gives error digit is out of range.

2)i have created 1ms timer interrupt . every 1ms i am increment msec . i am getting wrong calculation for displaying Msec to sec. other paramter it showing well. somewhere the conversion is affected

1S=1000ms 60S=1Min 60M=1H

      unsigned char LED_MS_Flag=0;
    unsigned char LED_SeMi_Flag=0;
    unsigned char LED_HM_Flag=0;
unsigned char Main_Flag=0;
unsigned char j=0;
 int Bottom_Value=0;
 unsigned int Top_Display=0;
unsigned int Float_Value;
unsigned int InG_value;
unsigned char LEDBuffer_1[8];

unsigned int Hour=0;
unsigned int Min=0;
unsigned int Sec=0;
unsigned int MSec=0;
const unsigned char DISPTABLE[28] = {0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09,0x11,0x83,0x31,
                                      //0  //1  //2  //3  //4  //5  //6  //7  //8  //9  //A  //U  //P
                                     0xD1,0xE3,0x89,0x63,0xE1,0xF5,0xC1,0x61,0x71,0xF3,0xFD,0xD5,0x85,0xFF,0X43};
                                      //h  //L  //Y  //C  //t  //r  //b   //E //F  //I  //-  //n //d  //blank //G
unsigned char Blink_Count=1;
unsigned char Converted_Value;
unsigned int Top_Value=0;
unsigned char EEPROM_Write_Flag=0;

unsigned char EEPROM_Read_Flag=1;
unsigned int Result;

void Process_RUN_MODE() {
    if(EEPROM_Read_Flag==1) {
        //READ_EPROM();
        EEPROM_Read_Flag=0;
    }
    Top_Display=(int)1123;

    LED_MS_Flag=1;
    if(LED_MS_Flag==1) {

        LED_HM_Flag=0;//min_Hour Flag
        LED_SeMi_Flag=0;// Sec & min FLag
        LED_MS=1;
        LED_SS=0;
        LED_HM=1;
        Dissect(Top_Display);
        DelayMs(10);
        Dissect_2(Bottom_Value);
    } else if(LED_HM_Flag==1) {
        LED_SeMi_Flag=0;//sec & min flag
        LED_MS_Flag=0;//Sec_ms Flag
        LED_HM=0;
        LED_MS=1;
        LED_SS=1;
        Dissect(Top_Display);
        Dissect_2(Bottom_Value);
    } else if(LED_SeMi_Flag==1) {
        LED_HM_Flag=0;//min_Hour Flag
        LED_MS_Flag=0;
        LED_SS=1;
        LED_MS=0;
        LED_HM=1;
        Dissect(Top_Display);
        Dissect_2(Bottom_Value);
    }

}

void interrupt isr(void) {

    asm("clrwdt");

    if (TMR1IF) {
        TMR1IF = 0;
        //  TMR1H = 0x3C;
        //  TMR1L = 0xB0;100ms

        TMR1H = 0xFE;
        TMR1L = 0x0C;// timer interrupt for 1ms
        if(Top_Display>Bottom_Value) {
            if(LED_MS_Flag==1) {
                Bottom_Value=(Sec*100)+MSec;
            } else if(LED_SeMi_Flag==1) {
                Bottom_Value=(Min*100)+Sec;
            } else if(LED_HM_Flag==1) {
                Bottom_Value=(Hour*100)+Min;
            }

        } else if(Top_Display==Bottom_Value) {

        }
        MSec++;
        if(MSec>1000) {
            MSec=0;
            Sec=Sec+1;
        }
        if(Sec>=59) {
            Sec=0;
            Min=Min+1;
        }
        if(Min>=59) {
            Min=0;
            Hour=Hour+1;
        }
        if(Hour>99) {
            Hour=0;
        }
        Display();
    }

}





} 
Void main()
 {

  while(1)
   {
Process_RUN_MODE();
  }

}

void Dissect_2(unsigned int Value)              // Spliting of process value in digits form
 {
    unsigned char a,Temp;
    for(a = 4;a >= 1 ; a--)
    {

     Temp = Value%10;
     Value = Value/10;
     LEDBuffer_1[a-1] = DISPTABLE[Temp];    

    }

 }

void Dissect(unsigned int Value)            // Spliting of process value in digits form
 {
    unsigned char a,Temp;

    for(a = 8;a >= 5 ; a--)
    {
     Temp = Value%10;
     Value = Value/10;
     LEDBuffer_1[a-1] = DISPTABLE[Temp];    

    }

 }
\$\endgroup\$
3
  • \$\begingroup\$ unsigned int b = Top_Display / 100; unsigned int c = Top_Display - b*100; and then b and c are your two split variables. \$\endgroup\$
    – jonk
    Feb 18, 2020 at 3:51
  • 1
    \$\begingroup\$ I'm voting to close this question as off-topic because the fact that the target is a microcontroller has no bearing on the fact it's a pure programming question. \$\endgroup\$
    – Matt Young
    Feb 18, 2020 at 4:16
  • \$\begingroup\$ Here is my code. Top Display shows Set value and Bottom Display shows process value. I have variable Msec, Sec,Min,Hour which is independently running.now bottom value should display Min and sec increment. My question how to split and display bottom one \$\endgroup\$
    – Ajit
    Feb 18, 2020 at 5:20

2 Answers 2

3
\$\begingroup\$

1) variable declaration. I have declare variable unsigned int Top_Display=0; if assign Top_Display=0123 display shows 0083 if assign Top_Display=123 display shows 0123 Some of the variable it take properly and some are not. if i assign value Top_Display=0129 it gives error digit is out of range.

In C and many other programming languages, leading zero indicates an octal number.

printf("%d\n", 010);

8

As there is no '8' or '9' in a well-formed octal number, you get an error at compile time. Your constant 0123 is decimal 83, and that's probably not what you wanted.

\$\endgroup\$
0
\$\begingroup\$

Here 1234 variable used for timing application.Assume 1234 where 12 M and 34 Sec. Can some one suggest me how to do it.

    void main()
    {
      unsigned int min,sec,Top_Display=1234;

       min = Top_Display/100; 
       sec = Top_Display%100;

    }
// Assumptions: it willalways be a 4 digit number/valid number/
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.