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 rightmost1colum n
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
4 4253 Banfa 9,065
Recognized Expert Moderator Expert
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.
sicarie 4,677
Recognized Expert Moderator Specialist
Moving to Misc Discussions. (I missed the C/C++ in there, but please feel free to move it back if it was in there.)
Banfa 9,065
Recognized Expert Moderator Expert
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.
sicarie 4,677
Recognized Expert Moderator Specialist
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...)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Galbu |
last post by:
Hi All, please could you look at this code?
int main()
{
__asm
{
mov ah,01h
int 21h
}
return 0;
}
|
by: Sweety |
last post by:
hello,
Is there any code using interrupts .
bye
|
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 uses the class at run
time. That may be too late.
What I'm actually trying to do is hook up a TraceListener so that calls
to Debug.Assert will throw an exception inside NUnit unit tests.
Because the DefaultTraceListener just pops up a dialog...
|
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 standard. My
question now is:
Is there a chance that such statement will become a part of C standard
in the future? In some cases using asm language is the best way to
acomplish some small task, hence integration of C and asm would greatly
enhence C,...
|
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 Oncomm events but the constand calling of the OnComm consumes a huge number of machine cycles and bogs the computer down. If I connect the pins to a valid RS232 voltage then the interrupts stop and everything is happy. This did not occur in...
| |
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 be executed
on interrupts and is most common in embedded application.
My own preference is a different one. If I write a scheduler that uses
a timer, I would keep the timer interrupt code together with the code
that does the initialisation, adds...
|
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 uses registers/
interrupts into C/C++.
1. What are the inline($FA); & inline($FB); Pascal functions? What is
the C/C++ equivalent?
inline($CD / $1C);
inline($9C);
|
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 how??
Do IRQs overlap between two types of interrupts or not?
|
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 privileged instructions.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |