Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/29/07 21:04
Read: times


 
#147604 - use register as a pointer to a table
Responding to: ???'s previous message
Ali Shaheen said:

hi,
i have interfaced keypad with 8051.i want to store 3 digit number (0-999) . and then display it on three, 7-segment displays.
can anyone help me how to solve this problem.can i use stack to store digits..? and how can i convert a digit to binary code to send to 7.segment to display that digit.
:(



First of all, most 7-segment displays actually have eight segments, as there's usually a decimal point in addition to the segments a..g, so it's really A..G and DP.

Secondly, the obvious way to do this is to use a table lookup.

Whatever the correspondence between your 7-segment layout and the port that drives them, you can lay it out however you like and use a table to store the representation of each value that you wish to display. The translation can be quite arbitrary, so it can take the code from your keypad directly and translate it for you, or it can translate the scan code returned by your keypad scanning routine into a hexadecimal or decimal digit first.

You can keep the translation table in code space, pointed to by the data pointer (DPTR) and indexed with the content in A (Check the MCU datasheet for the instruction set, and that will show you which instructions you could use for that and how they will work.) That will convert ASCII, your scan code, the BCD value, or whatever else you use, into the 7 segment code byte, with the segment bits arranged however you like. You can store the ASCII, or whatever, code, the one that needs to be translated, in a RAM location, and point to it with, say, R1 (If you've studied the instruction set, you know that R0 and R1 are convenient index registers for indirect access to on-chip read/write memory). Since you must store those locations in RAM, you point to them with, say, R1, and then simply increment R1 to fetch the next value. At the same time that you increment the pointer to the value to be displayed, you can increment the digit select so that, assuming you're multiplexing your digits, you select the next digit on the display at the same time that you select the value to be displayed.

That way you don't risk messing up your stack.

Now, you can use the stack, but then you have to retain a pointer to the portion of the stack that you use for that purpose. That may prove to be a mite cumbersome. Try picking out the instructions with which you'd do that ... you'll see what I mean.

MCU instruction sets typically contain instructions handy for table lookup. That's what you should use in this case, I believe.

This does, BTW, look like a homework assignment, and should take you no more than 10 minutes to figure out, once you've read through and understood the MCU datasheet and instruction set.

RE

List of 25 messages in thread
TopicAuthorDate
how to use buffer or stack to store digits            01/01/70 00:00      
   many question            01/01/70 00:00      
   Stack            01/01/70 00:00      
   use register as a pointer to a table            01/01/70 00:00      
      How many segments?            01/01/70 00:00      
         you seldom need to use both ...            01/01/70 00:00      
            Not as DP, but...            01/01/70 00:00      
               sorry ... double post            01/01/70 00:00      
               Why would you want those?            01/01/70 00:00      
                  example            01/01/70 00:00      
      Timer interrupt and segments in RAM            01/01/70 00:00      
         many words about two lousy microseconds            01/01/70 00:00      
            Lousy microseconds            01/01/70 00:00      
               Wholehardely agree            01/01/70 00:00      
                  Burning stack bytes            01/01/70 00:00      
                     you need to read "the bible"            01/01/70 00:00      
                        Not entirely true            01/01/70 00:00      
                     Table lookup in 'C'            01/01/70 00:00      
                        Why tables can be costly on C            01/01/70 00:00      
                           Well, If you abuse the tools...            01/01/70 00:00      
                           if we consider this off topic, you may be correct            01/01/70 00:00      
                              Not even then?            01/01/70 00:00      
                                 Another thread, please            01/01/70 00:00      
                                    And the new thread is...            01/01/70 00:00      
   Example on driving 7-segment displays            01/01/70 00:00      

Back to Subject List