Homerclese
- 16th October 2005, 21:36
Hello,
One of my simpler PIC projects is basically just a LED sequencer for ports B C & D. Using the code space storage technique I had made a few tests and everything seemed fine. All I had to do was create more patterns, store them in upper code space and write the routines to select and display.
After about the fourth routine things started to fall apart. The execution would just stop. After many hours on this forum I still do not know why this is happening. Do I have some boundary problem or could I be stepping on the program in the codespace somehow? Overflow, underflow, memory problem? ("Well that's almost a sentence.")
As a test, I reduced the code to a linear repeat of the same subs (just labels) starting with chase9 and ending with chase9k. There are no go subs or branch statements. When run this usually, but not always, stops executing at chase9i. It used to stop at chase9G so I removed it but the problem remains, now at a different location. I moved the LED power source to a different one than the pic is using, then removed it completely. I use the debug command for output to my LCD display. Hang a couple of LED's on portB to see activity.
What is going on? Any ideas?
'pic16f877 codespace starts at 6245 tried at 7145 with same results
L var word ' Define loop variable
P var word ' Define pause variable
Q var word ' Define Main variable
QQ var byte ' Define Main variable
REPS var byte
Doagain var byte
PCDataB var byte
PCDataC var byte
PCDataD var byte
define osc 4
PCAddress var WORD ' Used to determine ADDRESS of Data
' within Program Code space
PCData var BYTE ' Data Variable - in this example a BYTE
' but could be a WORD as each memory
' address is capable of storing 14-bits
PCWord var WORD
Define debug_pacing 1000 'serial setup
Define debug_reg porta
Define debug_bit 0
Define debug_baud 2400
Define debug_mode 1 'inverted mode for 232 level
TRISA= %000000
TRISC= %00000000
TRISB= %00000000
TRISD= %00000000
Start:
' the following code groups chase9 through chase9k are all the same
chase9:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9 REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9a:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9a REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9b:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9b REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9c:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9c REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9d:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9d REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9e:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9e REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9f:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9f REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
CODE CONTINUES ON NEXT SCREEN
One of my simpler PIC projects is basically just a LED sequencer for ports B C & D. Using the code space storage technique I had made a few tests and everything seemed fine. All I had to do was create more patterns, store them in upper code space and write the routines to select and display.
After about the fourth routine things started to fall apart. The execution would just stop. After many hours on this forum I still do not know why this is happening. Do I have some boundary problem or could I be stepping on the program in the codespace somehow? Overflow, underflow, memory problem? ("Well that's almost a sentence.")
As a test, I reduced the code to a linear repeat of the same subs (just labels) starting with chase9 and ending with chase9k. There are no go subs or branch statements. When run this usually, but not always, stops executing at chase9i. It used to stop at chase9G so I removed it but the problem remains, now at a different location. I moved the LED power source to a different one than the pic is using, then removed it completely. I use the debug command for output to my LCD display. Hang a couple of LED's on portB to see activity.
What is going on? Any ideas?
'pic16f877 codespace starts at 6245 tried at 7145 with same results
L var word ' Define loop variable
P var word ' Define pause variable
Q var word ' Define Main variable
QQ var byte ' Define Main variable
REPS var byte
Doagain var byte
PCDataB var byte
PCDataC var byte
PCDataD var byte
define osc 4
PCAddress var WORD ' Used to determine ADDRESS of Data
' within Program Code space
PCData var BYTE ' Data Variable - in this example a BYTE
' but could be a WORD as each memory
' address is capable of storing 14-bits
PCWord var WORD
Define debug_pacing 1000 'serial setup
Define debug_reg porta
Define debug_bit 0
Define debug_baud 2400
Define debug_mode 1 'inverted mode for 232 level
TRISA= %000000
TRISC= %00000000
TRISB= %00000000
TRISD= %00000000
Start:
' the following code groups chase9 through chase9k are all the same
chase9:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9 REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9a:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9a REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9b:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9b REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9c:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9c REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9d:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9d REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9e:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9e REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
chase9f:
REPS=0 :QQ=0 :P=10
WHILE REPS <3
Debug 254,1
Debug 254,2
Debug 254,192
Debug " chase9f REPS=",dec reps," QQ= ",dec qq," pp=",dec p
pause 1000
PCAddress=6245
FOR q=0 TO 24
READCODE PCAddress+0,PCDataB
READCODE PCAddress+1,PCDataC
READCODE PCAddress+2,PCDataD
PORTB= PCDatad
PORTC= PCDataC
PORTD= PCDatab
PCAddress=PCAddress+3
pause p
NEXT Q
REPS=REPS+1
qq=qq+1
WEND
pause 500
CODE CONTINUES ON NEXT SCREEN