Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupt on RBO pic16f628a

Status
Not open for further replies.

birdman0_o

Active Member
Hey guys I can't get my code working perhaps one of you guys can find the fault

The interrupt's purpose will change however for now it just shines an led. There is a tri colour led attached, PWM is enabled.

Code:
;***************************************************************
;
; Reciever!
;
;***************************************************************
	LIST	p=16F628a
	#INCLUDE	<p16F628a.inc>
	__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF &_INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
	ERRORLEVEL	-302
;***************************************************************
	CBLOCK	0x20			; Delay files d1, d2 and d3 are at 20h, 21h and 22h
	d1
	d2
	d3
	count1
	count2
	count3
	ENDC
	ORG	0x0000
	GOTO	Init
	ORG	0x004
	GOTO	Int
Init
	MOVLW	H'07'			; Turn off comparators
	MOVWF	CMCON			; ^
	CLRF	PORTA			; All pins low
	CLRF	PORTB			; All pins low
	BSF	STATUS,RP0		; Select bank 1
	MOVLW	B'00011000'		; Pin ,4,5 input
	MOVWF	TRISA			; Move to tris a
	MOVLW	B'00000001'
	MOVWF	TRISB			; Port b is output except pin rb0 (interupt)
	BCF	STATUS,RP0		; Select bank 0
;**** ENABLE EXTERNAL INTERRUPT ON RB0
	CLRF	INTCON
	BSF	OPTION_REG,NOT_RBPU
	BSF	OPTION_REG,INTEDG
	BSF	INTCON,PEIE
	BSF	INTCON,INTE		; Set rbo as int
	BSF	INTCON,GIE		; Turn on interrupts     gei
;******************************************
	CALL	Set_timer
	GOTO	Main
Int
	BCF	INTCON,INTF
	MOVLW	B'00000000'
	MOVWF	PORTB
	CALL	Delay1
	RETFIE
; Blue = b'00100100'
; Red =  b'00000110'
; Green= b'00100010'
Main
	MOVLW	B'00100010'
	MOVWF	PORTB
	CALL	Fade
	MOVLW	B'00100100'
	MOVWF	PORTB
	CALL	Fade
	MOVLW	B'00000110'
	MOVWF	PORTB
	CALL	Fade
	GOTO	Main
Fade
	CALL	Pause
	MOVLW	0x02
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x10
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x40
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x80
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0xFF
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x80
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x40
	MOVWF	CCPR1L
	CALL	Pause
	MOVLW	0x10
	MOVWF	CCPR1L
	RETURN
Pause	
	MOVLW	0x02
	MOVWF	count3
D6	
	MOVLW	0x3F
	MOVWF	count1
D4	
	MOVLW	0xFA
	MOVWF	count2
D5	
	DECFSZ	count2,F
	GOTO	D5
	DECFSZ	count1,F
	GOTO	D4
	DECFSZ	count3,F
	GOTO	D6
	RETLW	0x00
;*********************************************************
Delay1
	MOVLW	0x0B0
	MOVWF	d1
	MOVLW	17h
	MOVWF	d2
	MOVLW	0x02
	MOVWF	d3
Delay2
	DECFSZ	d1,F
	GOTO	$+2
	DECFSZ	d2,F
	GOTO	$+2
	DECFSZ	d3,F
	GOTO	Delay2
	GOTO	$+1
	GOTO	$+1
	GOTO	$+1
	RETLW	D'00'			; 499994 cycles
;***************************************************************
Set_timer				; Pwm period = (pr2+1)*4*tosc [1*10^-6] * tmr2 prescale value [16]
	CLRF	T2CON			; Pwm high  =  (ccpr1l+ccp1x+ccp1y(10bits)) * tosc [1*10^-6] * tmr2 prescaler value
	CLRF	TMR2
	CLRF	INTCON
	BSF	STATUS,RP0
	CLRF	PIE1
	BCF	STATUS,RP0
	CLRF	PIR1
	BSF	STATUS,RP0
	MOVLW	0xFF
	MOVWF	PR2			; Compare with 255
	BCF	STATUS,RP0
	MOVLW	0x02
	MOVWF	CCPR1L
	MOVLW	0x03
	MOVWF	T2CON			; Prescaler 1:16 and postscaler 1:1
	MOVLW	0x3C
	MOVWF	CCP1CON
	BSF	T2CON,TMR2ON
	RETURN
