16f628 interrupt on change help

Discussion in 'Embedded Systems and Microcontrollers' started by chrischristian, May 21, 2008.

  1. chrischristian

    Thread Starter Active Member

    Feb 22, 2008
    43
    0
    I'm trying to use IOC (interr. on change) in 628, here is the code which works well on simmulator but not on hardware, what I want to do is that LED # 1 lights continiously as power is switched on and as interrupt occur (RB4 goes HIGH ) LED # 1 gets off and LED # 2 lights on and this remains so untill interrupt is not removed.
    But, what is actually happening is that as interr. occur (RB4 goes high) LED #1 turns off but, LED # 2 doesn't lights up, can't understand whats wrong, please help !

    Code ( (Unknown Language)):
    1.     list p=16f628
    2.         #include<p16f628.inc>
    3.         __CONFIG  _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    4.         ERRORLEVEL   -302
    5.         cblock  0x20
    6.             temp
    7.             temp_s      
    8.         endc
    9. ;******************************************************************
    10.     org 0x00
    11.     goto main
    12. ;***********************************INTERRUPT LOOP*****************
    13.     org 0X04
    14. inter:
    15.         movwf temp
    16.         swapf STATUS,w
    17.         clrf  STATUS
    18.         movwf   temp_s     
    19.         movlw b'10000000'
    20.         movwf PORTA
    21.         btfsc PORTB,0x04
    22.         goto inter
    23.         bcf INTCON,0x00
    24.         swapf temp_s,w
    25.         movwf STATUS
    26.         swapf temp,w
    27.         retfie
    28.  
    29. main:
    30.     bsf INTCON,0x07         ;Globel interrupt enable(we are using interr.)
    31.                
    32.     bsf INTCON,0x03         ;RB4-RB7 interrupt on change is enabled/ in other words these pins will also work as
    33.                             ;interrupts and interrupt will occur every time any of these pin changes state
    34.                             ; i.e.:HIGH to LOW or LOW to HIGH, we can not set it to be on eather one state change      
    35.     bcf INTCON, 0x00        ;Clear RB4-RB7 interrupt flag so, that another interr. can occur.
    36. ;**********************************SET UP THE PORTS *****************
    37.     bsf STATUS,RP0          ;switch to BANK 1
    38.     movlw b'00010001'  
    39.     movwf TRISB             ;set RB0 & RB4 as input
    40.     movlw b'00000000'
    41.     movwf TRISA             ;setPORT A all output
    42.     bcf OPTION_REG,0x07     ; enable weak pull ups on port b/ pull ups mean internal resistors
    43.     bsf OPTION_REG,0x06     ;interuupt on rising age/this is by defoult set
    44.     bcf STATUS,RP0          ;back to BANK  0
    45.     movlw 0x07              ;turn comparators off, so HIGH will be simple
    46.                             ; HIGH rather than +5V (compared to supply) so with the LOW
    47.     movwf CMCON            
    48.  
    49. Loop:
    50.  
    51.     movlw b'00000001'      
    52.     movwf PORTA             ;set pin 0 of port a HIGH
    53.     goto Loop
    54.     END
     
  2. chrischristian

    Thread Starter Active Member

    Feb 22, 2008
    43
    0
    Sorry to bother my bread board is damaged the ckt works good on the other one.
     
Loading...