• AVR Freaks

Hot!Displaying handing;

Author
AMPS
Super Member
  • Total Posts : 516
  • Reward points : 0
  • Status: offline
2020/02/18 02:36:22 (permalink)
0

Displaying handing;

I have code which is finally worked for 4mhz external crystal, 1ms timer interrupt.using PIC16F886
 
I have 2 issue in code:
1)if i assign value Top_Display=0123; display shows 0083 for some of the value it shows properly.
2)in this type of case it print 0100 in bottom and stop.
3)Msec to sec conversion is not doing properly. 
 

#include <htc.h>
#include <stdio.h>
#include <math.h>
#include "delay.h"
#define _XTAL_FREQ 4000000

__CONFIG(FOSC_HS & WDTE_ON& PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_OFF&MCLRE_ON &BOREN_ON&FCMEN_ON &WRT_OFF);
#define DISPCLK RB5
#define DISPDATA RB6
#define STROBE RB7

unsigned int Hour=0;
unsigned int Min=0;
unsigned int Sec=0;
unsigned int MSec=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];
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


void PRG_RUN_RESET() {
 Bottom_Value=0;
 Sec=0;
 Hour=0;
 Min=0;
 MSec=0;

}

void Process_RUN_MODE() {

 Top_Display=0123;

 LED_MS=0;

 Key_CHK_RESET();

 if(LED_MS==0) {
  LED_SS=1;
  LED_HM=1;
  Dissect(Top_Display);
  Dissect_2(Bottom_Value);

 } else if(LED_HM==0) {
  LED_MS=1;
  LED_SS=1;
  Dissect(Top_Display);
  Dissect_2(Bottom_Value);
 } else if(LED_SS==0) {
  LED_MS=1;
  LED_HM=1;
  Dissect(Top_Display);
  Dissect_2(Bottom_Value);
 }

}


void main(void) {

 while(1) {
  Process_RUN_MODE();
 }
}