;*********************************


Thanks,

Mike
 
Last edited:
Like this birdman. OK :)

EDIT: the clear INTCON in the Set_Timer subr kills the Interrupts.....

Code:
;************************************************* **************    
;
; Reciever!  
;
;************************************************* **************    
	list	p=16F628a
#INCLUDE <p16F628a.inc>  
	__config _CP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF &_INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
	errorlevel -302
;************************************************* **************    
	cblock	0x20		; Delay files d1, d2 and d3 are at 20h, 21h and 22h
d1
d2
d3
count1
count2
count3
	endc
	org	0x0000
	goto	Init
	org	0x004
	goto	Int
Init
	movlw	H'07'		; Turn off comparators
	movwf	CMCON		; ^
	clrf	PORTA		; All pins low
	clrf	PORTB		; All pins low
	bsf	STATUS,RP0	; Select bank 1
	movlw	B'00011000'	; Pin ,4,5 input
	movwf	TRISA		; Move to tris a
	movlw	B'00000001'
	movwf	TRISB		; Port b is output except pin rb0 (interupt)
	bcf	STATUS,RP0	; Select bank 0
;**** ENABLE EXTERNAL INTERRUPT ON RB0    
	clrf	INTCON
	bsf	OPTION_REG,NOT_RBPU
	bsf	OPTION_REG,INTEDG
	bsf	INTCON,PEIE
	bsf	INTCON,INTE	; Set rbo as int
	bsf	INTCON,GIE	; Turn on interrupts gei
;******************************************    
	[COLOR="Red"]call	Set_timer[/COLOR]
	goto	Main
Int
	bcf	INTCON,INTF
	movlw	B'00000000'
	movwf	PORTB
	call	Delay1
	retfie
; Blue = b'00100100'    
; Red = b'00000110'    
; Green= b'00100010'    
Main
	movlw	B'00100010'
	movwf	PORTB
	call	Fade
	movlw	B'00100100'
	movwf	PORTB
	call	Fade
	movlw	B'00000110'
	movwf	PORTB
	call	Fade
	goto	Main
Fade
	call	Pause
	movlw	0x02
	movwf	CCPR1L
	call	Pause
	movlw	0x10
	movwf	CCPR1L
	call	Pause
	movlw	0x40
	movwf	CCPR1L
	call	Pause
	movlw	0x80
	movwf	CCPR1L
	call	Pause
	movlw	0xFF
	movwf	CCPR1L
	call	Pause
	movlw	0x80
	movwf	CCPR1L
	call	Pause
	movlw	0x40
	movwf	CCPR1L
	call	Pause
	movlw	0x10
	movwf	CCPR1L
	return
Pause
	movlw	0x02
	movwf	count3
D6
	movlw	0x3F
	movwf	count1
D4
	movlw	0xFA
	movwf	count2
D5
	decfsz	count2,F
	goto	D5
	decfsz	count1,F
	goto	D4
	decfsz	count3,F
	goto	D6
	retlw	0x00
;************************************************* ********    
Delay1
	movlw	0x0B0
	movwf	d1
	movlw	17h
	movwf	d2
	movlw	0x02
	movwf	d3
Delay2
	decfsz	d1,F
	goto	$+2
	decfsz	d2,F
	goto	$+2
	decfsz	d3,F
	goto	Delay2
	goto	$+1
	goto	$+1
	goto	$+1
	retlw	D'00'		; 499994 cycles
;************************************************* **************    
Set_timer 			; Pwm period = (pr2+1)*4*tosc [1*10^-6] * tmr2 prescale value [16]  
	clrf	T2CON		; Pwm high = (ccpr1l+ccp1x+ccp1y(10bits)) * tosc [1*10^-6] * tmr2 prescaler value
	clrf	TMR2
	[COLOR="DarkOrange"]clrf	INTCON[/COLOR]
	bsf	STATUS,RP0
	clrf	PIE1
	bcf	STATUS,RP0
	clrf	PIR1
	bsf	STATUS,RP0
	movlw	0xFF
	movwf	PR2		; Compare with 255
	bcf	STATUS,RP0
	movlw	0x02
	movwf	CCPR1L
	movlw	0x03
	movwf	T2CON		; Prescaler 1:16 and postscaler 1:1
	movlw	0x3C
	movwf	CCP1CON
	bsf	T2CON,TMR2ON
	return
;*********************************
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top