code freezes after one run
Posted: Fri Dec 09, 2016 7:09 pm
this code freezes up after one run through the code but only when using battery power. runs fine if the pickit2 still connected.using an 18F24K20 pic const array has 112 bytes. compiler says 512 bytes program bytes used and 42 variables. I am thinking its a memory issue?? but it should still freeze w/ pickit2 being connected.
Code: Select all
DIM RedLEDs AS PORTb
DIM GreenLEDs AS PORTa
DIM Anodes AS PORTC
DIM GreenBuffer(8) AS BYTE
DIM RedBuffer(8) AS BYTE
DIM x AS BYTE
DIM ScrollingTextOffset AS WORD
DIM ScrollingTextSpeed AS BYTE
DIM DefaultScrollingTextSpeed AS BYTE
SUB UpdateScrollingText()
IF ScrollingTextSpeed <> 0 THEN
DEC(ScrollingTextSpeed)
ELSE
ScrollingTextSpeed = DefaultScrollingTextSpeed
INC(ScrollingTextOffset)
IF ScrollingTextOffset >= (BOUND(RedData)-7) THEN ' we need to check if we have reached the start of the last eight columns of data that's why we take away 8
ScrollingTextOffset = 0
ENDIF
ENDIF
END SUB
SUB SaveGraphics()
FOR x = 0 TO 7
''GreenBuffer(x) = GreenData(x + ScrollingTextOffset)
RedBuffer(x) = RedData(x + ScrollingTextOffset)
NEXT
END SUB
SUB DisplayGraphics()
FOR x = 0 TO 7
''GreenLEDs = GreenBuffer(x) XOR %11111111
RedLEDs = RedBuffer(x) XOR %11111111
Anodes.bits(7 - x) = 1
DELAYUS(520)
Anodes.bits(7 - x) = 0
NEXT
END SUB
SetAllDigital
TRISA = %00000000 ' PORTA outputs
TRISB = %00000000 ' PORTB outputs
TRISC = %00000000 ' PORTC outputs
'TRISD = %00000000 ' PORTC outputs
'TRISE = %00000001 ' PORTC outputs except pin 0
// Start Of Program
OSCCON = %01100000 ' Internal oscillator running at 8mHz
'OSCTUNE.bits(6) = 1 ' enable PLL so we can run this thing at 32Mhz
//GreenLEDs = %00000000 ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
RedLEDs = %00000000 ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
Anodes = %00000000
ScrollingTextOffset = 0
DefaultScrollingTextSpeed = 45
ScrollingTextSpeed = DefaultScrollingTextSpeed
// Main Loop
WHILE True() // This creates an infinite loop
UpdateScrollingText
SaveGraphics
DisplayGraphics