MPLAB IED CODE program running on a PIC32MM Curiosity Development Board.
am trying to have the code below behave as follow Each timer interrupt should change the LEDs to one of the states shown below, in the order shown (go from state 1 to state 2, 2 to 3, 3 to 4, and from 4 back to 1): 1. Both LEDs off 2. LED1 off, LED2 on 3. LED1 on, LED2 off 4. Both LEDs on (return to state 1 after leaving state 4)
the example code
#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, TRISC ## TRISC = 0 --> all PORTC bits = output
sw zero, ANSELC ## ANSELC = 0 --> all PORTC bits digital
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
li t1, _PORTC_RC9_MASK
sw t1, LATCSET
sw t0, LATACLR ## 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
li t1, _PORTC_RC9_MASK
sw t1, LATCINV
sw t0, LATAINV ## Flip LED1
eret ## Return from interrupt
.end isrvector11
Hello
I have more than 15 years of experience in the embedded systems design and pcb design and electronics systems design
So let's discuss your project in chat
Hello,
I am electronics and telecommunication engineer and I am quite experienced in embedded systems design. So far I have used PIC microcontrollers including PIC32MM for many different projects and I am quite sure that I can help you with your project. Just give me all the details and I will do my best to help you.
Best regards