Intcon,gie

Status
Not open for further replies.

RMIM

Member
I know you have to reset (via software) T0IF,INTF and RBIF as it says so in the data sheet (16f628a).

My program is not working: I have noticed that bit GIE is reverting back to 0, is this normal? Do I have to set this back to 1 in software?

edit: my code is now working with an extra BSF INTCON,GIE. but where does it say in the data sheet this must be reset. or why is mine reverting back to 0

thanks.
 
Last edited:
Hi,

From the Datasheet, the only thing I know, that can turn off the GIE is your own code, BCF GIE or a RESET.

A Global Interrupt Enable bit, GIE (INTCON<7>)
enables (if set) all un-masked interrupts or disables (if
cleared) all interrupts. Individual interrupts can be
disabled through their corresponding enable bits in
INTCON register. GIE is cleared on Reset.

Possibly you are turning off the GIE bit when you are setting or clearing other INTCON bits.

Post your code then we can see ...
 
Post your code then we can see ...



I'm trying to learn how interrupts work. The circuit now works, it flashes the LED (7sec on 7sec off), but im sure the code is messy and I cant understand why INTCON bit 7 is reverting back to O.

Code:
LIST	p=16F628a		;tell assembler what chip we are using
	include "P16F628a.inc"		;include the defaults for the chip

	

	;cblock 
		counter1 equ 20h
		counter2 equ 21h
		counter3 equ 22h
	;endc

	org 000h
	GOTO SETUP

	org 004h
	GOTO INTERRUPT


SETUP:
	;;;;;;;;;;;;;;BANK 1 BELOW;;;;;;;;;;;;;;

	BSF STATUS,5 ;BANK 1

	BSF OPTION_REG,7 ;RBPU: PORT B PULL UPS 1=OFF 0=ON
	BCF OPTION_REG,6 ;INTEDG: INTERRUPT EDGE
	BCF OPTION_REG,5 ;T0CS: BIT5 CLOCK SOURCE, EXTERNAL = 1  INTERNAL CYCLE = 0
	BCF OPTION_REG,4 ;T0SE: EDGE TRIGGER FOR EXTERNAL TRIGGER
	BCF OPTION_REG,3 ;PSA: ASSIGNS PRESCALER TO Timer0=0 watch dog=1
	BsF OPTION_REG,2 ;PS2:
	BsF OPTION_REG,1 ;PS1:
	BsF OPTION_REG,0 ;PS0: pre-scaler


	movlw 	b'00000000'		
   	movwf 	TRISB			;set PortB INPUTS/OUTPUTS
	movlw 	b'00000000'
	movwf	TRISA			;set PortA INPUTS/OUTPUTS

	;;;;;;;;;;;;;;BANK 0 BELOW;;;;;;;;;;;;;;

	BCF STATUS,RP0 ;BANK 0

	BSF INTCON,GIE 	;Enable general interrupts GIE=bit 7
	BCF INTCON,PEIE ;bit6 PERIPHERAL INTERRUPTS
	BSF INTCON,T0IE	;bit5 TMR0 OVERFLOW INTERRUPT 1=ENABLE
	BCF INTCON,INTE	;bit4 EXTERNAL INTERRUPT RB0 1=ON 0=OFF
	BCF INTCON,RBIE ;bit3 PORT CHANGE RB INTERRUPT 0=OFF
    BCF INTCON,T0IF ;bit2 TMR0 OVERFLOW INTERRUPT FLAG, MUST BE CLEARED IN SOFTWARE
	BCF INTCON,INTF ;bit1 EXTERNAL INTERRUPT FLAG
	BCF INTCON,0	;bit0 RB <7:4> pin have changed state = 1 (must be cleared in software)




RESETreg:

		
	MOVLW d'1'
	MOVWF TMR0 ;Timer0 starting point, writing this will start timer after two ins. cyc.
	BCF INTCON,T0IF

	MOVLW d'75' ;
	MOVWF counter1
	movwf counter2


INTERRUPT:
	
	BCF INTCON,T0IF ;reset flag
	BSF INTCON,GIE ;I HAVE ADDED THIS EXTRA LINE AND NOW IT WORKS
	MOVLW d'1'
	MOVWF TMR0
	btfss counter1,0
	goto bit1
	goto ON
	
bit1:
	btfss counter1,1
	goto bit2
	goto ON
	
bit2:
	btfss counter1,2
	goto bit3
	goto ON
	
bit3:
	btfss counter1,3
	goto bit4
	goto ON
	
bit4:
	btfss counter1,4
	goto bit5
	goto ON
	
bit5:
	btfss counter1,5
	goto bit6
	goto ON

bit6:
	btfss counter1,6
	goto bit7
	goto ON
	
bit7:
	btfss counter1,7
	goto OFF
	goto ON




ON:

	MOVLW b'11111111'
	MOVWF PORTA
	MOVWF PORTB

	BCF INTCON,T0IF
	MOVLW d'1'
	MOVWF TMR0

	DECFSZ counter1,f
	goto wait
	goto OFF

	

OFF:
	MOVLW b'00000000'
	MOVWF PORTB
	MOVWF PORTA

	BCF INTCON,T0IF

	DECFSZ counter2,f
	RETFIE
	goto RESETreg





wait:

	BCF INTCON,T0IF
	nop
    nop
	goto wait





	end
 

If RESETreg is called.. you never retfie so GIE will not be set.
 
Hi,

Yup , there are a lot of classic stater problems there, but don't worry, we all make them

First do look up that 16F628ATEMP.asm file which shows how the Interrupts should be set up.
Its a complicted proceedure but have a go first as there is too much for me to guide you though.

You set up all your lower Interrpupt bits first, then you set the GIE as the last thing before your main code runs.

Have a look at these examples in these turorials https://www.gooligum.com.au/tutorials.html
and of course Nigels own
 
So I have to use retfie somewhere or GIE goes back to 0?

GIE is cleared when the interrupt is called to prevent an interrupt interrupting your interrupt The RETFIE instruction sets GIE again and exits the handler.

Here is a good bit of reading and a LED demo using interrupts.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…