8051 need help with code:CCC

Thread Starter

123dsfsdfdsfsdfsdf

Joined Dec 21, 2022
4
So hello:3
I have already tried many things, and looked at many things, but I can't implement any way to read a value from my data table character by character
here code:
error:
    Morse:
                        mov  DPTR, #Text     ; Point to the beginning of the text
                            mov     A, R0 ;offset to acc
    
    NextChar:
                        movc A, @A+DPTR            ; Load a character from the text into register A
                            cjne A, #2Eh, EndProgram   ;check for dot
                            cjne A, #20h, WordSpace    ;check for space
                        cjne A, #00h, CharLoop     ; Check if the character is not null (end of text)
                        jmp  EndProgram            ; Otherwise, move to the next character in the text  !!!!!!!!HOW TO CHECK IF IT NULL!!!!!!!!!!!

    CharLoop:
                            orl     A, #20h
                            clr  C ;clear C flag after orl
                            subb A, #61h
                            mov     DPTR, #ASCII_TO_MORSE_TABLE
                            movc A, @A+DPTR
                            ;mov  R4, A     ; R4 = Code MORSE
                            inc  R0;             ; counter chars at Text
                            mov  R2, #00h  ; counter dot\dash in char
                            jmp DotORDash
  DotORDash:  ; here is error, i cant understand how to get char from A(rn A = '....!' where "!" have to be end and i go to next char) 
                            
                            ; R4, A = "--.-!"
                            ; Somehow load to A a first char and so on
                            mov A, #R2
                            inc R2 ; "wich char morse ++"
                            ; cjne work with this
                            cjne A, #21h, Morse; if r4 != "!" jmp Morse
                            cjne A, #2Dh, DASH; if r4 != "-" call DASH
                            cjne A, #2Eh, DOT; if r4 != "." call DOT
                            jmp Morse
Table:
Text: db 'Hello world!'

 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  |  |   0  |  |   1  |  |   2  |  |   3  |   |  4  |  |   5  |  |   6  |  |   7  |   |   8  |  |   9  |
 

Papabravo

Joined Feb 24, 2006
20,615
You need one index for the ASCII character strings. This would seem to be R0. You need a 2nd index for the Morse code Strings. How about R1. Alternatively, you could push R0 onto the stack, reuse it, and restore the index to your ASCII string with a POP operation. You could aslo use the XCH operation to save and restore values.
 

Ian Rogers

Joined Dec 12, 2012
1,134
When you create the table you will need to create four characters per ASCII character.

A~Z all have four or less is E = . and T = - worst case like J, Q and others having four J =.---
Do you want to print out your message "Hello world"? If so you will need a table for ASCII A~Z and a second for the MORSE A~Z

Take H this is ASCII position 72 So if the ASCII A position is 65, H will need to be the 7th letter.
For the MORSE table with 4 characters per character will start at 10 * 4, so ASCII[7] will equal MORSE[28] then print four characters H will be ....
 

Thread Starter

123dsfsdfdsfsdfsdf

Joined Dec 21, 2022
4
You need one index for the ASCII character strings. This would seem to be R0. You need a 2nd index for the Morse code Strings. How about R1. Alternatively, you could push R0 onto the stack, reuse it, and restore the index to your ASCII string with a POP operation. You could aslo use the XCH operation to save and restore values.
But I use Charloop here to find out under which index the morse code for my current letter is, and the main problem for me is how to check this character in morse form step by step (that is, I know that this is the character "a", I know where it is, its morse representation, but I don't know how to check and call the corresponding DOT\DASH functions)
 

Thread Starter

123dsfsdfdsfsdfsdf

Joined Dec 21, 2022
4
When you create the table you will need to create four characters per ASCII character.

A~Z all have four or less is E = . and T = - worst case like J, Q and others having four J =.---
Do you want to print out your message "Hello world"? If so you will need a table for ASCII A~Z and a second for the MORSE A~Z

Take H this is ASCII position 72 So if the ASCII A position is 65, H will need to be the 7th letter.
For the MORSE table with 4 characters per character will start at 10 * 4, so ASCII[7] will equal MORSE[28] then print four characters H will be ....
yes, I tried to do that, but at first there was an error in the implementation of such a table, and even without the table there was a problem how to process this data again so that to call DOT\DASH
 

John P

Joined Oct 14, 2008
2,014
It's a long time since I wrote code for the 8051, but this looks as if it must fail:
Code:
  cjne A, #2Eh, EndProgram   ;check for dot
  cjne A, #20h, WordSpace    ;check for space
  cjne A, #00h, CharLoop     ; Check if the character is not null (end of text)
  jmp  EndProgram            ; Otherwise, move to the next character in the text  !!!!!!!!HOW TO CHECK IF IT NULL!!!!!!!!!!!
Surely CJNE is "Compare and jump if not equal"? So it does the first compare, and for anything except 0x2E, jumps to EndProgram. Then it compares to 0x20, and the only value acc can have at that point is 0x2E, so it can't possibly be 0x20, and it jumps to WordSpace. The program will never reach the other 2 lines at all. Have I forgotten how the code works, or is the program really this bad?
 

Thread Starter

123dsfsdfdsfsdfsdf

Joined Dec 21, 2022
4
It's a long time since I wrote code for the 8051, but this looks as if it must fail:
Code:
  cjne A, #2Eh, EndProgram   ;check for dot
  cjne A, #20h, WordSpace    ;check for space
  cjne A, #00h, CharLoop     ; Check if the character is not null (end of text)
  jmp  EndProgram            ; Otherwise, move to the next character in the text  !!!!!!!!HOW TO CHECK IF IT NULL!!!!!!!!!!!
Surely CJNE is "Compare and jump if not equal"? So it does the first compare, and for anything except 0x2E, jumps to EndProgram. Then it compares to 0x20, and the only value acc can have at that point is 0x2E, so it can't possibly be 0x20, and it jumps to WordSpace. The program will never reach the other 2 lines at all. Have I forgotten how the code works, or is the program really this bad?
yeah, i know its fail 100%, i know how fix that, but i dont know how to get char step-by-step from ASCII table
 
Top