I've noticed that a repeat loop with a call to a sub that also has a repeat in it will both use the same variable SysRepeatTemp1 say - so the repeat containing the sub will do unpredictable things as the variable is overwritten. Here's part of the code I was working on -
'Chip settings
#chip 16F1936, 8
#config OSC = INTOSC, PWRTE = ON, MCLRE = OFF, WDTE = OFF
' UART settings for serial LCD - 9 bit transmission
' with TX9D carrying the register select bit
#define SLCD_RS TXSTA.TX9D
#define USART_BAUD_RATE 9600
#define USART_BLOCKING
set TXSTA.TX9 on ' Enable 9 bit transmission
Dir PORTC.7 In
Dir PORTC.6 out
do
repeat 4
LCDWriteChar(32)
wait 5 ms
LCDHex(0x03D5,3)
end repeat
loop
' Write to the serial LCD
sub SLCD_Write(in SLCD_byte)
set SLCD_RS off
if LCD_RS on then set SLCD_RS on
HSerSend SLCD_byte
end sub
' Overloaded Sub to print a number of HexDigits (1 to 4) from a word
' to the LCD in hex - no leading zero removal
sub LCDHex(In LCDValue as word, in HexDigits)
Set LCD_RS On
HexDigits -
for LCDdigits = 3 to 0
LCDValueTemp = 0
repeat 4
rotate LCDValue left
rotate LCDValueTemp left
end repeat
if HexDigits >= LCDdigits then
if LCDValueTemp > 9 then LCDValueTemp = LCDValueTemp + 7
LCDWriteByte(LCDValueTemp + 48)
end if
next
end sub
The repeat in LCDHex uses the same variable as the main repeat loop when I compile it. Its easy enough to work round with a for-next loop though.
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I love that feature. As example i have subroutines with two optional word variables
Using the same variable names for computing the values, the compiler automatically elinminate the need for copying the values
form one variable to the other. This features have allowed me to write the project in basic instead of assembler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Hugh,
I've noticed that a repeat loop with a call to a sub that also has a repeat in it will both use the same variable SysRepeatTemp1 say - so the repeat containing the sub will do unpredictable things as the variable is overwritten. Here's part of the code I was working on -
'Chip settings
#chip 16F1936, 8
#config OSC = INTOSC, PWRTE = ON, MCLRE = OFF, WDTE = OFF
' Serial LCD setup
#define LCD_IO 0
#define LCDWriteByte SLCD_Write
#define LCD_NO_RW
' UART settings for serial LCD - 9 bit transmission
' with TX9D carrying the register select bit
#define SLCD_RS TXSTA.TX9D
#define USART_BAUD_RATE 9600
#define USART_BLOCKING
set TXSTA.TX9 on ' Enable 9 bit transmission
Dir PORTC.7 In
Dir PORTC.6 out
do
repeat 4
LCDWriteChar(32)
wait 5 ms
LCDHex(0x03D5,3)
end repeat
loop
' Write to the serial LCD
sub SLCD_Write(in SLCD_byte)
set SLCD_RS off
if LCD_RS on then set SLCD_RS on
HSerSend SLCD_byte
end sub
' Overloaded Sub to print a number of HexDigits (1 to 4) from a word
' to the LCD in hex - no leading zero removal
sub LCDHex(In LCDValue as word, in HexDigits)
Set LCD_RS On
HexDigits -
for LCDdigits = 3 to 0
LCDValueTemp = 0
repeat 4
rotate LCDValue left
rotate LCDValueTemp left
end repeat
if HexDigits >= LCDdigits then
if LCDValueTemp > 9 then LCDValueTemp = LCDValueTemp + 7
LCDWriteByte(LCDValueTemp + 48)
end if
next
end sub
The repeat in LCDHex uses the same variable as the main repeat loop when I compile it. Its easy enough to work round with a for-next loop though.
Frank
I love that feature. As example i have subroutines with two optional word variables
Using the same variable names for computing the values, the compiler automatically elinminate the need for copying the values
form one variable to the other. This features have allowed me to write the project in basic instead of assembler.