free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Go to page  [1] 2
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
dtyh
Sun Sep 14 2008, 09:50AM
 User Offline
Registered Member #9781
Joined: Tue Aug 12 2008, 06:30PM

Posts: 14
Thanked 0 times in 0 posts
Hi, can any1 teach me how to setup an interrupt service routine in assembly code?

Back to top


pdi33
Sun Sep 14 2008, 10:08AM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 770
Thanked 185 times in 180 posts
hi dtyh,
the procedure is quite simple:
first determine the vector address of the interrupt service routine u want to process.
e.g. service routine for external interrupt1 is 0013h. now u should add a statement at this origin to jump to the service routine like this

org 13h
sjmp INT1_SR
.
.
.
.

INT1_SR:
.
.
;add ur service routine code here
.
.
reti

note u have to add the reti instruction at the end of the code to make the uC differentiate between the standard subroutines and the interrupt service routines.





* inspired to develop,developing to inspire *
Back to top



This post has been thanked 1 time
 dtyh 
Arun Kumar V
Mon Sep 15 2008, 09:53AM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 522
Thanked 219 times in 186 posts

and don't forget to protect your registers and Accumulator using PUSH ACC and POP ACC.

when switching between register banks use : SETB PSW.3 and/or SETB PSW.4

use one bank for main program and other bank/s for interrupt service routines


Arun
Back to top



This post has been thanked 1 time
 dtyh 
dtyh
Tue Sep 16 2008, 05:34PM
 User Offline
Registered Member #9781
Joined: Tue Aug 12 2008, 06:30PM

Posts: 14
Thanked 0 times in 0 posts
Thanks pdi33 and Arun. Do i need to protect register or Accumulator if i'm not using it in ISR? I'm still learning 8051 and dont know how to switch register bank.
Back to top


Arun Kumar V
Tue Sep 16 2008, 07:03PM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 522
Thanked 219 times in 186 posts

hello dtyh,

even if you are not using ACC or R registers in your ISR, its always a safe practice to protect them. may be you are not using them in your current program but you may be using them in some other future codes.

Switching between Register banks for Main and ISRs is advisable.

ISRs can make or break a embedded design, when then micro executes ISR and jumps back to main loop or the address where it was before interrupt occured, the programmer should ensure the status of important regs and Acc are undisturbed.

also keep in mind to move SP (stack pointer) to a safe location above Register banks and other RAM variables.

MOV SP,#50H should be your first instruction in the code ( 50H can be changed to some other value according to usage)




Arun
Back to top



This post has been thanked 1 time
nischay kumar
Wed Sep 17 2008, 06:18AM
 User Offline
Registered Member #8311
Joined: Sat Jun 07 2008, 11:09AM

Posts: 31
Thanked 3 times in 3 posts


yep, unprotected Acc. and registers create a havoc, i experienced this when i was working on my Digital clock project.

i forgot to move SP above R banks and my variables, this resulted in uncommon behavior.

further i used same registers of bank 1 for main and timer ISR, and after a lot of head scratching i realized my mistake.
Back to top


Freddy
Wed Sep 17 2008, 11:59AM

 User Offline
Registered Member #9399
Joined: Mon Jul 28 2008, 10:01PM

Posts: 38
Thanked 0 times in 0 posts
yeah, this is good. I use this too

and bits like TR0 & TR1 should be protected too to avoid havoc

pdi33 wrote ...

hi dtyh,
the procedure is quite simple:
first determine the vector address of the interrupt service routine u want to process.
e.g. service routine for external interrupt1 is 0013h. now u should add a statement at this origin to jump to the service routine like this

org 13h
sjmp INT1_SR
.
.
.
.

INT1_SR:
.
.
;add ur service routine code here
.
.
reti

note u have to add the reti instruction at the end of the code to make the uC differentiate between the standard subroutines and the interrupt service routines.







[ Edited Wed Sep 17 2008, 12:00PM ]


Build target 'Target 1''
linking...
Program Size: data=8.0 xdata=0 code=709
creating hex file from "Final Year Project"...
"Final Year Project" - 0 Error(s), 0 Warning(s).
Back to top


dtyh
Thu Sep 18 2008, 11:02PM
 User Offline
Registered Member #9781
Joined: Tue Aug 12 2008, 06:30PM

Posts: 14
Thanked 0 times in 0 posts
Hi, one question i want to ask...what address is safe for me to start my main code? As ISRs occupies some vector address.
Back to top


pdi33
Fri Sep 19 2008, 12:02PM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 770
Thanked 185 times in 180 posts
each vector address has three bytes free till u encounter the next vector. So the code can safely start three bytes after the last interrupt vector address. If u do not want to bother with searching for it, use
org 50h


* inspired to develop,developing to inspire *
Back to top


funa
Wed Sep 24 2008, 08:19AM
 User Offline
Registered Member #8083
Joined: Mon May 26 2008, 07:47PM

Posts: 8
Thanked 0 times in 0 posts
Hi , since you are still learning 8051 and you don't know how to switch register bank I would like to suggest to try with Pascal language.

Here you have an example with Turbo51.
http://turbo51.com/documentation/interrupts

Check compiled code in assembler file and you will see what you would have to do in assembly language.

Turbo51 - Free Pascal compiler for 8051
http://turbo51.com
Back to top


Go to page  [1] 2  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems