Here's one version using a modified PBP library routine & macro;
Code:
Result VAR BYTE BANK0 SYSTEM
I VAR BYTE BANK0 SYSTEM
Temp VAR BYTE BANK0 SYSTEM
X VAR BYTE
TRISB.4 = 1
Result = 0
Main:
for I = 0 to 7 ' loop x 8
X = 0
while X < 10 ' Test pin x 10
if PORTB.4 = 1 then
call BitSet ; Result.0[I] = 1
else
call BitClear ; Result.0[I] = 0
endif
X = X + 1
wend
next I
Done:
goto Done
BitClear:
ASM
call ConvertBit ; Bitmask -> W
movwf Temp ; W -> Temp
comf Temp,F ; Invert Temp
movf Temp,W ; Temp -> W
andwf Result,F ; AND W with Result
return
ENDASM
BitSet:
ASM
call ConvertBit ; Bitmask -> W
iorwf Result,F ; OR W with Result
return
;******************************************************
;* Input : I = bit (0 - 7) *
;* Output : W = bit mask *
;* Notes : Modified example from PBP library *
;******************************************************
ConvertBit ; See pbppic14.lib CONVBIT & TABLE?C macro
movlw btable >> 8 ; Get high address of jump table
movwf PCLATH ; Set program counter latch high
movf I,W ; Get bit number from I into W reg
andlw 07h ; Isolate lower 3 bits (only works with 0-7)
TABLE?C 08h ; PBP library macro for table alignment
btable ; Returns from table with bit mask in W reg
retlw 01h ; %00000001
retlw 02h ; %00000010
retlw 04h ; %00000100
retlw 08h ; %00001000
retlw 10h ; %00010000
retlw 20h ; %00100000
retlw 40h ; %01000000
retlw 80h ; %10000000
ENDASM
END
You can learn a good deal about assembly language by reading through the
PBP library.
Bookmarks