Assembler 8051 how to fix indexing on not first character

56 Views Asked by At

i need a help to solve a problem with indexing at my code of assembler 8051, code below, SO main problem, No matter how many characters I write to the Text, they are still displayed as the character A, and I don't know how to fix it, so I hope someone can explain what the problem is

  Start:
                            mov  R0, #00h          ; Initialize the text index counter
    Morse:
                        mov  DPTR, #Text     ; Point to the beginning of the text
                            mov  A, R0 ;offset to acc
    
    NextChar:
                            cjne R0, #00h, LetterSpaceCALL 
                            jmp Continue0
  Continue0:
                            movc A, @A+DPTR            ; Load a character from the text into register A
                            inc  R0
                            cjne A, #'.', nextTest01   ;check for dot
                            jmp endProgram

  nextTest01: cjne A, #' ', nextTest02
              jmp WordSpace    ;check for space
                            
  nextTest02: jz  EndProgram   ; Check if the character is not null (end of text)

;A is character to decode 
    Char:
                            orl  A, #20h      ;convert to lowercase
                            clr  C            ;clear C flag after orl
                            subb A, #'a'      ;calculate the sequence number of the character
              mov  DPTR, #ASCII_TO_MORSE_TABLE ;set pointer to first char ('a')
;find start morse code for next char
;increasing pointer in loop until separate char '!' is not find
  morseCode:
; DPTR now point to start of morse code sequence
              clr A
              movc A, @A+DPTR
              inc dptr ;move pointer to next morse char
              cjne A, #'!', nextTest03 ; not correct work right here because of compare ! to char, he never jump to test03
              jmp Morse ; if '!' then process next char of message
  nextTest03:
                            call VoidCall
              cjne A, #'-', DotCall ;if dot make somethnig (no others chars as '.' are enabled)
              jmp DashCall ; if '-' make something
                            jmp morseCode

    DotCall:
                          call DOT
                            jmp  morseCode

    DashCall:
                          call DASH
                            jmp  morseCode
  VoidCall:
                            call Void
  ret

    WordSpace:
                        call NEXT_WORD      ; Delay between words
                        jmp  Morse

    LetterSpaceCALL:
                            call LetterSpace
                jmp  Continue0

    EndProgram:
                            clr  GREEN_LED
Text: db 'sos.'

ASCII_TO_MORSE_TABLE:db     '.-!', '-...!', '-.-.!', '-..!',    '.!', '..-.!', '--.!',  '....!', '..!', '.---!', '-.-!', '.-..!',   '--!', '-.!', '---!', '.--.!', '--.-!', '.-.!', '...!', '-!', '..-!', '...-!', '.--!', '-..-!', '-.--!', '--..!' 
                          ; | a  | |  b   | |  c  |  |  d  |     |e|  |  f  |  | g   |  |  h   | | i  | |  j   | |  k  | |  l  |  | m  | | n  | |  o  | |  p  |  |  q  |  |  r |  |  s  | | t | |  u |  |  v  |  |  w  | |  x  |  |  y  |  |  z  |  
                    
1

There are 1 best solutions below

0
the busybee On

You are calculating the index into the morse table between Char: and morseCode:, but you never use that value.

Instead you simply morse the first character, and this is "A".

You need to use the index to skip until you find the morse code for the actual character. You can do this by going through the table, taking the markers ('!') into account. Or, like others suggest, expand each table entry to for example 8 bytes, and calculate the address.

If you go for the searching method, you will need to save the index in some other place than ACC (register A, accumulator), because you need the register to read the codes via movc A, @A+DPTR.