16f628 interrupt on change help

Thread Starter

chrischristian

Joined Feb 22, 2008
43
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 !

Rich (BB code):
	list p=16f628
		#include<p16f628.inc>
		__CONFIG  _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
		ERRORLEVEL   -302
		cblock	0x20
			temp 
			temp_s      
  		endc
;******************************************************************
	org 0x00
	goto main
;***********************************INTERRUPT LOOP*****************
	org 0X04
inter:
		movwf temp
		swapf STATUS,w
		clrf  STATUS
		movwf	temp_s		
		movlw b'10000000'
		movwf PORTA
		btfsc PORTB,0x04
		goto inter
		bcf INTCON,0x00
		swapf temp_s,w
		movwf STATUS
		swapf temp,w
		retfie

main:
	bsf	INTCON,0x07			;Globel interrupt enable(we are using interr.)
				
	bsf INTCON,0x03			;RB4-RB7 interrupt on change is enabled/ in other words these pins will also work as
							;interrupts and interrupt will occur every time any of these pin changes state
							; i.e.:HIGH to LOW or LOW to HIGH, we can not set it to be on eather one state change  		
	bcf INTCON, 0x00		;Clear RB4-RB7 interrupt flag so, that another interr. can occur.
;**********************************SET UP THE PORTS *****************
	bsf	STATUS,RP0			;switch to BANK 1
	movlw b'00010001'	
	movwf TRISB				;set RB0 & RB4 as input
	movlw b'00000000'
	movwf TRISA				;setPORT A all output
	bcf OPTION_REG,0x07		; enable weak pull ups on port b/ pull ups mean internal resistors
	bsf OPTION_REG,0x06		;interuupt on rising age/this is by defoult set
	bcf STATUS,RP0			;back to BANK  0
	movlw 0x07				;turn comparators off, so HIGH will be simple
							; HIGH rather than +5V (compared to supply) so with the LOW
	movwf CMCON				

Loop:

	movlw b'00000001'		
	movwf PORTA				;set pin 0 of port a HIGH
	goto Loop
	END
 

Attachments

Top