| ??? 08/03/11 09:20 Read: times  | 
#183167 - something like this , without any warranty : Responding to: ???'s previous message  | 
mysegcode segment code
mysegbit  segment bit
mysegdata segment data
;----------------
rseg mysegbit
tx_bit: ds 1
;----------------
rseg mysegdata
c_maxtxbuflength equ 16
txmsglength: ds 1
txbuffer: ds c_maxtxbuflength
txpointer: ds 1
txsendcounter: ds 1
txbytetosend: ds 1
txbitcounter: ds 1
;-----------------
rseg mysegcode
  org 0
  ljmp main_tx_test
  
  org 0bh
  ljmp T0_isr
main_tx_test:
  mov dptr #messagehello
  call proc_prepare_tx_message ;will send 'HELLO,'
  call proc_send_message
  mov dptr #messageworld
  call proc_prepare_tx_message ;will send 'HELLO,'
  call proc_send_message
  jmp main_tx_test
;-------------
messagehello: db 'HELLO,',0 ;zero teminated string
mesasgeworld: db 'WORLD!',13,10,0
proc_prepare_tx_message:
   mov r2,#c_maxtxbuflength
   mov r3,#0
   mov r0,#txbuffer
pr_pmsgcop_loop:   
   clr a
   movc a,@a+dptr
   jz pr_pmsgcop_zeroterm ;zero terminator found
   mov @r0,a 
   inc r0
   inc r7
   djnz r2,pr_pmsgcop_loop
pr_pmsgcop_zeroterm:
   mov txmsglength,r7     
   ret 
;------------
proc_send_message:
   mov a,txmsglength
   jz proc_send_mes_end
   mov txsendcounter,a
   mov txpointer,#0
proc_send_mnext:   
   mov a,txpointer
   add a,#txbuffer
   mov r0,a
   mov a,@r0
   
   setb c
   rrc a
   mov tx_bit,c
   mov txbytetosend,a
   mov txbitcounter,#10
   
   call inittimerT0 ;this starts  sending byte by Timer0
                    ;sending is moved by ISR for Timer0
proc_send_mes_waitbyte:
   mov a,txbitcounter   
   jnz proc_send_mes_waitbyte
   inc txpointer
   dec txsendcounter 
   mov a,txsendcounter
   jnz proc_send_mnext
proc_send_mes_end:
   ret
;-------------
T0bittime_const equ 65536-416 
;416== bit time in microseconds, xtal=12 MHz, 12 clocker
inittimerT0:
    clr TR0
    clr ET0 
    mov a,TMOD 
    anl a,#0f0h
    orl a,#1 ;mode 1 for TIMER0   
    mov TL,#low(T0bittime_const) 
    mov TH,#high(T0bittime_const)
    clr P3.1 ;start bit bigins here
    setb TR0 
    setb ET0
    ret
;----------
T0_isr:
    clr EA
    push PSW
    push acc
    ;output next bit
    mov c,tx_bit
    mov P3.1,c   
    ;reload timer
    clr TR0
    mov a,#low(T0bittime_const)
    add a,TL0
    mov TL0,a
    mov a,#high(T0bittime_const)
    addc a,TH0
    mov TH0,a
    setb TR0   
    setb EA
    
    ;prepare next bit to send
    mov a,txbytetosend
    setb c
    rrc a
    mov tx_bit,c
    mov txbytetosend,a
    ;checking for byte sended?
    dec  txbitcounter
    mov a,txbitcounter
    jnz T0_ISRend 
    ;byte is sended, stop interrupt
    clr TR0
    clr ET0
T0_ISRend:
     pop acc
     pop psw
     reti
 
 | 



