program crashes: is it my code or the chip?


Results 1 to 16 of 16

Threaded View

  1. #1

    Default program crashes: is it my code or the chip?

    This program works, sometimes for a couple minutes, some times only for a few seconds, but always crashes eventually. I'm using a PIC12F675 and I've read that it is not the most reliable chip. So I'm wondering if there's something wrong with my code or maybe it's the chip. If it were my code, I would think it would be more consistent in the point at which it crashed or simply wouldn't work at all.

    This is what happens:
    Push button1 and its LEDs work perfectly all the time. It's Push button2 that causes the problems. Eventually Push Button2 and its LEDs lock up and will not respond. When this happens, the LEDs associated with Push button1 toggle once. If I press Push button1, this seems to reset Push Button 2, and Push Button 2 and its LEDs will work fine until it locks up again.

    The code for push button2 is identical to push button1, it just uses different variable names and I/Os

    ' Name : BUTTONTEST2.pbp
    ' Compiler : PICBASIC PRO Compiler 3.0
    ' Assembler : PM
    ' Target PIC : 8-pin PIC12F675 or similar type
    ' Hardware : Kee
    ' Oscillator : 4MHz internal
    ' Keywords : HIGH, LOW
    ' Description : use a push button to toggle two LEDs. THere are two push buttons.
    'each push button toggles a separate set of LEDs. Program also debounces


    #config
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
    #endconfig


    Define OSCCAL_1K 1 ' PIC12F675, Calibrate internal oscillatordefine MCLRE_OFF
    define BUTTON_PAUSE 5


    LED Con 0 'Alias GPIO.0 to LED
    LED2 con 1 'Alias GPIO.1 to LED2
    LED3 con 4 'Alias GPIO.4 to LED3
    LED4 con 5 'Alias GPIO.5 to LED4
    PB Var GPIO.2 'Alias GPIO.2(pin 5) to PB(push button1)
    PB2 var GPIO.3 'Alias GPIO.3(pin 4) to PB2(push button2)
    LEDstate var bit 'LED on = 1, LED off = 0
    LEDstate2 var bit 'LED4 on = 1, LED4 off = 0


    ANSEL = 0 'Set all digital
    CMCON = 7 'Analog comparators off
    high LED 'begin with LED on
    low LED2 'begin with LED2 off
    high LED4 'begin with LED4 on
    low LED3 'begin with LED2 off
    LEDstate = 1 'begin with LED recognized as on
    LEDstate2 = 1 'begin with LED4 recognized as off


    main:
    If (PB = 0) and (LEDstate = 1) Then 'push button1 is pressed when LED is on
    low LED 'toggle LED off
    high LED2 'toggle LED2 on
    pause 10 'wait 10ms for debounce
    goto WaitForRelease1 'go to subroutine for releasing push button1
    endif

    if (PB = 0) and (LEDstate = 0) then 'push button1 is pressed when LED is off
    high LED 'toggle LED on
    low LED2 'toggle LED2 off
    pause 10 'wait 10ms for debounce
    goto WaitForRelease2 'go to subroutine for releasing push button1
    Endif

    If (PB2 = 0) and (LEDstate2 = 1) Then 'push button2 is pressed when LED4 is on
    low LED4 'toggle LED4 off
    high LED3 'toggle LED3 on
    pause 10 'wait 10ms for debounce
    goto WaitForRelease3 'go to subroutine for releasing push button2
    endif

    if (PB2 = 0) and (LEDstate2 = 0) then 'push button2 is pressed when LED4 is off
    high LED4 'toggle LED4 on
    low LED3 'toggle LED3 off
    pause 10 'wait 10ms for debounce
    goto WaitForRelease4 'go to subroutine for releasing push button2
    Endif

    goto main


    'subroutines for action upon release of push buttons. Debounces, changes LEDstate() variable,
    'and prevents looping when button is pressed and held


    WaitForRelease1:
    if PB = 1 then 'push button1 is released after toggling LED off
    pause 10 'wait 10ms for debounce
    LEDstate = 0 'recognize LED as off
    endif
    goto main

    WaitForRelease2:
    if PB = 1 then 'push button1 is released after toggling LED on
    pause 10 'wait 10ms for debounce
    LEDstate = 1 'recognize LED as on
    endif
    goto main


    WaitForRelease3:
    if PB2 = 1 then 'push button2 is released after toggling LED4 off
    pause 10 'wait 10ms for debounce
    LEDstate2 = 0 'recognize LED4 as off
    endif
    goto main

    WaitForRelease4:
    if PB2 = 1 then 'push button2 is released after toggling LED4 on
    pause 10 'wait 10ms for debounce
    LEDstate2 = 1 'recognize LED4 as on
    endif
    goto main


    'end of subroutines


    End
    Last edited by keithv; - 24th March 2014 at 16:41.

Similar Threads

  1. PICKit2 just crashes
    By johnbond in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th June 2011, 07:40
  2. Replies: 1
    Last Post: - 22nd May 2011, 19:37
  3. 16f690 crashes
    By Lincoln S. in forum Serial
    Replies: 8
    Last Post: - 26th November 2008, 08:32
  4. Program Code and Program Memory
    By DenFrod in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2007, 14:51
  5. problems reading code from chip
    By leland in forum General
    Replies: 4
    Last Post: - 17th October 2004, 10:42

Members who have read this thread : 0

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