Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

timer0 interrupt 16F877A [AssemblY]

Status
Not open for further replies.

azhari24

Newbie level 6
Joined
Oct 30, 2011
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,348
hey friend, i want to use Timer0 interrupt in PIC16F877A. how to calculate delay interrupt?
i want get delay 8ms with internal clock(4ms). Can you help me?

this is my program with delay 8ms interrupt, but can't be run.
Code:
MULAI:					; BEGINNING OF THE MAIN PROGRAM
	BSF		STATUS,5		; INITIALIZATION PORT B
	MOVLW	B'11111100'		; SET THE FIRST TWO BITS OF PORT C AS OUTPUT
	MOVWF	TRISC

	BSF		TRISB,0			; SET THE BIT 0 OF PORT B AS INPUT/ SET PORT INTERRUP

	BCF		OPTION_REG,INTEDG ; SET RISING EDGE
	BCF		INTCON,INTF		; RESET INTERRUPT FLAG OF INT
	BSF 	INTCON,INTE		; SET IEBIT OF INT
	BSF 	INTCON,GIE		; SET GLOBAL INT ENABLE

; INITIALIZATION OF TIMER0
	MOVLW	0X04
	MOVWF	OPTION_REG		; T0 PRESCALE, TIMER, 1:32
	MOVLW	D'6'			;SET COUNT FOR 6
	MOVWF	TMR0			; 
	MOVLW	0xA0				; ENABLE T0 AND GLOBAL INTS
	MOVWF	INTCON	
	CLRF	FLAGS

INT_SERVICE:
	MOVWF	W_TEMP		; SAVE  W AND STATUS REGISTERS
	SWAPF	STATUS,W
	MOVWF	STATUS_T

	MOVLW	D'6'			; RESET COUNT FOR 156
	MOVWF	TMR0			
	BCF		INTCON,T0IF		; RESET T0 INT FLAGS
	BSF		FLAGS,0			; SET USER FLAG; INT OCCURS

	;CALL	SEND_USB
	MOVLW	00H
	MOVWF	RDorWR

	BCF		INTCON,INTF
	SWAPF	STATUS_T,W	; RESTORE W AND STATUS REGISTERS
	MOVWF	STATUS
	SWAPF	W_TEMP,F
	SWAPF	W_TEMP,W

	RETFIE
 

Why not use C? It makes life so much easier!
 

True - but assembly language is mre fun!

I think the real problem with your code is the addresses it is located at. The interrupt vector is fixed at 0x0004 but without specifying any addresses or relocation information, I'm guessing the interrupt either isn't turned on or if it is, jumps to the wrong code.

Start your program with ORG 0 then immediately GOTO your intitialization code MULAI. Then add ORG 0x0004 and put your existing INT_SERVICE code there. You can then freely add your other routines, including MULAI after the interrupt routines. Like this:

ORG 0x0000
goto mulaii

ORG 0x0004
<INT_SERVICE routine here>

mulai:
<remaining code here>

Also read about using 'pagesel' and 'banksel' it will help you keep track of the page selecting bits in the STATUS register.

Brian.
 

Why not use C? It makes life so much easier!

I want to get a more precise time. so I use assembly code. thank you for your suggestion....:grin:

---------- Post added at 18:50 ---------- Previous post was at 18:23 ----------

True - but assembly language is mre fun!

I think the real problem with your code is the addresses it is located at. The interrupt vector is fixed at 0x0004 but without specifying any addresses or relocation information, I'm guessing the interrupt either isn't turned on or if it is, jumps to the wrong code...............

Brian.

this is my addresses information.
Code:
	ORG 	0000H
	GOTO	MULAI			; JUMP TO MAIN PROGRAM		
	ORG		0004H			; INTERRUPT VECTOR AREA
	GOTO	INT_SERVICE

i will try your suggestion. thank you...

okey i will tray
 

Good luck :) Currently I am also working on a PIC16F, but Im using C !
 

If you put the interrupt routine itself at address 0004, it will be entered automatically without having to 'goto' somewhere else. It saves an address/instruction and avoids the risk of your ISR crossing a page boundary which unless you are very carefull WILL cause you problems.

The easiest way to start a program is to copy the MPLAB template for that device and then add your code to it. This sets the addresses and creates the ISR save/restore routines for you.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top