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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/09/04 19:28
Read: times


 
Msg Score: 0
 +1 Good Question
 -1 Overrated
#72211 - 4Bit to serial (Tx/Rx)
I would like to transmit 4 bit data which subjects to change every .125 ms. The .125ms (with about 4-10 machine cycle period) 0 pulse signal is connected to INT0.

What I have to do is to pack those data into 8 bit (take two of them) and then send it out throufh serial port (which means .256ms for each serial TX). And I also need to detect incoming serial data which come in form of 8 bits, covert back to parallel 4 bits change every .125ms.

I program it on Atmel AT89C52 at 22.118Mhz, serial baud rate is 57600. On testing, my 4 bit data is ADPCM signal of a sinewave. The I connected TX,RX of the uController together. The result is I couldn't recover the sinewave, look like noise (althrough signal change relative to the frequency of the sinewave), It does recover VERY NICE (perfect) somethime if I reset uController many times.

Please help and Here is my code
Best Regards,

Thone M.
  TxBlock     BIT   0H          ;Transmission Hi or Low bit selection for buffer
  RxBlock     BIT   1H          ;Received shift out Hi or Low bit selection
  INT0_test   BIT   10H
  
  
  TxBuffStart EQU   30H
  RxBuffStart EQU   40H


;Test serial port with out any buffer
  ORG     0000H
  AJMP    Initialize_Program

  ORG     0003H                 ;interrupt section
  AJMP    External0_Interrupted
  
  ORG     0023H                 ;serial interrupt
  AJMP    Serial_Interrupted    ;jump to serial interrupt handler

Initialize_Program:
  MOV     SCON, #52H            ;serial mode 1
  MOV     TMOD, #20H            ;timer mode 2
  MOV     A, PCON               ;setting SMOD = 1, Read-Modify-Write
  SETB    ACC.7                 ;
  MOV     PCON, A               ;
  MOV     TH1, #0FEH            ;set 57600 baud rate
  MOV     IE, #10010001B        ;set interrupt
  SETB    TR1                   ;start timer 
  SETB    PX0
  SETB    PS
  CLR     TxBlock
  CLR     RxBlock
  MOV     SBUF, #00000000B      ;send start byte
  JNB     TI, $
  JMP     $

;*******************************************************************************
External0_Interrupted:

;Interrupt Test
  JB      INT0_test, on_off
  SETB    INT0_test
  SETB     P2.2
  AJMP    END_TEST
on_off:
  CLR     INT0_test
  CLR     P2.2
END_TEST:

;Save variable
;-------------
  PUSH    ACC

;Move Rx data onto Port 1
;-------------------------
  MOV     A, RxBuffStart
  JNB     RxBlock, Low_RxBlock
  RL      A
  RL      A
  RL      A
  RL      A
  MOV     P1, A
  CLR     RxBlock
  SETB    P2.0
  AJMP    Tx_Start

;Low Rx Block
;--------------
Low_RxBlock:
  MOV     P1, A
  SETB    RxBlock
  CLR     P2.0

;Start Transmission section
;--------------------------
Tx_Start:
  ;Save incoming data
  MOV     A, P0
  ANL     A, #00001111B
  JNB     TxBlock, Low_TxBlock

  RL      A
  RL      A
  RL      A
  RL      A

;Begin to add High byte to low byte and send data out from serial port
;----------------------------------------------------------------------
  ORL     A, TxBuffStart
  JNB     TI, $                       ;loop until transmittor is ready
  CLR     TI
  MOV     SBUF, A
  CLR     TxBlock
  AJMP    End_External0_Interrupted

Low_TxBlock:
;Begin to add Low byte into buffer
;---------------------------------
  MOV     TxBuffStart, A
  SETB    TxBlock

End_External0_Interrupted:
  ;Restore variable
  POP     ACC
  RETI
  
;*******************************************************************************
Serial_Interrupted:
;Make sure that it is Rx interrupt
;----------------------------------
  JNB     RI, End_Serial_Interrupt
  CLR     RI
  
;Save data from internal serial buffer
;-------------------------------------
  MOV     RxBuffStart, SBUF
  
End_Serial_Interrupted:
  RETI



List of 4 messages in thread
TopicAuthorDate
4Bit to serial (Tx/Rx)            01/01/70 00:00      
   RE: 4Bit to serial (Tx/Rx)            01/01/70 00:00      
      RE: 4Bit to serial (Tx/Rx)            01/01/70 00:00      
         RE: 4Bit to serial (Tx/Rx)            01/01/70 00:00      

Back to Subject List