Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MPlab source code help!!

Status
Not open for further replies.

Cleong

Member level 2
Joined
Feb 17, 2006
Messages
53
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,789
mplab btfsc

Below are the code of hamming code in MPlab
Can someone explain it briefly to me what the code mean
(in theorythically i can understand how it work but when it in source code then i totally blur..)

Hamming code generator
;
;Since our communication is one way, we'll use forward error correction
;to detect single bit errors. To do this, we'll add code bits to our
;ten bit results for a total of 14 bits. These code bits will be in bit
;positions 13, 12, 11, and 10.
;Code bit P1 will be in position D13 and will be the exclusive OR of:
; P1=D9+D8+D6+D5+D3+D1
;Code bit P2 will be in position D12 and will be the exclusive OR of:
; P2=D9+D7+D6+D4+D3+D0
;Code bit P4 will be in position D11 and will be the exclusive OR of:
; P4=D8+D7+D6+D2+D1+D0
;Code bit P8 will be in position D10 and will be the exclusive OR of:
; P8=D5+D4+D3+D2+D1+D0
;The data will be packed as: P1 P2 P4 P8 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
;************************************************************************
(TRANSMITTER PART)
HammCode
clrf HCREG ;Calculate first code bit
movlw 0x20 ;P1=D9+D8+D6+D5+D3+D1
btfsc ACCH,1
incf HCREG,f
btfsc ACCH,0
incf HCREG,f
btfsc ACCL,6
incf HCREG,f
btfsc ACCL,5
incf HCREG,f
btfsc ACCL,3
incf HCREG,f
btfsc ACCL,1
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
iorwf ACCH,f ;set code P1 to a 1
clrf HCREG ;Calculate second code bit
movlw 0x10 ;P2=D9+D7+D6+D4+D3+D0
btfsc ACCH,1
incf HCREG,f
btfsc ACCL,7
incf HCREG,f
btfsc ACCL,6
incf HCREG,f
btfsc ACCL,4
incf HCREG,f
btfsc ACCL,3
incf HCREG,f
btfsc ACCL,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
iorwf ACCH,f ;set code P2 to a 1
clrf HCREG ;Calculate third code bit
movlw 0x08 ;P4=D8+D7+D6+D2+D1+D0
btfsc ACCH,0
incf HCREG,f
btfsc ACCL,7
incf HCREG,f
btfsc ACCL,6
incf HCREG,f
btfsc ACCL,2
incf HCREG,f
btfsc ACCL,1
incf HCREG,f
btfsc ACCL,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
iorwf ACCH,f ;set code P4 to a 1
clrf HCREG ;Calculate fourth code bit
movlw 0x04 ;P8=D5+D4+D3+D2+D1+D0
btfsc ACCL,5
incf HCREG,f
btfsc ACCL,4
incf HCREG,f
btfsc ACCL,3
incf HCREG,f
btfsc ACCL,2
incf HCREG,f
btfsc ACCL,1
incf HCREG,f
btfsc ACCL,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
iorwf ACCH,f ;set code P8 to a 1
return

(RECEIVER PART)
hamm_decode
clrf HCVECT ;clear vector register
clrf HCREG ;Calculate first code bit
;P1=D9+D8+D6+D5+D3+D1+P1
btfsc BUFF_HIGH,5
incf HCREG,f
btfsc BUFF_HIGH,1
incf HCREG,f
btfsc BUFF_HIGH,0
incf HCREG,f
btfsc BUFF_LOW,6
incf HCREG,f
btfsc BUFF_LOW,5
incf HCREG,f
btfsc BUFF_LOW,3
incf HCREG,f
btfsc BUFF_LOW,1
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
bsf HCVECT,0 ;set vector bit 0 to a 1
clrf HCREG ;Calculate second code bit
;P2=D9+D7+D6+D4+D3+D0+P2
btfsc BUFF_HIGH,4
incf HCREG,f
btfsc BUFF_HIGH,1
incf HCREG,f
btfsc BUFF_LOW,7
incf HCREG,f
btfsc BUFF_LOW,6
incf HCREG,f
btfsc BUFF_LOW,4
incf HCREG,f
btfsc BUFF_LOW,3
incf HCREG,f
btfsc BUFF_LOW,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
bsf HCVECT,1 ;set vector bit 1 to a 1
clrf HCREG ;Calculate third code bit
;P4=D8+D7+D6+D2+D1+D0+P4
btfsc BUFF_HIGH,3
incf HCREG,f
btfsc BUFF_HIGH,0
incf HCREG,f
btfsc BUFF_LOW,7
incf HCREG,f
btfsc BUFF_LOW,6
incf HCREG,f
btfsc BUFF_LOW,2
incf HCREG,f
btfsc BUFF_LOW,1
incf HCREG,f
btfsc BUFF_LOW,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
bsf HCVECT,2 ;set vector bit 2 to a 1
clrf HCREG ;Calculate fourth code bit
;P8=D5+D4+D3+D2+D1+D0+P8
btfsc BUFF_HIGH,2
incf HCREG,f
btfsc BUFF_LOW,5
incf HCREG,f
btfsc BUFF_LOW,4
incf HCREG,f
btfsc BUFF_LOW,3
incf HCREG,f
btfsc BUFF_LOW,2
incf HCREG,f
btfsc BUFF_LOW,1
incf HCREG,f
btfsc BUFF_LOW,0
incf HCREG,f
rrf HCREG,f
btfsc STATUS,C ;if summation results in odd number
bsf HCVECT,3 ;set vector bit 3 to a 1
movf HCVECT,f ;test vector
btfsc STATUS,Z ;if zero then no error - otherwise, flip bit
return
movf HCVECT,w ;get the Hamming vector
call hcode_shuffle ;remap code
movwf HCVECT
clrf MASKH ;initialize mask registers
clrf MASKL ;
bsf STATUS,C
 

hamming code source

As the code is without comments so it is hard to help you.

If you have its circuit diagram, post it, so it will help read code.

nguyennam
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top