This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

.asm language

can any one help ! how do i display a number larger than 9 in a LCD screen using .asm language

Parents
  • How much larger?
    You can create a loop, and while your number is >= 10 you subtract 10 while incrementing a variable. If this variable is non-zero, then display it. Then display the remainder after of the subtractions.
    Starting with a loop subtracting while >= 100 will allow you to handle numbers 0..255.

    For large numbers, it can be better to do it the other way.

    Keep a set of counters for your digit positions.
    One for count of 10000.
    One for count of 1000.
    One for count of 100.
    One for count of 10.
    One for count of 1.

    Zero all counter variables.

    Keep second set of state variables for the different digit positions.

    Zero all but the ones variable that you set to 1.

    Check if lowest bit in number is set. In that case, add the state variables to the counter variables, while keeping track of carry.

    Double the number stored in the state variables, i.e. from 0 0 0 0 0 0 0 1 to 0 0 0 0 0 2.

    If next lowest bit in number is set, then add state variables to counter variables.

    Continue to double the state variables and check further bits in the number.

    This basically means that you are conditionally adding the values
    1 2
    4 8
    16
    32
    64
    128
    256
    ...

    to your counter variables. When you have walked through all set bits in your number, your counter variables will represent the digits to display. Process from most significant digit, and skipp all zero counters until you find the first non-zero. Then emit all counters down to the 1:s counter.

    A third alternative is to perform division and modulo operations, but that quickly gets complicated when the input number is larger than what the processor can natively compute div/mod for.

Reply
  • How much larger?
    You can create a loop, and while your number is >= 10 you subtract 10 while incrementing a variable. If this variable is non-zero, then display it. Then display the remainder after of the subtractions.
    Starting with a loop subtracting while >= 100 will allow you to handle numbers 0..255.

    For large numbers, it can be better to do it the other way.

    Keep a set of counters for your digit positions.
    One for count of 10000.
    One for count of 1000.
    One for count of 100.
    One for count of 10.
    One for count of 1.

    Zero all counter variables.

    Keep second set of state variables for the different digit positions.

    Zero all but the ones variable that you set to 1.

    Check if lowest bit in number is set. In that case, add the state variables to the counter variables, while keeping track of carry.

    Double the number stored in the state variables, i.e. from 0 0 0 0 0 0 0 1 to 0 0 0 0 0 2.

    If next lowest bit in number is set, then add state variables to counter variables.

    Continue to double the state variables and check further bits in the number.

    This basically means that you are conditionally adding the values
    1 2
    4 8
    16
    32
    64
    128
    256
    ...

    to your counter variables. When you have walked through all set bits in your number, your counter variables will represent the digits to display. Process from most significant digit, and skipp all zero counters until you find the first non-zero. Then emit all counters down to the 1:s counter.

    A third alternative is to perform division and modulo operations, but that quickly gets complicated when the input number is larger than what the processor can natively compute div/mod for.

Children
  • thanks for the input, i would like to display the number in LCD, i am using a count button, for each increment upt o 9 i am able to display after that i have problem, following is the code i used

    ;***********subroutin
    NUMBER MOVLW 2 ;enables the display
    MOVWF PORTA
    MOVLW 3H
    MOVWF PORTB
    CALL CLOCK
    MOVF COUNT,W ; count is the vasriable from the push button
    MOVWF PORTB
    CALL CLOCK ;clock character onto display.
    RETLW 0

    ;*******display*************

    MSG15 ; NUMBER DISPLAY
    MOVLW 0CH ;Cursor on second line, C3
    CLRF PORTA
    MOVWF PORTB
    CALL CLOCK
    MOVLW 04H
    MOVWF PORTB
    CALL CLOCK
    CALL NUMBER ; is from soubroutin
    CALL DELAY
    RETLW 0

    ;************main program

    i call MSG15 ; to display

  • thanks for the input, i would like to display the number in LCD, i am using a count button, for each increment upt o 9 i am able to display after that i have problem, following is the code i used

    ;***********subroutin
    NUMBER MOVLW 2 ;enables the display
    MOVWF PORTA
    MOVLW 3H
    MOVWF PORTB
    CALL CLOCK
    MOVF COUNT,W ; count is the vasriable from the push button
    MOVWF PORTB
    CALL CLOCK ;clock character onto display.
    RETLW 0

    ;*******display*************

    MSG15 ; NUMBER DISPLAY
    MOVLW 0CH ;Cursor on second line, C3
    CLRF PORTA
    MOVWF PORTB
    CALL CLOCK
    MOVLW 04H
    MOVWF PORTB
    CALL CLOCK
    CALL NUMBER ; is from soubroutin
    CALL DELAY
    RETLW 0

    ;************main program

    i call MSG15 ; to display