Trying to passing a value to a FOR statement with a simple byte variable and it doens't work.
Am I doing it wrong ?
The first FOR doens't work, the second one works obviously.
;Chip Settings
#chip 18F47K40
#config RSTOSC=HFINTOSC_64MHZ
;Defines (Constants)
#define LCD_IO 8
#define LCD_RS PORTA.3
#define LCD_RW PORTA.5
#define LCD_Enable PORTE.0
#define LCD_DATA_PORT PORTD
#define USART_BAUD_RATE 31250
#define LCD_DB0 PORTD.0
#define LCD_DB1 PORTD.1
#define LCD_DB2 PORTD.2
#define LCD_DB3 PORTD.3
#define LCD_DB4 PORTD.4
#define LCD_DB5 PORTD.5
#define LCD_DB6 PORTD.6
#define LCD_DB7 PORTD.7
;Variables
Dim start_value As byte
start_value = 10
For counter = start_value to 0
Locate 1, counter
print ("1")
Next
For counter = 10 to 0
Locate 0, counter
print ("1")
Next
end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
quick question : can we use a word as a counter variable ? I've tried but it seems it only counts to 255 and consider any higher value to be equal to 255
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to passing a value to a FOR statement with a simple byte variable and it doens't work.
Am I doing it wrong ?
The first FOR doens't work, the second one works obviously.
Your counter is going down so you need to add step -1 to the end of the line.
indeed ! I (naively) assumed that GCB would deduce the direction from the value it gets.
thanks a lot
You don't need the minus sign but makes it more readable.
quick question : can we use a word as a counter variable ? I've tried but it seems it only counts to 255 and consider any higher value to be equal to 255
Declare a word, integer to long variable and then use this variable.