I don't know and I can't test/try if your code right now but a simple workaround would beCode:For i = 0 to BalCount ' (Or possibly BalCount-1) HSEROUT [BalBuffer] NEXT HSEROUT [26,13]
I don't know and I can't test/try if your code right now but a simple workaround would beCode:For i = 0 to BalCount ' (Or possibly BalCount-1) HSEROUT [BalBuffer] NEXT HSEROUT [26,13]
Thanks Henrik,
I went this way already but so it is correct, the number of characters cannot be replaced by a variable.
Strange....
Roger
Which device are you using?
I compiled two different version and looked at the .lst and with my limited understanding of assembly I'd say it "should work"
First, HSEROUT [STR Buffer\16]
Here it takes the literal 16 and moves it to the low byte (I think) of system variable R4.Code:movlw low (010h) movwf R4 + 1 movlw low (low (HSEROUTJ)) movwf R8 clrf (R8) + 1 clrf R2 + 1 movlw low (low (_Buffer)) call SEROUT2STRN
Second, HSEROUT [STR Buffer\Length]
Here it takes the Length variable, and loads THAT to the low byte (I think) of system variable R4.Code:movf _Length, W movwf R4 + 1 movlw low (low (HSEROUTJ)) movwf R8 clrf (R8) + 1 clrf R2 + 1 movlw low (low (_Buffer)) call SEROUT2STRN
In the actual serout macro it then decrements R4 to determine when it's done.
Page 47 of the manual says "STR must be followed by a backslash and a number that specifies how many
characters (bytes) to collect."
So, as I understand it, it should be a number, not a variable.
If you want to change that on the fly, then Henrik's loop is the way to go.
Ioannis
it works for me
Code:;pic18f26k22 tx demo #CONFIG CONFIG FOSC = INTIO67 CONFIG PLLCFG = OFF CONFIG PRICLKEN = OFF CONFIG FCMEN = OFF CONFIG IESO = OFF CONFIG PWRTEN = OFF CONFIG BOREN = SBORDIS CONFIG BORV = 190 CONFIG WDTEN = ON CONFIG WDTPS = 32768 CONFIG CCP2MX = PORTC1 CONFIG PBADEN = OFF CONFIG CCP3MX = PORTB5 CONFIG HFOFST = ON CONFIG T3CMX = PORTC0 CONFIG P2BMX = PORTB5 CONFIG MCLRE = EXTMCLR CONFIG STVREN = ON CONFIG LVP = OFF CONFIG XINST = OFF CONFIG DEBUG = OFF CONFIG CP0 = OFF CONFIG CP1 = OFF CONFIG CP2 = OFF CONFIG CP3 = OFF CONFIG CPB = OFF CONFIG CPD = OFF CONFIG WRT0 = OFF CONFIG WRT1 = OFF CONFIG WRT2 = OFF CONFIG WRT3 = OFF CONFIG WRTC = OFF CONFIG WRTB = OFF CONFIG WRTD = OFF CONFIG EBTR0 = OFF CONFIG EBTR1 = OFF CONFIG EBTR2 = OFF CONFIG EBTR3 = OFF CONFIG EBTRB = OFF #ENDCONFIG define OSC 8 DEFINE DEBUG_REG PORTB DEFINE DEBUG_BIT 7 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 DEFINE HSER_TXSTA 20h DEFINE HSER_BAUD 9600 trisb=$7f OSCCON = $60 ; OSC 8 anselc = 0 BalBuffer VAR BYTE[60] BalCount VAR BYTE latb.7=1 for BalCount= 0 to 59 BalBuffer[BalCount]=BalCount+"0" next BalBuffer[59]=0 pause 2000 debug "ready",13,10 BalCount = 40 HSEROUT [STR BalBuffer\BalCount,13,10] debug STR BalBuffer\BalCount,13,10 debug "full load",13,10 debug STR BalBuffer,13,10 end
Warning I'm not a teacher
or even
Code:BalCount = 40HSEROUT [STR BalBuffer\BalCount,13,10] debug STR BalBuffer\BalCount,13,10 debug "full load",13,10 debug STR BalBuffer,13,10 HSEROUT [STR BalBuffer,13,10] for BalCount= 0 to 40 HSEROUT [STR BalBuffer\BalCount,13,10] next end
Warning I'm not a teacher
Unfortunately Charles Leo is not monitoring this forum. I 'll make a post on support.melabs.com to clarify this, since the manual is not very clear on the matter.
I 'd rather be 100% sure that this is trusted all the time on all MCU's.
Ioannis
it fails of course for more than 255 chrs
Code:BalBuffer VAR BYTE[300] BalCount VAR word latb.7=1 clear for BalCount= 0 to 59 BalBuffer[BalCount]=BalCount+"0" next for BalCount= 1 to 59 BalBuffer[BalCount+60]=BalCount+"0" next for BalCount= 1 to 59 BalBuffer[BalCount+120]=BalCount+"0" next for BalCount= 1 to 59 BalBuffer[BalCount+180]=BalCount+"0" next for BalCount= 1 to 59 BalBuffer[BalCount+240]=BalCount+"0" next BalBuffer[0]=13 BalBuffer[60]=13 BalBuffer[120]=13 BalBuffer[180]=13 BalBuffer[240]=13 pause 2000 debug "ready",13,10 BalCount = 40 HSEROUT ["40 ",STR BalBuffer\BalCount,13,10] debug "40 ",STR BalBuffer\BalCount,13,10 debug "full load " debug STR BalBuffer,13,10 HSEROUT ["full load ",STR BalBuffer,13,10] BalCount = 255 HSEROUT ["255 ",STR BalBuffer\BalCount,13,10] HSEROUT [13,10] HSEROUT ["260"] BalCount = 260 HSEROUT [STR BalBuffer\BalCount,13,10] end
Last edited by richard; - 22nd February 2021 at 11:29.
Warning I'm not a teacher
Bookmarks