SEE ALSO POST BELOW FOR A SHORTER EXAMPLE
18F452, Xtal 8.00MHz, EasyPic3, GLCd 128*64
Problem : structure variable value (pg_mos.decal) is changed after instruction strcat(focaletxt,"mm ")
From code below follow carefully this :
Compile it
Start debugger
Add variables :
- i
- PortA
- pg_acc
- pg_mos
F8 key is pressed while debugging.
Here is below variables to change while debugging
While debugging note that line 62 set pg_mos.decal variable to 2
Line 72 change i value to 5 (to swap loop)
Line 82 change PortA value to 16 (to go to select case 16)
Line 98 change pg_acc.current to 3 (to go to select case 3)
Line 118 change i value to 3 (to swap loop)
Stop on line 127 : strcat(focaletxt,"mm ")
Have a look at pg_mos.decal in debugger window. (value = 2)
Now, if you simulate line 127, pg_mos.decal value is set to 0.
I have checked a dozen time, but found nothing.
Is that a bug ?
Code: Select all
program Tete_pano_Orion
symbol BP_Dr = porta.0
Symbol BP_Ga = porta.1
symbol BP_Ha = porta.2
symbol BP_Ba = porta.3
const pg_acc_nb as byte = 6
Const pg_acc_txt as string[pg_acc_nb][10] = ("Appareil ","Spherique","Pano 360 ","Mosaique ","Interval ","Goto ")
const pg_mos_nb as byte = 4
Const pg_mos_txt as string[pg_mos_nb][10] = ("Orientat :","Focale :","Vitesse :","Rotation :")
structure Tmenu
dim decal as byte
dim Last as byte
dim Current as byte
end structure
dim
someText as string[21]
text1 as string[10]
focaletxt as string[7]
pg_acc, pg_mos as TMenu
i, portrait as byte
focale as word
sub procedure test_portrait
if portrait = 0 then text1 = "Paysage " else text1 = "Portrait" end if
end sub
sub procedure affich_focaletxt(dim normal as byte)
Glcd_Write_Text(focaletxt,64,pg_mos.current + pg_mos.decal,normal)
end sub
sub Procedure affich_page(dim byref nom_page as string[21] )
Glcd_Fill(0x00)
Glcd_Set_Font(@FontSystem5x8, 5, 8, 32)
Glcd_Write_Text(nom_page, 0, 0, 1)
Glcd_H_Line(0, 127, 8, 1)
end sub
sub procedure delay_200ms
delay_ms(200)
end sub
main:
TRISA = $FF
TRISB = 0
TRISC = 0
TRISD = 0
ADCON1 = 7
ADCON0 = 0
CCP1CON = 0
PORTA = 0
Glcd_Init(PORTB, 2, 3, 4, 5, 7, 6, PORTD)
menu:
pg_acc.current = 0
pg_acc.decal = 2
pg_mos.decal = 2 'LINE 62
portrait = 0
focale = 300
pg_accueil:
'Affichage page accueil
affich_page("Tete motorisee 1.00")
i= 0
do
Text1 = pg_acc_txt[i] 'LINE 72
Glcd_Write_Text(Text1,0,pg_acc.decal+i,1)
inc(i)
loop until i = pg_acc_nb
'asm nop end asm
Text1 = pg_acc_txt[pg_acc.current]
Glcd_Write_Text(text1,0,pg_acc.current+pg_acc.decal,0)
pg_acc:
do nop loop until PortA <> 0 'LINE 82
pg_acc.last = pg_acc.current
select case portA
case 4 'haut
dec(pg_acc.current)
if pg_acc.current = 255 then pg_acc.current = pg_acc_nb - 1 end if
case 8 'bas
inc(pg_acc.current)
if pg_acc.current = pg_acc_nb then pg_acc.current = 0 end if
case 16 'entree (bp haut, bas, droit, gauche enfoncés)
select case pg_acc.current
case 1 'page appareil
case 2 'page pano 360
case 3 'mosaique 'LINE 98
goto pg_mosaique
end select
end select
Text1 = pg_acc_txt[pg_acc.last]
Glcd_Write_Text(Text1,0,pg_acc.last+pg_acc.decal,1)
Text1 = pg_acc_txt[pg_acc.current]
Glcd_Write_Text(Text1,0,pg_acc.current+pg_acc.decal,0)
delay_200ms 'delay_ms(200)
do loop until porta = 0
goto pg_acc
pg_mosaique:
affich_page("Mosaique")
i = 0
do
Text1 = pg_mos_txt[i] 'LINE 118
Glcd_Write_Text(text1,0,pg_mos.decal+i,1)
inc(i)
loop until i = pg_mos_nb
test_portrait
Glcd_Write_Text(text1,64,pg_mos.decal,0)
pg_mos.current = 0
wordtostr(focale,focaletxt)
strcat(focaletxt,"mm ") 'LINE 127
Glcd_Write_Text(focaletxt,64,pg_mos.decal+1,1)
'Glcd_Write_Text(focaletxt,64,3,1)
pg_mos:
select case pg_mos.current
case 0 'orientation
do loop until PortA <> 0
select case portA
case 1, 2 'portrait, paysage
portrait = not(portrait)
test_portrait
Glcd_Write_Text(text1,64,pg_mos.decal,0)
case 4 'haut
pg_mos.current = pg_mos_nb+1
Glcd_Write_Text(text1,64,pg_mos.decal,1)
Glcd_Write_Text(" ",64,pg_mos.current,0)
case 8 'bas
test_portrait
Glcd_Write_Text(text1,64,pg_mos.decal,1)
inc(pg_mos.current)
affich_focaletxt(0)
case 16 'validation, retour page precedente
pg_acc.current = 3
goto pg_accueil
end select
delay_200ms 'delay_ms(200)
do loop until porta = 0
case 1 'focale
do loop until PortA <> 0
select case portA
case 1, 2'plus focale
if porta = 1 then focale = focale + 2 else focale = focale - 2 end if
WordToStr(focale,focaletxt)
affich_focaletxt(0)
strcat(focaletxt,"mm ")
delay_ms(75)
case 4 'haut
affich_focaletxt(1)
dec(pg_mos.current)
test_portrait
Glcd_Write_Text(text1,64,2,0)
delay_200ms 'delay_ms(200)
do loop until porta = 0
case 8 'bas
affich_focaletxt(1)
inc(pg_mos.current)
Glcd_Write_Text(" ",64,pg_mos.current + 2,0)
delay_200ms 'delay_ms(200)
do loop until porta = 0
case 16 'validation, retour page precedente
pg_acc.current = 3
goto pg_accueil
end select
end select
goto pg_mos
end.