Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] extraction of digits in pic assembly

Status
Not open for further replies.

charu2539211

Junior Member level 3
Joined
Jul 22, 2013
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
200
Hi all

I am doing a project and i have a value stored in the memory location. I need to extract the hundred, tenth and unit digit so that i can display them on three seven segment display individually....

usually we do this ( here i am taking the value to be 250 for example)

250%10= 0(unit digit)
250/10= 25 (qotient)
25/10=2 (hundredth digit)
25%10=5 (tenth digit)

so now i have to implement this in pic assembly for any value i have stored in a particular memory loaction . I am using p16f887 and mpasm assembler.

any ideas would be of great help.
 

It depends on how the numbers are stored in memory. For example, if it is stored as text or BCD you only have to use a small look-up table per digit, if it is binary you need to do some processing first because it will be in base 16 (hexadecimal) rather than decimal.

Are you converting a single byte (value 0 - 255) or does it have to be 0 - 999 ?

Brian.
 

It has to be 0-999

It is stored in hexadecimal in memory. have to display the corresponding decimal value.
 

Value is stored as binary in the variable. 0x01, 1, 0b00000001 are all same. What is your problem? You want to display value one as '1' on LCD? If yes, you have to convert each digit to character and display it. To do that you need to add 48 or 0x30 to the value.

0x01 + 48 = '1'
 

No. Adding decimal 48 (ascii zero) will convert it to an ascii digit, this application uses a 7-segment display so a look-up table is the best solution.

I suggest you use code from the Piclist web site:

to split the number into hundreds, tens and units then use a small look-up table to convert them into segment patterns for each digit.

Brian.
 

Brian-
let's say i have a value in hex -0f0 stored in my memory. if i split the each digit individiually then i ll get 0,f and 0 sepaerately. if i refer each of these to a lookup table, f will have a value 15 right??
how do u suggest i display that...?
and also 0f0 in decimal is 240 which is the value i want to actually display....

how do u think i should proceed now???
 

Extract each digit of 240 and add 48 to each digit and display it. Finally '2' '4' '0' will be displayed.

0xF0/100 + 48 is same as 240/100 + 48
 

Jayanth, you are right if the digit starts at 0x240 but the problem states 0x0F0. 240 is the decimal representation of it but not the value the OP is starting with. In any case, adding 48 will make it ASCII and they are asking for 7-segment.

The simplest way is to make three variables, you can call them anything you like but here I'll use H, T and U for Hundreds, Tens and Units. These will hold the decimal conversion of the hex number.
1. Take the original number and see how many time you can subtract D'100' from it until the result is less than D'100'. This gives you the H value.
2. From what is left, see how many times you can subtract D'10' before the result is less than D'10', this gives you the T value.
3. The remainder is the U value.
4. Take each of these in turn and use the value as an index to a look-up table containing the 7-segment patterns.

Brian.
 

jayanth- if i do it ur way i get only the ASCII value. i cant use it.

- - - Updated - - -

Brian- i tried it the way u said. it worked.

thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top