Simple program - Strange problem!


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Exclamation Simple program - Strange problem!

    Hi

    PIC used: 12F635

    In my code:
    GP 0,1,2 are outputs
    GP 5,4,3 are inputs.
    Two outputs are latching (GP 0,1 ) and third one (GP2) stays on for 5 seconds only

    The problem
    The latching part is not working fine. When GP5 is pressed, GP0 goes high but it doesn't go low when GP5 is pressed again - instead it goes low when GP4 is pressed ! GP4 - GP1 pair work fine by themself- when GP4 is pressed once GP1goes high and when GP4 if pressed again - GP1 goes low.

    My code is attached - Please help if you can:
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Break up your delays into shorter PAUSE times so it can react to each interrupt faster, and
    don't mess with INTCON.7 when using ON INTERRUPT.

    PBP places a RETURN at location 4 (hardware interrupt vector), so INTCON.7 gets left clear
    and this lets PBP know an interrupt needs to be serviced.

    INTCON.7 is automatically set on return from your interrupt handler. If you set INTCON.7 in
    your code, after ON INTERRUPT is used, PBP assumes the interrupt has already been
    serviced.

    See if this helps;
    Code:
    DEFINE    NO_CLRWDT 1
    DEFINE    OSC 4
    Include "modedefs.bas"
    led VAR gpio.1
    i VAR BYTE
    X VAR WORD
    
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _BOD_ON & _CPD_ON & _IESO_OFF & _FCMEN_ON & _WUREN_OFF
    main:
      ' Initialize the processor
      TRISIO = %111000
      GPIO = 0     
      CMCON0 = 7   
      INTCON=128
      OPTION_REG =%10000111  ' RAPU = off, PS 1:256 to TMR0 (overflows in 256*256*1uS) 65.536 mS
      pcon.5=0
      pie1=0
      t1con.0=0
      i=0
    
    ON INTERRUPT GOTO start
    
    pause 50
    
    check:
    if gpio.5=1 then ' Takes GP0 high BUT not low
    toggle gpio.0
     'pause 300      ' TMR0 will overflow long before this PAUSE is finished
    FOR X = 1 TO 300 ' 300mS PAUSE in 1mS increments
       PAUSE 1
    NEXT X
    while gpio.5
    pause 1
    wend
    endif
    
    if gpio.4=1 then ' Independently working fine BUT also takes low gp.0 if it's high only
    toggle gpio.1
     'pause 300      ' TMR0 will overflow long before this PAUSE is finished
    FOR X = 1 TO 300 ' 300mS PAUSE in 1mS increments
       PAUSE 1
    NEXT X
    while gpio.4
    pause 1
    wend
    endif
    
    if gpio.3=1 then
    gpio.2=1
     'pause 100      ' TMR0 will overflow long before this PAUSE is finished
    FOR X = 1 TO 100 ' 100mS PAUSE in 1mS increments
       PAUSE 1
    NEXT X
    while gpio.3
    pause 1
    wend
    TMR0=0
    INTCON.5 = 1	' enable TMR0 overflow interrupt
    endif
    
    goto check
    
    disable
    start:
    i=i+1
    INTCON.2=0   ' clear TMR0 overflow interrupt flag bit
    if i=77 then
    gpio.2=0
    i=0
    ' INTCON=128 ' INTCON.7 gets set on return from here
    endif       
    resume
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Hey Bruce, Now if GP1 is high, and gp0 is activated via gp4, it gets high and goes low after 2 seconds appx.
    If GP1 is LOW, activating GP0 via gp4 makes it high but not low.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Where is GPIO.0 activated by GPIO.4?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    So Sorry, My Mistake, need a redbull. I will correct my sentence:
    " If GP1 is high, and gp0 is activated via gp5, it gets high and goes low after 2 seconds appx.
    If GP1 is LOW, activating GP0 via gp5 makes it high but not low"

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Can't say what would cause that. Programmed a 12F635 here, and it works just as
    expected per the code example above.

    LEDs on GPIO.0, 1 and 2, and buttons on GPIO.3, 4 and 5 with pull-down resistors, and
    button presses taking inputs high.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Talking Thanks

    Thanks Bruce. It was the PCB track getting short. It's working fine now.

Similar Threads

  1. INT interrupt problem
    By netstranger.nz in forum General
    Replies: 5
    Last Post: - 13th October 2009, 07:52
  2. Strange behaviour of my PBP code.
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th August 2009, 20:20
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. PIC18F4525 & LCD simple code problem
    By aggie007 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd November 2007, 16:29
  5. Strange problem with PBP 2.50
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th October 2007, 20:45

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