Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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



 



List of 30 messages in thread
TopicAuthorDate
bit banging program touble            01/01/70 00:00      
   why?            01/01/70 00:00      
      i need a second serial port            01/01/70 00:00      
         something like this , without any warranty :            01/01/70 00:00      
         a good start would be ...            01/01/70 00:00      
            only 3 'U's are commingout of 100            01/01/70 00:00      
               Separate the characters and look with scope            01/01/70 00:00      
                  finally it worked            01/01/70 00:00      
                     uart receiver in software            01/01/70 00:00      
   No I/O or No Timing            01/01/70 00:00      
      "No I/O or No Timing"            01/01/70 00:00      
   Someday you will learn...            01/01/70 00:00      
      this isnt the actual code            01/01/70 00:00      
         Well then another lesson to learn...            01/01/70 00:00      
   Assembler Manual will help you            01/01/70 00:00      
      assembler manual?            01/01/70 00:00      
   Data is 8 Bit??            01/01/70 00:00      
   Bit width timing and timer TH0,TL0 Values            01/01/70 00:00      
      checked values for TH0 and TL0            01/01/70 00:00      
         keil baud rate Calculator not for bit bang            01/01/70 00:00      
   LSB first            01/01/70 00:00      
   now reception....            01/01/70 00:00      
      1) din = din >> 1            01/01/70 00:00      
         working at 1200 baud            01/01/70 00:00      
            delayRS()            01/01/70 00:00      
               why do i have to sample stop bit            01/01/70 00:00      
                  Need not, but should            01/01/70 00:00      
                  because            01/01/70 00:00      
                     Much to a real UART            01/01/70 00:00      
                  1.5 bit delay            01/01/70 00:00      

Back to Subject List