PDA

View Full Version : Any chance of Life being easy?



josegamez
- 1st November 2006, 20:17
Hi everyone!

I have been programming a PIC18F458 with PICBasic Pro and so far everything has gone nice and easy except for changing the oscillator configuration but I got the hang of that already. So I've been printing menus on an LCD, doing pauses, responding to keyboard interrupts, etc but I've now gotten to the point where I actually have to process data and bits. My question is: is there a way of working with groups of bits? (I haven't found anything on this subject in any book on PBP). What I mean is, is there the PBP equivalent for Verilog command lines that involve groups of bits such as PortA[3:1] for example? It would really make my life easier if I could do things like Datum[6:4] = 2 for example or others like IF PORTB[5:1]=3 THEN .... etc. But like I said I haven't seen anything on this anywhere.

If it's not possible, is there at least a way to concatenate bits and stuff into variables without using OR masks? Thanks to all, I hope I was clear in my question because I need help with that. God bless you.

paul borgmeier
- 2nd November 2006, 04:11
Not quite as pretty as your verilog versions ... but should work

;Datum[6:4] = 2
Datum.6=1
Datum.4=0

;IF PORTB[5:1] = 3 THEN
If (PORTB & $22) = $22 THEN

EDIT:
or

IF PORTB.5 = 1 THEN
IF PORTB.1 = 1 THEN
ENDIF
ENDIF

josegamez
- 2nd November 2006, 19:47
Ok I see your point, although those aren't quite equivalent yet. A verilog statement like Datum[6:4] = 2 would change all bits from bit 6 to bit 4 of Datum, turning Datum into X010XXXX where the X's are the previous bit values of Datum before the statement. So referring to Datum as Datum[6:4] is like having a new 3 bit variable where Datum[4] is the new bit 0, Datum[5] is the new bit 1 and Datum[6] is the new bit 2 to complete the three bit variable. But thanks I guess I'll have to work my way around with those sort of tricks. Thanks for your time, God bless.

paul borgmeier
- 2nd November 2006, 20:26
As is clear from above, I have never used verilog ...., for completeness this not so pretty approach still works


;Datum[6:4] = 2
Datum.6=0
Datum.5=1
Datum.4=0


;IF PORTB[5:1] = 3 THEN
If (PORTB & $3E) = $06 THEN

OR you could blast the first type with inline ASM


;Datum[6:4] = 2
Datum var byte
ASM
movlw 0x20 ; b00100000 new values
xorwf _Datum, W
andlw 0x70 ; b01110000 mask values
xorwf _Datum, F ; bX010XXXX
ENDASM
Others might have a cleaner method?

EDIT - added comments to ASM routine

josegamez
- 2nd November 2006, 20:52
OK thanks a lot, I'll try that :)