I have written in assembler 3-Digit 7Segment Multiplexing Code that works very well...because i have inpit format number from 000-999 To be displayed i need to write ASM function that takes this input number and put each digit in correspoding registers so that my function then can take this number that is index in array and read 7-Segment HEX code that will be send to each segment to turn on LED so that correct digit is displayed.
So Here is Example:
Input Number Is: 432 And i Need to after function is done to put in registers these values:
R23 - 04
R24 - 03
R25 - 02
So i look at ATMEL avr200.asm and test these code:
.include "m328pdef.inc" .CSEG digit: .DB 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F .ORG 0x0005 rjmp RESET RESET: ; INIT - Stack Pointer ldi R16, HIGH(RAMEND) out SPH, R16 ldi R16, LOW(RAMEND) out SPL, R16 ;***** Subroutine Register Variables .def drem16uL=r14 .def drem16uH=r15 .def dres16uL=r16 .def dres16uH=r17 .def dd16uL =r16 .def dd16uH =r17 .def dv16uL =r18 .def dv16uH =r19 .def dcnt16u =r20 ; LOAD - Divident(dd8u) And Divisor(dv8u) => 432(1B0) / 100 = 4.32 ; Divident 1 ldi dd16uH, HIGH(0x01B0) ldi dd16uL, LOW(0x01B0) ; Divisor 1 ldi dv16uH, HIGH(100) ldi dv16uL, LOW(100) call div16u ldi ZH, HIGH(digit) ; Load Start Z-Address Of Digit Array (Flash) ldi ZL, Low(digit) add ZH, dres16uH ; Add The Digit1 Index adc ZL, dres16uL ; Add 0 To Propagate The Carry lpm R23, Z ; Read Digit1 From Flash loop: rjmp loop ;***** Code div16u: clr drem16uL ; clear remainder Low byte sub drem16uH, drem16uH ; clear remainder High byte and carry ldi dcnt16u,17 ;init loop counter d16u_1: rol dd16uL ;shift left dividend rol dd16uH dec dcnt16u ; decrement counter brne d16u_2 ; if done ret ; return d16u_2: rol drem16uL ;shift dividend into remainder rol drem16uH sub drem16uL,dv16uL ;remainder = remainder - divisor sbc drem16uH,dv16uH ; brcc d16u_3 ;if result negative add drem16uL,dv16uL ; restore remainder adc drem16uH,dv16uH clc ; clear carry to be shifted into result rjmp d16u_1 ;else d16u_3: sec ; set carry to be shifted into result rjmp d16u_1
I added code that read MSB and LSB byte of first result digit and this is 04 and get from index array value 0x66 that when send to 7-Display Segment will be number 4.
So i see in debugger that drem16uL and drem16uH have value in my example 32 so i need to get 3 and 2 and put it in above example registers. U know that 432/100=4,32 and AVR take in above example whole number that is 4 and 32 put in reminder registers so how to do that efficiently to get 3 and 2?
Thanks.