Announcement

Collapse
No announcement yet.

Pbp interrupt on change problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pbp interrupt on change problem

    Hi everyone i am confused because i couldn't manage running my code i want to run my keyboard by interrupt on chance.I am using 16f1939 mcu and buttons are set as 4x2 matrix.Rows are rb4 and rb5 ports.Coloumns are rb0 to rb3.(up swıtch,downswıtch ,left , rıght,menu, backlight,etc.I have to use them in device menu so they are not relevant with routine operation.(i want to mean i have to use ioc)but there is no chance my device resarts and restarts again.
    here is a part of my programme
    DEFINE OSC 16
    anselA=0
    anselB=0
    anselD=0
    anselE=0

    trisA = %00100001 'TV LEVEL INPUT ,BATT_CHECK
    trisB = %00010000 'RW1,RW2
    trisE = %00000000
    trisC = %00000000 'SET AS OUTPUT
    TRISD = %00000000 'SET AS OUTPUT
    OSCCON = %01111010 'Internal OSC=16Mhz
    INTCON = %10001000
    IOCBP = %00001111
    IOCBN = %00010000 'IOC B PORT DOWN EDGE IS INTERRUPT ACTIVATED ON PORTB.4
    OSCTUNE= %00011111 'SET FOR MAX OSC

    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    DEFINE LCD_DREG PORTD 'LCD data port
    DEFINE LCD_DBIT 0 'LCD data starting bit 0
    DEFINE LCD_RSREG PORTD 'LCD register select port
    DEFINE LCD_RSBIT 4 'LCD register select bit
    DEFINE LCD_EREG PORTD 'LCD enable port
    DEFINE LCD_EBIT 6 'LCD enable bit
    DEFINE LCD_COMMANDUS 2000 'Set data delay time in us
    DEFINE LCD_DATAUS 50 'DATA DELAY
    DEFINE LCD_LINES 2 'SET LINES ON LCD
    low PORTD.5 'LCD WRITE CONDITION
    LOW PORTB.4
    SW1 var byte
    SW2 var byte
    SW3 var byte
    SW4 var byte
    SW5 var byte
    SW6 var byte
    SW7 var byte
    SW8 var byte
    BACK_LIGHT VAR PORTD.7
    AGC_LED VAR PORTA.2
    LOCK_LED VAR PORTA.4
    CHANNEL VAR BYTE
    ADVAL VAR WORD
    VOLTAGE VAR WORD
    VOLTAGE_INT VAR BYTE
    VOLTAGE_DEC VAR byte
    ON INTERRUPT goto SWITCH_HANDLE 'ACTIVE WHEN INTERRUPT OCCURS
    DISABLE
    SWITCH_HANDLE:
    HIGH LOCK_LED
    'BUTTON_SELECT:
    portb=%00101111
    if portb.0=0 then SW1 = 1
    if portb.1=0 then SW2 = 1
    if portb.2=0 then SW3 = 1
    if portb.3=0 then SW4 = 1
    '******* 2.satır taraması ******
    portb=%00011111
    ' portb.4 e 0 değeri verilerek 1.satır taraması gerçekleştirilir
    ' buna göre portb.0,1,2,3 deki durum gözlenir.
    ' Eğer bu butonlardan birine basıldıysa ilgili buton değişkeni 1 yapılır.
    if portb.1=0 then SW5 = 1
    if portb.2=0 then SW6 = 1
    'INTCON = %10001000
    IOCBF = %00000000
    RESUME
    ENABLE
    IF SW1 = 1 THEN GOTO UP
    IF SW2 = 1 THEN GOTO DOWN
    UP:
    SW1=0
    HIGH AGC_LED
    IF CHANNEL = 21 THEN
    CHANNEL = 21
    ELSE
    CHANNEL = CHANNEL + 1
    ENDIF
    GOTO DIVIDER_SET

    DOWN:
    SW2=0
    HIGH AGC_LED
    IF CHANNEL > 7 THEN
    CHANNEL = CHANNEL - 1
    ENDIF
    GOTO DIVIDER_SET

    LEFT:
    SW3=0
    LCDOUT $FE,$1,"TURNED RIGHT "
    PAUSE 500
    GOTO READ_ADC

    RIGHT:
    SW4=0
    HIGH AGC_LED
    LCDOUT $FE,$1,"TURNED LEFT "
    PAUSE 500
    GOTO READ_ADC
    SWITCHES:
    SW1=0:SW2=0:SW3=0:SW4=0:SW5=0:SW6=0:SW7=0:SW8=0
    RETURN
    '*******************************************************************************
    END_SW:
    '***************PROGRAM END*****************************************************
    END

  • #2
    Your program doesn't have a Main loop.

    Execution will "Fall into" the interrupt routine, then reset at the RESUME statement since there was no interrupt.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

    Comment

    Working...
    X