G_PortC_0 = IO_RC0_PORT; //Pin RC0 Single bit Binary Input (sends to righter most bit0)
// 00000001 what I think would be the result assuming all pins are high
G_PortC_1 = IO_RC1_PORT<<1; //shift RC1bit to bit1
// 00000010 what I think would be the result assuming all pins are high
GettinBetter wrote:Roche wrote:This sort of got me intrigued. I only work in assembly - this seems to work OK:
- Code: Select all
;------------------------------------------------------------------------------
;gray
; Converts 8 bit gray code to binary
; can almost certainly be optimised - takes about 91 +/- instructions to execute
; Uses 3 8 bit registers
; input ; input gray code
; output ; output binary
; count ; loop count
;------------------------------------------------------------------------------
gray: ; 8 bit gray to binary converter
movlw 0x08 ; initialise loop count
movwf count
clrf output ; clear the output
btfsc input, 7 ; test most significant bit
bsf output, 7
gray10:
decfsz count ; loop until done
bra grayloop
rlncf input ; preserve the input
rlncf output ; final rotation
return
grayloop:
rlncf input ; all operations are on the most significant bit of input and output
btfss output, 7 ; which are rotated to evaluate each bit.
bra grayloop10
rlncf output
btfss input, 7
bsf output, 7
bra gray10
grayloop10:
rlncf output
btfsc input, 7
bsf output, 7
bra gray10
;------------------------------------------------------------------------------
I'm sure there are ways to improve it...
Regards,
Roche
That's interesting, is this something you've just created, and I assume you tested it? I don't know anything about assembly, but am aware it's possible to insert it into a 'C' file. The encoder I'm using is a 10bit so am using a 16bit var to concatenate both ports pins. Trouble is, the output is binary so there's still work to do on each value to convert to hex.
I took onboard what you guys are saying, I'll make an effort to learn to use the simulator and/or debugging options and break it into smaller parts proving each section.
It's still bugging me though, as to why the encoder has blank spots!
Regards
Les
Users browsing this forum: No registered users and 1 guest