473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Assembly Code with Interrupts

105 100+
I have to modify this assembly code in order to make it use interrupts. Right now, when I push button 1 on the microprocessor the count increments once (the LED's count in binary, using only 3 LED's and only counting to 7 in binary). The second button on the microprocessor, when pushed, resets the count. I have the addreses for both button in the code.

However, my trouble is modifying this code. I HAVE to use interrupts. I need a lot of help with this!! I don't even know where to start putting the code in for this!! The interrupts are supposed to be timer interrupts and when they happen, use a poll to count up or count down. I guess I'm supposed to have code in there that enables them??

Here's my working code right now with NO interrupts...



;This program is a binary debouncing counter. Each press of switch 1 will count forward in binary with the board LEDs. Once count 8 is reached, the counter will reset itself back to count/state 0. At any time, switch 2 can be pressed to fully reset the counter.

gaddr equ fe8H ; Port G address register
gddr equ fe9H ; Port G data direction register
gout equ febH ; Port G output register
eaddr equ fe0H ; Port E address register
eddr equ fe1H ; Port E data direction register
eout equ fe3H ; Port E output register
din equ fdeH ; Port D input register
fin equ fe6H ; Port D input register
reg equ ffdH ; Working register set
sphi equ ffeH ; Stack pointer high
splo equ fffH ; Stack pointer low

org 002H ; Initializing the reset vector
start:
dw 0038H ; Restart at this address
org 038H ; Start in first available memory location

ldx reg, #00H ; Select working register set
ldx splo, #20H ; Set low byte of stack pointer
ldx sphi, #02H ; Set high byte of stack pointer
reset:
ldx r4, #00H ; Set register to state counter of 0

call initLED ; Access both DDRs and make all bits outputs
call allOff ; Turn off all LEDs
endless:
call delay ; Delay for debouncing the switch

SW1:
ldx r1, din ; Load r1 with SW1's value
and r1, #08H ; See if the switch was pressed
jp ne, SW2 ; If switch was not pressed do not increment the state
inc r4 ; Increment state if pressed

N1:
cp r4, #1 ; Switch (r4) ?= 1
jp ne, N2 ; If not equal, check next number
call allOff ; Turn off all LEDs
call oneOn ; LED: 001
call latchClk ; Latch clock for LED
jp caseOut ; break
N2:
cp r4, #2 ; Switch (r4) ?= 2
jp ne, N3 ; If not equal, check next number
call allOff ; Turn off all LEDs
call twoOn ; LED: 010
call latchClk ; Latch clock for LED
jp caseOut ; break
N3:
cp r4, #3 ; Switch (r4) ?= 3
jp ne, N4 ; If not equal, check next number
call allOff ; Turn off all LEDs
call threeOn ; LED: 011
call latchClk ; Latch clock for LED
jp caseOut ; break
N4:
cp r4, #4 ; Switch (r4) ?= 4
jp ne, N5 ; If not equal, check next number
call allOff ; Turn off all LEDs
call fourOn ; LED: 100
call latchClk ; Latch clock for LED
jp caseOut ; break
N5:
cp r4, #5 ; Switch (r4) ?= 5
jp ne, N6 ; If not equal, check next number
call allOff ; Turn off all LEDs
call fiveOn ; LED: 101
call latchClk ; Latch clock for LED
jp caseOut ; break
N6:
cp r4, #6 ; Switch (r4) ?= 6
jp ne, N7 ; If not equal, check next number
call allOff ; Turn off all LEDs
call sixOn ; LED: 110
call latchClk ; Latch clock for LED
jp caseOut ; break
N7:
cp r4, #7 ; Switch (r0r4) ?= 7
jp ne, N8 ; If not equal, check next number
call allOff ; Turn off all LEDs
call sevenOn ; LED: 111
call latchClk ; Latch clock for LED
jp caseOut ; break
N8:
cp r4, #8 ; Switch (r4) ?= 8
jp eq, reset ; If 8, reset

caseOut: ; End of case

SW2:
ldx r1, fin ; See what Switch 2 is doing
and r1, #40H ; See if the switch was pressed
jp nz, waitLoop; If switch was not pressed do not reset
jp reset ; Reset if the switch was pressed

;-----------------------------

