;------------------------------------------------------------------------------
sendcarrybit: ; Transmits carryflag for 9600 baud RS232 @ 15 MHZ.
;------------------------------------------------------------------------------
  jc +  ; Change this to jnc for standard RS232 line levels.
  
  bic.b #1, &P1OUT  ; Simply a LED connectes P1.0 -- A>K -- 470 Ohm -- GND
  jmp ++
+ bis.b #1, &P1OUT
+ 

  ; Wait.
  ; 3 cycles per loop. 
  ; 15 MHz / 9600 Hz = 1562,5 cycles/bit  --> 521 loop runs. 
  ; 18 MHz / 9600 Hz = 1875   cycles/bit  --> 625 loop runs.

  mov #520, r11 ; One less for better timing ;-)
- dec r11       ; (1)
  jnz -         ; (2)
  ;             ; 

  ret


;------------------------------------------------------------------------------
emit:  ; ( c -- ) Emit a byte via emulated RS232 over LED.
;------------------------------------------------------------------------------
 
  push r10
  push r11
  popda r10
  
  inv r10 ; Silence = logic 1 = darkness. I like to see data beeing transmitted as light.
  
  setc                 ; Startbit shining
  call #sendcarrybit
  
  rrc r10
  call #sendcarrybit
  
  rrc r10
  call #sendcarrybit
  
  rrc r10
  call #sendcarrybit

  rrc r10
  call #sendcarrybit

  rrc r10
  call #sendcarrybit

  rrc r10
  call #sendcarrybit

  rrc r10
  call #sendcarrybit
  
  rrc r10
  call #sendcarrybit
  
  clrc                ; Stopbit darkness
  call #sendcarrybit
  
  
  
  mov #1000, r11 ; One less for better timing ;-) Garantiert Ruhe ! Ein bisschen warten...
- dec r11       ; (1)
  jnz -         ; (2)
  ;             ; 
    
  pop r11
  pop r10
  ret
  
   