PDA

View Full Version : Crashing 16F628 Code



hhaplant
- 23rd March 2012, 15:42
Hi,

My microcontroller stops working within 24 hours. When i reset it, it works again for 24 hours.
I tried several things but i cannot see what i am doing wrong in the code.



DEVICE 16F628A ;Gebruik een 16F628A type
CONFIG HS_OSC, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_OFF
ALL_DIGITAL TRUE ;Alle ingangen digitaal
XTAL 20 ;Kristal van 20MHz

HSERIAL_BAUD = 2400 ' Set baud rate to 2400
HSERIAL_RCSTA = %10010000 ' Enable serial port and continuous receive
HSERIAL_TXSTA = %00100000 ' Enable transmit and asynchronous mode
HSERIAL_CLEAR = ON ' Optionally clear the buffer before receiving
PORTB_PULLUPS ON ;On-chip pull-up weerstanden actief

; 76543210
PORTA = %00000000 ;Alle niveaus van PORTA eerst laag maken
PORTB = %00000000 ;Alle niveaus van PORTB eerst laag maken
TRISA = %00000000 ;Alle PORTA poorten omschakelen als ingang
TRISB = %11111111 ; 1 = Input 0 = Output

;Logische constanten
SYMBOL K1 = PORTA.2
SYMBOL S1 = PORTB.7
SYMBOL S2 = PORTB.6

DIM SerData AS BYTE
DIM Opdracht AS BYTE
DIM S1_Status AS BIT
DIM S2_Status AS BIT

S1_Status = 0
S2_Status = 0

CLEAR ;Wis alle RAM geheugen

HSEROUT["Program Started"]
MainProgram:

WHILE 1 = 1 ;Oneindige lus

IF S1 = 0 THEN ;S1 is Ingedrukt
IF S1_Status = 1 THEN
HSEROUT["11"]
S1_Status = 0
ENDIF
ELSE
IF S1_Status = 0 THEN
HSEROUT["10"]
S1_Status = 1
ENDIF
ENDIF

IF S2 = 0 THEN ;S1 is gesloten.
IF S2_Status = 1 THEN
HSEROUT["21"]
S2_Status = 0
ENDIF
ELSE
IF S2_Status = 0 THEN
HSEROUT["20"]
S2_Status = 1
ENDIF
ENDIF

HSERIN 10, timeout,[DEC SerData]

SELECT SerData
CASE 10
LOW K1
CASE 11
HIGH K1
CASE 12
HIGH K1
DELAYMS 50
LOW K1
END SELECT

WEND

timeout:
GOTO MainProgram

END ;Einde programma


Who can help me ?

c_moore
- 23rd March 2012, 15:52
What compiler are you using? That looks like PDS code.
This is a Picbasic forum.

c_moore
- 23rd March 2012, 21:18
well what meant was that is is a forum for PBP and not PDS.

Archangel
- 24th March 2012, 09:40
While not PBP, it is similar enough to understand, I would ask 2 questions, what happens to the select case statement if not any of those choices?
In PBP we have a case else where you can direct what is to happen, does your compiler automatically jump to end select if there is no match, or does it run out into La La Land, stack under / overflow sit and wait for help . . . ?
The other thing I might try is to enable the WDT.