initLED:
ldx eaddr, #01H; select Port E DDR in address register
ldx eddr, #00H ; make all pins outputs
ldx gaddr, #01H; select port G DDR in address register
ldx gddr, #00H ; make all pins outputs
ret
waitLoop:
ldx r1, din ; Load r1 with SW1's value
and r1, #08H ; See if the switch was pressed
jp z, waitLoop; If switch is still pressed, loop again
jp endless
delay:
ld r2, #05H ; initialize r2 = 10
outer:
clr r0 ; set r0 = 0000H for maximum possible delay
clr r1 ; set r1 = 0000H for maximum possible delay
inner:
decw rr0 ; decrement rr0 (inner loop)
jp ugt, inner ; !=0, continue inner loop
dec r2 ; decrement r2 (outer loop)
jp ugt, outer ; !=0, continue outer loop
ret
oneOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1EH; enable the rightmost column
ret ; LED: 00001
twoOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1DH; enable the rightmost - 1 column
ret ; LED: 00010
threeOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1CH; enable the rightmost and rightmost -1 column
ret ; LED: 00011
fourOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1BH; enable the rightmost - 2 column
ret ; LED: 00100
fiveOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1AH; enable the rightmost- 2 and rightmost column
ret ; LED: 00101
sixOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #19H ; enable the rightmost-2 and rightmost1column
ret ; LED: 00110
sevenOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #18H ; enable the rightmost2,1,& rightmost column
ret ; LED: 00111
latchClk:
orx eout, #80H; drive D1's latches' clock high
andx eout, #7fH ; drive D1's latches' clock low
ret
allOff:
ldx gout, #00H ; disable all rows
ldx eout, #1fH ; disable all columns
orx eout, #e0H ; drive 3 Port E clocks high
andx eout, #1fH ; drive 3 Port E clocks low
orx gout, #80H ; drive 1 Port G clock high
andx gout, #7fH ; drive 1 Port G clock low
ret
Oct 16 '07 #1
4 4235
Banfa
9,065 Expert Mod 8TB
You have not even said which processor you are using. Processor architecture particularly with reference to interrupts differs wildly from processor to processor.

For example I am currently working on 2 difference microprocessors

A PIC18F2620 which has 2 interrupt vectors at 8H and 18H which all peripherals are routed through.

ECOG1K which has 40 odd interrupt vectors one for each peripheral plus several exception traps located in the address range 4H - 40H


Generally what happens on most microprocessors when an interrupt occurs is the current processor state is saved to the stack and then the processor jumps (vectors) to a fixed location in memory. This location normally contains either the address of the function to run to handle the interrupt or a branch instruction to the function to run to handle the interrupt. These are the interrupt vectors.

You will need to check your processors datasheet/manual and the manual of the assembler you are using. Between these 2 documents you will normally find all the information required to configure and handle your interrupts and if you are lucky some example code.
Oct 17 '07 #2
sicarie
4,677 Expert Mod 4TB
Moving to Misc Discussions. (I missed the C/C++ in there, but please feel free to move it back if it was in there.)
Oct 17 '07 #3
Banfa
9,065 Expert Mod 8TB
I think the C/C++ connection is that almost all embedded C/C++ programmers have to do a little assembly too for a few low level drivers/functions, like for instance interrupt handling.
Oct 17 '07 #4
sicarie
4,677 Expert Mod 4TB
I think the C/C++ connection is that almost all embedded C/C++ programmers have to do a little assembly too for a few low level drivers/functions, like for instance interrupt handling.
I would agree with that (though I personally didn't remember enough to follow all of it, I could still get the gist ;), but anyone else looking for help or reference with Assembly (without knowledge of C/C++) would be more likely to start out in the Misc Forum. (Well, they'd probably be most likely to start on Google, but...)
Oct 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Galbu | last post by:
Hi All, please could you look at this code? int main() { __asm { mov ah,01h int 21h } return 0; }
9
by: Sweety | last post by:
hello, Is there any code using interrupts . bye
8
by: Peter Gummer | last post by:
I want to perform some initialisation when an assembly is first loaded. I know about static constructors, but that's not what I want. A class's static constructor is not called until something...
85
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C...
0
by: AlanL | last post by:
I am using MSCOMM for serial control and have an issue with some computers. When the handshake lines (CD, DSR, etc )are not connected on the computer I they generate OnComm events. I can ignore the...
2
by: Eirik Midttun | last post by:
I have seen quite a few times that C programs contain a file named isr.c or files named a_isr.c, b_isr.c where a and b are hardware that generate interrupts. Obviously these files contain code to...
0
by: dhruba.bandopadhyay | last post by:
Am using Borland C++ 4.5 for the old dos.h APIs. It appears that newer versions of compilers stop support for the oldskool DOS routines. Am trying to convert/port an oldskool Pascal program that...
1
by: JKaur | last post by:
hello frnds, please tell me the difference between DOS interrupts and interrupts invoked using int86() function in C (are those 8086 intrupts?). In some text i have read these are different, but...
2
by: Hendrik van Rooyen | last post by:
Fredrik Lundh <fredr...ware.comwrote: Could one get there using ctypes to disable interrupts? Cross Platform? I can think of lots of hassles, starting with permissions to use the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.