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

A51 :How to Clear UART with Assembler

Hi everyone,
i write an assembler-program with Keil µ-Vision with the device C515C-L which has an 8051 architecture.
Now I try to clear the UART window in the simulator with some assembler code.
Does anyone know if this is possible?
I found out that it is possible to do this in C by sending <ESC>[J
But how I can I send this using assembler?
Can I anyone help me?

The C-Example is here:
http://www.keil.com/support/man/docs/uv4/uv4_db_dbg_serialwin.htm

  • Exactly what issues do you see with sending the same three characters using assembler instead of C? If you have assembler code that can send 'A', 'B' and 'C' then it should be quite easy to also send the escape character, followed by '[' and 'J'.

  • Thanks for your very fast answer Per Westermark.
    What you said is what I thought as well.
    but when i print out ESC[J the UART-Window only outputs the characters [ and J and does not clear anything..
    So here is a part of my assembler-code. Perhabs this helps..
    But anyway thanks for your help until now

    
    
    clearUART:
            mov a,#1Bh              ;ESC
            call serout             ;
            mov a,#5Bh              ;[
            call serout             ;
            mov a,#'J'              ;J
            call serout             ;
            ret
    
    
    ;Gib das Zeichen in a auf die serielle Schnittstelle aus.
    serout:
            jnb ti,$ ;Warte ggf., bis voriges Zeichen
                             ;fertig ausgegeben ist. (Dann wird
                             ;das Transmitter-Interrupt-Flag
                             ;gesetzt.)
            clr ti   ;Lösche Transmitter-Interrupt-Flag wieder.
            mov sbuf,a      ;Lege Zeichen in Sendepuffer und beginne Uebertragung.
            ret
    
    end
    
    

  • Note that <ESC> + [ + J clears from cursor to end of screen.
    <ESC> + [ + 2 + J erases all of screen.

  • okay..
    I tried these two things.
    In my view the second one must be right, because 2h means startOfText in ascii.

    
    clearUART:
            mov a,#1Bh              ;ESC
            call serout             ;
            mov a,#5Bh              ;[
            call serout             ;
            mov a,#'2'              ;2
            call serout             ;
            mov a,#'J'              ;J
            call serout             ;
            ret
    
    clearUART:
            mov a,#1Bh              ;ESC
            call serout             ;
            mov a,#5Bh              ;[
            call serout             ;
            mov a,#2h               ;2
            call serout             ;
            mov a,#'J'              ;J
            call serout             ;
            ret
    
    

    But unfourtenetly both didn't work for me.
    The UART window still only prints out the letters

    So teh UART-window shows something like this :

    
    XXXXXXXXXXXXXXXXXXXX
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X         @OO      X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    XXXXXXXXXXXXXXXXXXXX
    [ JXXXXXXXXXXXXXXXXXXXX
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X        @OO       X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    X                  X
    XXXXXXXXXXXXXXXXXXXX
    
    
    

  • I now found my failure.
    The code of clearUART was, how you already said, alright, but somewhere else in my code i once had tried to print out ESC. Just for to see if anything happens.
    And this ESC was unfortuenetly always printed directly before clearUART was executed.
    Because of this my programm always printed ESC ESC [ J. And this somehow confused the UART.

    So anyway the right way to clear the UART using assembler is:

    
    clearUART:
            mov a,#1Bh              ;ESC
            call serout             ;
            mov a,#5Bh              ;[
            call serout             ;
            mov a,#'J'              ;J
            call serout             ;
            ret
    
    
    ;<<<-----Serielle Schnittstelle----->>>
    
    
    ;serini: Initialisiere die serielle Schnittstelle des C515C
    ;auf 9600 Baud, 1 Stoppbit, kein Paritybit.
    ;Aufruf ist bei der echten Mikrocontrollerkarte im Labor nicht
    ;nötig, da für das Laden des Programms schon eine
    ;Initialisierung durch uVision erfolgt.
    ;Siehe auch das C515C-User-Manual, Seite 6-48ff.
    serini: mov srelh,#03h  ;Lade Baud-Rate-Zähler, oberer Teil
                            ;(Formel im User-Manual auf S. 6-54).
            mov srell,#0bfh ;Lade Baud-Rate-Zähler, unterer Teil,
                            ;und setze Zähler zurück.
            orl pcon,#10000000b ;Setze SMOD-Bit im Register PCON
                            ;(verdoppelt Baud-Rate).
            setb bd         ;Setze BD-Bit im Register ADCON0
                            ;(Baud rate generator enable).
            mov scon,#01010010b ;Setze Bits im Register SCON
                            ;(von links nach rechts):
                            ;SM0=0, SM1=1, SM2=0:
                            ;  serial mode 1, also 8-Bit-UART
                            ;  mit variabler Baud-Rate,
                            ;  einem Stoppbit und keinem
                            ;  Paritybit.
                            ;REN=1: Receiver enable.
                            ;TB8=0: unbenutzt (9. Sendebit).
                            ;RB8=0: unbenutzt (9. Empfangsbit).
                            ;TI=1: Transmitter-Interrupt-Flag.
                            ;RI=0: Receiver-Interrupt-Flag.
            ret
    
    
    
    ;Gib das Zeichen in a auf die serielle Schnittstelle aus.
    serout:
            jnb ti,$ ;Warte ggf., bis voriges Zeichen
                             ;fertig ausgegeben ist. (Dann wird
                             ;das Transmitter-Interrupt-Flag
                             ;gesetzt.)
            clr ti   ;Lösche Transmitter-Interrupt-Flag wieder.
            mov sbuf,a      ;Lege Zeichen in Sendepuffer und beginne Uebertragung.
            ret
    
    
    

  • Just note that you can't really confuse the UART. But you can "confuse" the state machine on the receiving end, that switches mode when it sees the ESC (which is why the character Escape is named as it is) and then waits for the sequence of characters that forms the control code.

    It seems that this state machine fails the "restart" situation, where there is a new ESC character received while it already thinks that it is processing an escape sequence. It is, alas, quite common that state machines forgets to resynchronize if there is a new start condition.