MessUpMymind
New Member
ive gone through Tutorial 12.3 of the wireless transmission and receiving of Nigel Goodwin's PIC Tutorial and the implementation has been successful.
Now I would like to wirelessly transmit out asynchronous data coming out from the serial port (using vb's mscomm) to my microcontroller. For that , I would need 2 PIC's (one at the TX end and the other at the RX end) for the implementation of Manchester Coding. Each data frame coming out of the computer is 10 bits consisting of 1 START bit, 8 DATA bits and 1 stop bit..(my vb settings are "9600,N,8,1")
From the serial port, a continuous string of ASCII characters will be transmitted out..
I understand that I have to configure the TXSTA and RXSTA registers as well as the SPBRG registers as stated in the datasheet but I would like to know how I can implement as well the Manchester Coding routine for this..
On the transmit side, I will be connecting the Tx pin from the serial port to Rx (pin26) of the 16f877A and then connect pin 25(Tx) to the data pin of the wireless transmitter.
On the receive side, I will be connecting the Data pin of the wireless receiver to pin26(Rx) of the PIC....
here's the Manchester coding routine that i extracted from nigel's tutorial:
and now what i need to do is , implement this Manchester coding into this transmitter side coding ,
Would be great if anyone could guide me on how I can implement the Manchester Code routine for what i want to achieve..
Now I would like to wirelessly transmit out asynchronous data coming out from the serial port (using vb's mscomm) to my microcontroller. For that , I would need 2 PIC's (one at the TX end and the other at the RX end) for the implementation of Manchester Coding. Each data frame coming out of the computer is 10 bits consisting of 1 START bit, 8 DATA bits and 1 stop bit..(my vb settings are "9600,N,8,1")
From the serial port, a continuous string of ASCII characters will be transmitted out..
I understand that I have to configure the TXSTA and RXSTA registers as well as the SPBRG registers as stated in the datasheet but I would like to know how I can implement as well the Manchester Coding routine for this..
On the transmit side, I will be connecting the Tx pin from the serial port to Rx (pin26) of the 16f877A and then connect pin 25(Tx) to the data pin of the wireless transmitter.
On the receive side, I will be connecting the Data pin of the wireless receiver to pin26(Rx) of the PIC....
here's the Manchester coding routine that i extracted from nigel's tutorial:
Code:
packet_len EQU 2 ;packet length 1 + 1 address byte
cblock 0x20 ;start of general purpose registers
ncnt
bt
sum
mtx_buffer
mtx_buffer1
mtx_delay ; half_frame delay
count1 ;used in delay routine
count2
counta ;used in delay routine
countb ;used in delay routine
endc
call mtx_init
movlw 0xAA ;set address byte to 0xAA
movwf mtx_buffer
;Manchester subroutines
; Author: el@jap.hu
; http://jap.hu/electronic/
mtx_init
movlw .115 ; 350 usec
movwf mtx_delay
return
;
mtx_send
; send out buffer
outbuf movlw 0x14 ; 20xbit1, 1xbit0
header movwf count2
head0 call bit1
decfsz count2,F
goto head0
call bit0
movlw mtx_buffer
movwf FSR
movlw packet_len
movwf count1
movlw 0xff
movwf sum
;
outbu0 movf INDF,W
call update_sum
movf INDF,W
call outbyte
incf FSR,F
decfsz count1,F
goto outbu0
movf sum,W
call outbyte
; buffer is sent
return
update_sum ; fast CRC-8 algorithm with poly x^8+x^5+x^4+1
; executes in 23 cycles per update
xorwf sum,f
clrw
btfsc sum,7
xorlw 0x7a
btfsc sum,6
xorlw 0x3d
btfsc sum,5
xorlw 0x86
btfsc sum,4
xorlw 0x43
btfsc sum,3
xorlw 0xb9
btfsc sum,2
xorlw 0xc4
btfsc sum,1
xorlw 0x62
btfsc sum,0
xorlw 0x31
movwf sum
return
outbyte movwf bt
movlw 8
movwf count2
outby0 rlf bt,F
btfsc STATUS,C
goto outby1
call bit0
goto outby2
outby1 call bit1
outby2 decfsz count2,F
goto outby0
;
call bit1
; and bit0 - falls through to bit0 subroutine
;send a bit0
bit0 TXHIGH ; HIGH
call mtx_bitdel ; bit time delay
TXLOW ; to LOW transition
call mtx_bitdel ; bit time delay
return
;send a bit1
bit1 TXLOW ; LOW
call mtx_bitdel ; bit time delay
TXHIGH ; to HIGH transition
call mtx_bitdel ; bit time delay
return
; bit delay modified by NG
mtx_bitdel movf mtx_delay, W
movwf ncnt
ndelaya1 decfsz ncnt, F
goto ndelaya1
return
; end of Manchester routines
and now what i need to do is , implement this Manchester coding into this transmitter side coding ,
Code:
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
ByteCounter EQU 0xBD ;address used for byte counter
;**********************************************************************
ORG 0x000 ; processor reset vector
goto Main ; go to beginning of program
;**********************************************************************
; isr code can go here or be located as a call subroutine elsewhere
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
Main:
banksel TRISC
bcf TRISC,6 ;c6=0 as output
bsf TRISC,0 ;c0=1 as input
bsf TRISC,1 ;c1=1 as input
; UART module setup
banksel SPBRG
movlw 15 ; rs232 baud as 57.6k as 15
movwf SPBRG ; Enable SPBRG register Baud Rate
banksel TXSTA ; Select memory bank for TXSTA SFR
bcf TXSTA,TX9 ; 8-bit transmission
bsf TXSTA,TXEN ; Enable Transmission
bcf TXSTA,SYNC ; Asynchronous mode
bsf TXSTA,BRGH ; High Baud Rate
banksel RCSTA
bcf RCSTA,SPEN ; Disable Serial port. I use usart tx function
bsf RCSTA,CREN ; Enable Receiver
BANKSEL PIE1
BCF PIE1,TXIE
; *******************save data in pic*******************************
SaveData
bsf STATUS,RP0 ;bank 1
movlw 0x42
movwf 0xBF
movlw 0x24
movwf 0xC0
;movlw 0x00
;movwf 0xC1
;movlw 0x00
;movwf 0xC2
;movlw 0x00
;movwf 0xC3
;movlw 0x00
;movwf 0xC4
;*********************transmit data new ******************************
MOVLW 0x02
MOVWF ByteCounter
TestTxreg
banksel PIR1
btfss PIR1,TXIF ;TXIF=1, is empty,skip
goto TestTxreg
TransData:
MOVLW 0xBF
MOVWF FSR ; TO RAM
;CLRF TXREG
GoOnTransData:
banksel TXREG
MOVF INDF,0
MOVWF TXREG ; Move the data to the transmit register
INCF FSR,1 ; INDF address number moves next
Wait0:
banksel PIR1
btfss PIR1,TXIF
goto Wait0
clrf TXREG
BSF STATUS,RP0
DECFSZ ByteCounter,1 ; ChannelCounter-1
goto GoOnTransData ; go on
Wait1:
banksel TXSTA
MOVLW 0x02
MOVWF ByteCounter
Delay:
BANKSEL RCSTA
MOVLW 0x02 ;20MHz=50ns=0.05us
MOVWF 0x20 ;0.05*4=0.2us
LOOP2:
MOVLW 0x03 ;E5=120us;c5=80us;85=75u;35=45=55=0
MOVWF 0x21 ;03H=16us
LOOP1:
DECFSZ 0x21,F
GOTO LOOP1
DECFSZ 0x20,F
GOTO LOOP2
GOTO TransData
;goto FinishData
FinishData:
movlw 0x00
movwf TXREG
goto FinishData
END
;*********************transmit data finish*****************
Would be great if anyone could guide me on how I can implement the Manchester Code routine for what i want to achieve..