void interrupt isr(void) {

 asm("clrwdt");

 if (TMR1IF) {
  TMR1IF = 0;
  TMR1H = 0xFE;
  TMR1L = 0x0C;// timer interrupt for 1ms
  if(Top_Display>Bottom_Value) {
   if(LED_SS==0) {
    Bottom_Value=(Sec*100)+MSec;
   } else if(LED_MS==0) {
    Bottom_Value=(Min*100)+Sec;
   } else if(LED_HM==0) {
    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();
 }

}

post edited by AMPS - 2020/02/21 23:42:00

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#1

11 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2766
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: Displaying handing; 2020/02/18 04:13:07 (permalink)
    +2 (2)
    Numerical constants with leading zeroes are interpreted as octal. Octal 123 == decimal 83.
    #2
    AMPS
    Super Member
    • Total Posts : 516
    • Reward points : 0
    • Status: offline
    Re: Displaying handing; 2020/02/20 22:41:41 (permalink)
    0
     
    Numerical constants with leading zeroes are interpreted as octal. Octal 123 == decimal 83.
     
    What i need to do overcome this issue. ??? 
     
    unsigned char LEDBuffer_1[8];// buffer will display related parameter
    DISPTABLE[X] will have the character to be displayed.
    const unsigned char DISPTABLE[27] = {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
    };
    Display will show 0123 if argument is like this. For this condition how can i combine to form digit & save. i tried saving but it wont do proper conversion.

    unsigned int Converted_Value = 0;
    j=0;k=1;l=2;m=3
    LEDBuffer_1[0] = DISPTABLE[j];
    LEDBuffer_1[1] = DISPTABLE[k];
    LEDBuffer_1[2] = DISPTABLE[l];
    LEDBuffer_1[3] = DISPTABLE[m];
    Converted_Value = LEDBuffer_1[0] * 1000 + LEDBuffer_1[1] * 100 + LEDBuffer_1[2] * 10 + LEDBuffer_1[3] * 1;

     
     

    Amps
    *.*.*.*.*.*.*.*.*.*.*.*.*
    #3
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Displaying handing; 2020/02/20 23:48:16 (permalink)
    +2 (2)
    Let me ask you something. How did you get these values to start with?
    j=0;k=1;l=2;m=3

     
    Edit: I would never used the letter 'l' as a variable; it looks too much like the digit '1'.
    post edited by 1and0 - 2020/02/20 23:50:20
    #4
    LdB_ECM
    Super Member
    • Total Posts : 297
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Displaying handing; 2020/02/21 06:27:37 (permalink)
    +1 (1)
    Its just 4 byte BCD, you had the right idea but its easier with a struct.
     
    The struct
    typedef struct
    {
        uint8_t thousands;
        uint8_t hundreds;
        uint8_t tens;
        uint8_t ones;
    } BCD_4BYTE;

     
    The conversion I have ignored speed but it does the job
    BCD_4BYTE BCDfromNumber(uint16_t num)
    {
        BCD_4BYTE retVal;
        retVal.ones = num % 10;
        retVal.tens = (num / 10) % 10;
        retVal.hundreds = (num / 100) % 10;
        retVal.thousands = (num / 1000) % 10;
        return retVal;
    }

     
    An example of use
    BCD_4BYTE abc = BCDfromNumber(123);

     
    #5
    AMPS
    Super Member
    • Total Posts : 516
    • Reward points : 0
    • Status: offline
    Re: Displaying handing; 2020/02/21 22:53:15 (permalink)
    0
    Edit: I would never used the letter 'l' as a variable; it looks too much like the digit '1'.
     
    I am just giving an example  how i am displaying the value.
    Assume passed argument is j=0;k=1;l=2;m=3;
    In this case display shows 0123 
    Now i would like to combine to form a integer no which can be used further for calculation.
    i.e 0123 means 01 Min  23S  . my question here to form digit and save it in variable.

    if (Blink_Count == 1) {
    BLINKSEGMENT = 6;
    BLINKFLAG = 1;
    LEDBuffer_1[0] = DISPTABLE[j];
    LEDBuffer_1[1] = DISPTABLE[k];
    LEDBuffer_1[2] = DISPTABLE[l];
    LEDBuffer_1[3] = DISPTABLE[m];
    Converted_Value = LEDBuffer_1[0] * 1000 + LEDBuffer_1[1] * 100 + LEDBuffer_1[2] * 10 + LEDBuffer_1[3] * 1;
    }


    Amps
    *.*.*.*.*.*.*.*.*.*.*.*.*
    #6
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Displaying handing; 2020/02/21 23:54:55 (permalink)
    0
    ajitnayak87
    Assume passed argument is j=0;k=1;l=2;m=3;
    In this case display shows 0123 
    Now i would like to combine to form a integer no which can be used further for calculation.
    i.e 0123 means 01 Min  23S  . my question here to form digit and save it in variable.

     
    LEDBuffer_1[0] = DISPTABLE[j];
    LEDBuffer_1[1] = DISPTABLE[k];
    LEDBuffer_1[2] = DISPTABLE[l];
    LEDBuffer_1[3] = DISPTABLE[m];
    Converted_Value = LEDBuffer_1[0] * 1000 + LEDBuffer_1[1] * 100 + LEDBuffer_1[2] * 10 + LEDBuffer_1[3] * 1;


    What value do you want "Converted_Value" to have here?  As I understand it, LEDBuffer_1[] contains the values of the displayed LED segments; do you think that will give you the value you want?
    #7
    AMPS
    Super Member
    • Total Posts : 516
    • Reward points : 0
    • Status: offline
    Re: Displaying handing; 2020/02/22 00:13:14 (permalink)
    0
    My question is how to form converted value in this case. Since LEDBuffer_1[] will have displayed led segment.
     
     

    Amps
    *.*.*.*.*.*.*.*.*.*.*.*.*
    #8
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Displaying handing; 2020/02/22 03:42:36 (permalink)
    +1 (1)
    ajitnayak87
    My question is how to form converted value in this case. Since LEDBuffer_1[] will have displayed led segment.

     
    And my questions are in my previous post. How to form a converted value depends on what value do you want?
     
    If you want "Converted_Value" to have a value of 123, then it is child's play:
    Converted_Value = 1000 * j + 100 * k + 10 * l + m;

     
    If you want "Converted_Value" to have a value of seconds, then it's also easily accomplished:
    Converted_Value = 600 * j + 60 * k + 10 * l + m;

     
    If you want "Converted_Value" to have a packed BCD value, then it is a piece of cake:
    Converted_Value = j << 12 | k << 8 | l << 4 | m;

     
    A walk in the park ... ;)
     
     
    post edited by 1and0 - 2020/02/22 04:19:57
    #9
    pcbbc
    Super Member
    • Total Posts : 1631
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: Displaying handing; 2020/02/23 09:18:19 (permalink)
    0
    AMPNow i would like to combine to form a integer no which can be used further for calculation.
    i.e 0123 means 01 Min  23S  . my question here to form digit and save it in variable.

    You can do this, but the structure of your whole program would seem wrong if you think you need to.  Internally within your program this value will already be stored in a variable somewhere. As an integer number of whole seconds for example.
     
    Your conversion should only need to happen one way, from integer to decimal digits for display. If you are manipulating the decimal digits (other than translating digits to illuminated LCD segments) you are going about the problem all crabbed. You’re also likely to get tied up in knots as to which set of values are the “master” set of data, and which are just temporary copies.
     
    Just manipulate the original integer value, e.g. add or subtract one to increase or decrease by a second, or add or subtract 60 to increase or decrease by one minute, etc. Then re-do the conversion from integer to decimal to update the display.
    #10
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Displaying handing; 2020/02/23 13:10:28 (permalink)
    0
    pcbbc
    You can do this, but the structure of your whole program would seem wrong if you think you need to.  Internally within your program this value will already be stored in a variable somewhere. As an integer number of whole seconds for example.

     
    Hence my question in Post #4:  "How did you get these values to start with?"
     
    #11
    pcbbc
    Super Member
    • Total Posts : 1631
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: Displaying handing; 2020/02/23 16:29:22 (permalink)
    0
    1and0Hence my question in Post #4:  "How did you get these values to start with?"

    Indeed, but I think your subtle hint may have been a little lost on the OP...
    Hence their “it’s just an example“ reply?
    #12
    Jump to:
    © 2020 APG vNext Commercial Version 4.5