Crashing 16F628 Code


Closed Thread
Results 1 to 4 of 4
  1. #1
    hhaplant's Avatar
    hhaplant Guest

    Default Crashing 16F628 Code

    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.

    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 ?

  2. #2
    Join Date
    Nov 2008
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Crashing 16F628 Code

    What compiler are you using? That looks like PDS code.
    This is a Picbasic forum.
    Regards
    CharlieM
    Using PBP3
    MCSPX

  3. #3
    Join Date
    Nov 2008
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Crashing 16F628 Code

    well what meant was that is is a forum for PBP and not PDS.
    Regards
    CharlieM
    Using PBP3
    MCSPX

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Crashing 16F628 Code

    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts