; PSoC 16C450 Replacement Amulet Example - Polling

.equ CTRL_REG, 0fe00h
.equ RX_REG, 0fe02h
.equ RX_FLAG, 40h

.org   000h
ljmp   start

.org   100h
start:
    lcall init
main:
    mov dptr, #CTRL_REG     ; check rx flag
    movx a, @dptr
    anl a, #RX_FLAG
    jz main

    mov dptr, #RX_REG       ; get data
    movx a, @dptr
    mov P1, a 
    lcall sndchr

    mov dptr, #CTRL_REG     ; clear the rx flag
    mov a, #05h             ; baud = 9600, no interrupts
    movx @dptr, a
    sjmp  main

init:
; Set up serial communication to the computer
    mov   tmod, #20h        ; set timer 1 for auto reload - mode 2   
    mov   tcon, #41h        ; run counter 1 and set edge trig ints
    mov   th1,  #0fdh       ; set 9600 baud with xtal=11.059mhz
    mov   scon, #50h        ; set serial control reg for 8 bit data
                            ; and mode 1

    mov   dptr, #CTRL_REG   ; Set up PSoC UART
    mov   a, #05h           ; baud = 9600, no interrupts
    movx  @dptr, a

    ret

sndchr:
   clr  scon.1              ; clear the tx  buffer full flag.
   mov  sbuf,a              ; put chr in sbuf
txloop:
   jnb  scon.1, txloop      ; wait till chr is sent
   ret
