Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

## EECE.

3170: Microprocessors I
## UMass Lowell
## Instructor: M. Geiger
## intTest1.S: in-class example to demonstrate PIC interrupt basics
## Basically same as timerTest.S but using timer interrupts

// Including xc.h allows use of SFR names, bit masks, etc.


#include <xc.h>

// Interrupt vector setup


.globl __vector_dispatch_11 ## Timer 1 interrupt = vector #11
.section .vector_11, code, keep
.align 2
.set nomips16
.ent __vector_dispatch_11
__vector_dispatch_11:
j isrvector11 ## Jump to actual ISR code, which is in text
section
nop
.end __vector_dispatch_11
.size __vector_dispatch_11, .-__vector_dispatch_11

// Start of text section


.text ## Text section contains code
.set noreorder ## Disable instruction reordering
.globl main ## Define main label as a global entity
.ent main ## and an entry point

main:

// Configure port A for output


sw zero, TRISA ## TRISA = 0 --> all PORTA bits = output
sw zero, ANSELA ## ANSELA = 0 --> all PORTA bits digital
li t0, _PORTA_RA0_MASK ## $t0 = 0x00000001
sw t0, LATASET ## Set Port A, bit 0 (turn LED1 on)

// Configure Timer 1
sw zero, T1CON ## Clear T1CON--disables timer to allow
setup

ori t1, zero, 0xFFFF ## Set t1 = 0xFFFF = initial PR1 value


sw t1, PR1 ## (maximum possible clock period--65,535
cycles)

li t2, _IFS0_T1IF_MASK ## t2 = bit mask for checking Timer


1 interrupt flag

## Prescale clock
li t3, _T1CON_TCKPS1_MASK ## Prescale by factor of 64 (TCKPS = 10)
sw t3, T1CONSET

// Configure interrupts
lui t3, 0x0001 ## Want INTCON bit 16 (VS<0>) = 1
## so vectors 8 bytes apart
ori t3, t3, _INTCON_MVEC_MASK ## Enable multivectored interrupt mode
sw t3, INTCON

li t3, _IPC2_T1IP_MASK ## Set T1 interrupt priority level


to 7
sw t3, IPC2 ## Implicitly sets subpriority level to 0

sw t2, IEC0 ## Enable Timer 1 interrupts (uses


## same bit mask as T1 interrupt flag)

ei ## Enable interrupts globally

li t3, _T1CON_TON_MASK ## Enable Timer 1 by setting "ON"


bit in T1CON
sw t3, T1CONSET

// Main loop--whole lotta nothing, just waiting for interrupt


mainloop:
j mainloop
nop
.end main

// Handle Timer1 interrupt--clear interrupt flag and toggle LED


.global isrvector11
.ent isrvector11
isrvector11:
li t2, _IFS0_T1IF_MASK
sw t2, IFS0CLR ## Clear T1IF in software!
li t0, _PORTA_RA0_MASK ## $t0 = 0x00000001
sw t0, LATAINV ## Flip LED1

eret ## Return from interrupt


.end isrvector11

You might also like