That looks like a bug in GCBASIC. STATUS.Z isn't set or cleared properly, so the if used to check if the loop should be run doesn't work. I'll fix this in the next version of GCBASIC.
The "while true" is not necessary. This code will generate more efficient assembly:
do
.
Instructions
.
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Vinas, the sintax for the Do While loop is correct...repeat all steps between the Do While instruction and the Loop instruction, while the condition remain true.
Kent, like said in my first post, the code works if I use a varialbe equal to one for Do While testing purpose.
Anyway Hugh, what you suggested (do....loop) works perfectly.
Here is the code:
'Software PWM
'PORTC.2 drive a LED
'this loop do a simple PWM
'with variable duty cycle
'causing a progressive LED illumination
#chip 16F690,4
#config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF
#Define LED1 PORTC.2
ANSEL=0
Forever=1
cont=0
level=0
i=0
' Main routine
DIR PORTC b'00000000' 'PORTC as output
PORTC = b'00000000' 'PORTC to 0
do
if cont>level then SET LED1 OFF
if cont<=level then SET LED1 ON
cont=cont+1
i=i+1
if i=200 then
level=level+1
i=0
end if
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've just tried a never ending loop using:
Do while true
.
Instructions
.
Loop
It doesn't work at all...the solution is to set a variable to one and use it for testing purpose like this:
Forever=1
do while Forever=1
.
Instructions
.
loop
Any idea ?
I think that your piece of code:
Do while true
.
Instructions
.
Loop
is not correct, simply due to the GCBASIC syntax.
vinas
The Do While Loop compiles and runs fine. Look at your Pic initialization and instructions as these are suspect. Are you getting compilation errors?
Kent
That looks like a bug in GCBASIC. STATUS.Z isn't set or cleared properly, so the if used to check if the loop should be run doesn't work. I'll fix this in the next version of GCBASIC.
The "while true" is not necessary. This code will generate more efficient assembly:
do
.
Instructions
.
loop
Hi Vinas, the sintax for the Do While loop is correct...repeat all steps between the Do While instruction and the Loop instruction, while the condition remain true.
Kent, like said in my first post, the code works if I use a varialbe equal to one for Do While testing purpose.
Anyway Hugh, what you suggested (do....loop) works perfectly.
Here is the code:
'Software PWM
'PORTC.2 drive a LED
'this loop do a simple PWM
'with variable duty cycle
'causing a progressive LED illumination
#chip 16F690,4
#config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF
#Define LED1 PORTC.2
ANSEL=0
Forever=1
cont=0
level=0
i=0
' Main routine
DIR PORTC b'00000000' 'PORTC as output
PORTC = b'00000000' 'PORTC to 0
do
if cont>level then SET LED1 OFF
if cont<=level then SET LED1 ON
cont=cont+1
i=i+1
if i=200 then
level=level+1
i=0
end if
loop