I didn't know we were going for speed....
I didn't know we were going for speed....
Dave Purola,
N8NTA
EN82fn
or even this way, constant speed
Code:control EQU 0x30 latb_shadow EQU 0x31 LATCH EQU 0x32 ; simulate lat reg ORG ResetVector goto Start Start MOVLW 0 MOVWF control MOVLW 3 MOVWF LATCH ; eg. LATB,A lopo BANKSEL latb_shadow INCF control,F MOVLW 0xf ANDWF control,F MOVFF LATCH ,latb_shadow MOVLW 0xf andwf latb_shadow ,F SWAPF latb_shadow,F MOVF control,W IORWF latb_shadow ,F SWAPF latb_shadow,W MOVWF LATCH GOTO lopo END
Warning I'm not a teacher
A little more thought reduces it further,no need at all for a shadow working reg at all
works perfectly on the simulator steps through all 16 "control" states on latb 4-7 and preserves latb 0-3.
Code:; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR Processor 18f4550 include "p18f4550.inc" TRUE equ 1 FALSE equ 0 cblock 0x30 control ;latb_shadow endc RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ; TODO ADD INTERRUPTS HERE IF USED MAIN_PROG CODE ; let linker place main program START MOVLW 0f MOVWF control MOVLW 3 MOVWF LATB,A lopo BANKSEL control INCF control,F MOVLW 0xf ANDWF control,F MOVF LATB,A,W ANDLW 0XF SWAPF WREG,F IORWF control,W SWAPF WREG,F MOVWF LATB ,A GOTO lopo
Last edited by richard; - 24th July 2018 at 08:02.
Warning I'm not a teacher
if I may...
Code:RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ; TODO ADD INTERRUPTS HERE IF USED MAIN_PROG CODE ; let linker place main program START MOVLW 0f MOVWF control MOVLW 3 MOVWF LATB,A lopo BANKSEL control incf control,F ; control = control + 1 bcf control,4 ; control = control mod 15 swapf control,W ; B7..B4 <- control xorwf LATB,W ; wreg = differences andlw 0xF0 ; ignore B3..B0 bits xorwf LATB,F ; update B7..B4 bits GOTO lopo
t'would be simpler/faster still if you were to use the B3..B0 pins as both the 'control' variable and 'control' I/O;
Code:RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ; TODO ADD INTERRUPTS HERE IF USED MAIN_PROG CODE ; let linker place main program START movlw 0x30 ; B7..B4 other I/O, B3..B0 = control movwf LATB ; lopo incf LATB,W ; B3..B0 bits = control, 0..15 xorwf LATB,W ; wreg = differences andlw 0x0F ; ignore B7..B4 bits (and control mod 16 for free) xorwf LATB,F ; update B3..B0 bits, 0..15 GOTO lopo
Last edited by Mike, K8LH; - 24th July 2018 at 23:08.
that's exactly what a good forum needsif I may...Mike, K8LH
your solution is excellent
Warning I'm not a teacher
I like pedja089's solution which is probably about as simple, efficient, and elegant as you can get with pure PBP code. He might test clearing the four LATB bits and then setting them based on if control.0 = 1 then latb.4 = 1 (or something similar).
I have to say the code PBP generated for the "Control << 4" instruction was pretty dismal. I'm curious to see what XC8 will generate for that...
Last edited by Mike, K8LH; - 25th July 2018 at 04:13.
Bookmarks