Wrtite number on a LCD

Status
Not open for further replies.

radialspel

New Member
Hi!

I have made a project with a pic16f84 there i have a variable called TEMP and it can be 0 to 100 (it is a temperature). If the variable for example is 74, is it possible to split the numbers to 7 and 4 or how can i do to show the temperature on the LCD-Display??? I have made the program in CC5X C-Compiler
 
Its kind of a cheat but if your using a byte to hold your variable you could do this.

variable var byte
temp var byte
lsd_digit var byte
msd_digit var byte

seperate:
temp = variable
if temp > 10 then
msd_digit = msd_digit + 1
temp = temp - 10
goto seperate
endif
if temp > 0 then
lsd_digit = lsd_digit + 1
temp = temp - 1
goto sperate
endif
return

Just remember to set lsd and msd to 0 before testing for them by calling the seperate function, Id call it as a gosub so execution continues from where it's called from. Msd will contain the variables multiple of 10(example 9 = 90) and lsd the variables 0-9 component.
 
Code:
char Hund, Tens, Ones;

     Hund = 0;
     Tens = 0;
     Ones = 0;     //Reset our variables

     if (Temp == 100)    //if it is 100 then ...
          Hund++;        //increase Hund to 1
     else 
          {              //and end... or, if it wasn't 100 then...
              while (Temp > 9)          //keep looping as long as Temp is bigger then 9
              {
                     Temp = Temp - 10;  //subtract 10 from temp ...
                     Tens++;            //and add one to Tens
              }
              Ones = Temp;  //when done the 'ones' remain in temp.
          }

The contents of Temp are destroyed by this code...
Code like this is better then using multiplations and divisions because a pic is much better at simply adding and subtracting
it only works up too 100 like you said, bigger values will output incorrect results
 
Aye that's why I used variable as the main holder and temp is well a temporary storage. Temp will always be 0 at the end of a call to seperate

Nice code though, much more optimized then what I posted. Also I should have assigned the value to temp outside of the seperation loop, as it is atm any value over 10 will be stuck in a continous loop since temp is assigned on each call.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…