View Full Version : Assembly Language inside PBP
Bill Legge
- 11th October 2009, 11:23
I'm using PBP with a PIC18F1220 in a weather station.
The rain gauge - a tipping bucket - triggers an assembler interrupt routine that accumulates the number of bucket tips.
the variable (in PBP) that holds the count is:
Rain VAR WORD
And the ASM interrupt routine includes the instruction:
incf _Rain ; Increment Rain variable
all works OK but the asm does not recognise the variable 'Rain' as a WORD and 'rolls over when it reaches 255.
How do I get the asm interrupt routine to deal with 'Rain' as a WORD
Thanks
Bill Legge
Jerson
- 11th October 2009, 12:10
You can try this.
movlw 1
addwf _Rain ; increment the LSB
btfsc STATUS,C ; if overflow, increase MSB
incf _Rain+1
Bill Legge
- 12th October 2009, 08:59
Thanks Jerson - I will give it a go.
I presume that PBP allocates two BYTES of memory to the WORD sized variable 'RAIN' and the assembler routine only deals with one of them?
I guess I could create two BYTES to hold the RAIN data and increment the 'higher' BYTE if there is a carry from the 'lower' - Seems a bit cumbersome and I was looking for a neater/easier way.
Regards Bill Legge
Acetronics2
- 12th October 2009, 09:13
Seems a bit cumbersome and I was looking for a neater/easier way.
Hi, Bill
As the 18F1220 is a 8 bits processor ... the neater/easier way is to use a 16 bits device !!!
not obvious easier, eh ???
NOW, The "DT Instant interrupts" might do the trick " neater " ( sic ) ... it's not raining as the "Niagara falls" , after all ...
OR use one of the chip 16 Bits counters ... you have 3 aboard, after alll ...
Alain
Darrel Taylor
- 12th October 2009, 21:52
I guess I could create two BYTES to hold the RAIN data and increment the 'higher' BYTE if there is a carry from the 'lower' - Seems a bit cumbersome and I was looking for a neater/easier way.
Simple addition or incrementing variables doesn't use the system registers.
So it's ok to break out of ASM and do it with PBP.
Rain VAR WORD
ASM
MyInt
;save context
;asm part here
ENDASM
Rain = Rain + 1
ASM
;more asm here
;restore context
retfie
ENDASM
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.