• AVR Freaks

PIC24 Timer interrupts in assembly

Author
Cypress
Starting Member
  • Total Posts : 42
  • Reward points : 0
  • Joined: 2014/07/30 14:01:07
  • Location: 0
  • Status: offline
2014/07/30 21:28:40 (permalink)
0

PIC24 Timer interrupts in assembly

I'm new to assembly programming.  I'm working with the PIC24EP512GP202 microcontroller.  So far, I've figured out how to do some simple things in assembly; however, I haven't figured out how to implement a timer interrupt service routine in assembly.  Can someone please post a simple assembly example program that uses a timer interrupt to toggle an output pin for a PIC24EP512GP202?
 
 
#1
BobAGI
Super Member
  • Total Posts : 1708
  • Reward points : 0
  • Joined: 2011/03/09 00:04:35
  • Location: Texas and Sweden
  • Status: offline
Re: PIC24 Timer interrupts in assembly 2014/07/31 06:50:24 (permalink)
4 (2)
You should confine yourself to one thread for any particular topic.
You have already posted another thread: http://www.microchip.com/forums/m812360.aspx#812360
Same topic, almost same wording.....

--
Bo B
Sweden & Texas
 
#2
Cypress
Starting Member
  • Total Posts : 42
  • Reward points : 0
  • Joined: 2014/07/30 14:01:07
  • Location: 0
  • Status: offline
Re: PIC24 Timer interrupts in assembly 2014/07/31 09:34:31 (permalink)
3 (1)
The only reason I posted twice was that the moderator didn't approve my first message for several hours, so I thought the first message had not gone through. (I have satellite internet service and I often experience connection problems during rain storms.) Sorry about that.
 
 
#3
kelvinu
Super Member
  • Total Posts : 263
  • Reward points : 0
  • Joined: 2007/06/16 08:07:32
  • Location: 0
  • Status: offline
Re: PIC24 Timer interrupts in assembly 2014/08/15 18:50:45 (permalink)
4 (1)
Cut from one of my projects running at 16mips . gives a 1 second "heartbeat"
24f16ka102
Add the global dec laration below for the timer
 
;********Global Dec larations: ***********************************************
 
        .global __reset              ;The label for the first line of code.
        .global __T1Interrupt    ;Dec lare Timer 1 ISR name global
 
;************************************************
 
in your chip setup code, set up your timer
 
;********************** ;setup timer 1 for 1msec interrupts
clr TMR1                   ;clear timer 1 
mov #200,w12         ;setup intcounter for WD LED 
mov w12,intcounter  ;save countdown value 
mov #16000,w7       ;16000=1000usec at 16 mips 1khz  
mov W7,PR1             ;set timer 1 time out period when PR1=TMR1=T1 interupt
bclr IFS0,#T1IF        ;clear t1 interupt flag IFS0,#T1IF 
bset IEC0,#T1IE       ;set interupt enable IEC0,#T1IE 
bset T1CON,#TON     ;turn on t1 16 bit timer
;**********************************************************************
 
some where else add the below ISR
 
;****************************************************************
;flashes led for heartbeat
;Timer 1 Interrupt Service Routine
;Example context save/restore in the ISR performed using PUSH.D/POP.D
;instruction. The instruction pushes two words W4 and W5 on to the stack on
;entry into ISR and pops the two words back into W4 and W5 on exit from the ISR
;or push.s/pop.s for just w0-3 and SR
 
__T1Interrupt: 
push.s                    ;save w0-3 
dec intcounter         ;dec counter 
btss SR,#Z              ;if not zero do nothing 
bra intcnotzero      
btg LATB,#LED         ;toggle LED  
mov #500,w0           ;reset counter w0 has been pushed into shadow 
mov w0,intcounter     ;
 
intcnotzero: 
bclr  IFS0, #T1IF         ;Clear the Timer 1 Interrupt flag Status bit. 
pop.s                         ;restore w0-3 
retfie                         ;Return from Interrupt Service routine
;***************************************************
#4
kelvinu
Super Member
  • Total Posts : 263
  • Reward points : 0
  • Joined: 2007/06/16 08:07:32
  • Location: 0
  • Status: offline
Re: PIC24 Timer interrupts in assembly 2014/08/15 18:59:24 (permalink)
0
goto
 
www.tcuts.co.uk and look for projects. there are a couple of assembly listings there that might get you going. assembly on the pic24/30/33 is an uphill struggle to start with as there are so few exampls out there, but once you get the idea of the how the assembler likes things it's not to hard.
 
 
#5
MBedder
Circuit breaker
  • Total Posts : 6754
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
Ian.M
Super Member
  • Total Posts : 13225
  • Reward points : 0
  • Joined: 2009/07/23 07:02:40
  • Location: UK
  • Status: offline
Re: PIC24 Timer interrupts in assembly 2014/08/23 21:14:37 (permalink)
0
Continues at: http://www.microchip.com/forums/m817417.aspx
(O.P. had posting problems in this thread)

--
NEW USERS: Posting images, links and code - workaround for restrictions.
I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
#7
Jump to:
© 2019 APG vNext Commercial Version 4.5