Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/PIC/!PICbasic/Extras/Interrupt

Apple][e/PD/PIC/!PICbasic/Extras/Interrupt

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras
Filename: Apple][e/PD/PIC/!PICbasic/Extras/Interrupt
Read OK:
File size: 03A3 bytes
Load address: 0000
Exec address: 0000
File contents
Interrupts
==========
Using interrupts on the PIC

If you want to save the status register (recommended), you will need to make
use of the SWaPF f,w instruction which doesn't affect the z flag like MOVF f,w 
does.This is an example of how to start and end to an interrupt service 
routine.Only two source responses are shown for clarity.

.irqhandler
MOVWF irqwork
SWaPF status,W
MOVWF irqstatus

.irqtests
BTFSC timer0flag  \Has timer zero timed out?
GOTO timer0irq  \This is where the handler is
BTFSC deltaBflag  \Was it a port B change interrupt?
GOTO deltaBirq  \This is where the handler is

.irqserviced
SWaPF irqstatus,W
MOVWF status  \Restore 'status'
SWaPF irqwork,F
SWaPF irqwork,W  \Restore 'W',being careful not to damage 'status' register
RETFIE

.timer0irq
\Do something
GOTO irqserviced

.deltaBirq
\Do something
GOTO irqserviced

This should work on the 16C61,16C71,and 16C84,but not on parts with paged
registers.
00000000  49 6e 74 65 72 72 75 70  74 73 0a 3d 3d 3d 3d 3d  |Interrupts.=====|
00000010  3d 3d 3d 3d 3d 0a 55 73  69 6e 67 20 69 6e 74 65  |=====.Using inte|
00000020  72 72 75 70 74 73 20 6f  6e 20 74 68 65 20 50 49  |rrupts on the PI|
00000030  43 0a 0a 49 66 20 79 6f  75 20 77 61 6e 74 20 74  |C..If you want t|
00000040  6f 20 73 61 76 65 20 74  68 65 20 73 74 61 74 75  |o save the statu|
00000050  73 20 72 65 67 69 73 74  65 72 20 28 72 65 63 6f  |s register (reco|
00000060  6d 6d 65 6e 64 65 64 29  2c 20 79 6f 75 20 77 69  |mmended), you wi|
00000070  6c 6c 20 6e 65 65 64 20  74 6f 20 6d 61 6b 65 0a  |ll need to make.|
00000080  75 73 65 20 6f 66 20 74  68 65 20 53 57 61 50 46  |use of the SWaPF|
00000090  20 66 2c 77 20 69 6e 73  74 72 75 63 74 69 6f 6e  | f,w instruction|
000000a0  20 77 68 69 63 68 20 64  6f 65 73 6e 27 74 20 61  | which doesn't a|
000000b0  66 66 65 63 74 20 74 68  65 20 7a 20 66 6c 61 67  |ffect the z flag|
000000c0  20 6c 69 6b 65 20 4d 4f  56 46 20 66 2c 77 20 0a  | like MOVF f,w .|
000000d0  64 6f 65 73 2e 54 68 69  73 20 69 73 20 61 6e 20  |does.This is an |
000000e0  65 78 61 6d 70 6c 65 20  6f 66 20 68 6f 77 20 74  |example of how t|
000000f0  6f 20 73 74 61 72 74 20  61 6e 64 20 65 6e 64 20  |o start and end |
00000100  74 6f 20 61 6e 20 69 6e  74 65 72 72 75 70 74 20  |to an interrupt |
00000110  73 65 72 76 69 63 65 20  0a 72 6f 75 74 69 6e 65  |service .routine|
00000120  2e 4f 6e 6c 79 20 74 77  6f 20 73 6f 75 72 63 65  |.Only two source|
00000130  20 72 65 73 70 6f 6e 73  65 73 20 61 72 65 20 73  | responses are s|
00000140  68 6f 77 6e 20 66 6f 72  20 63 6c 61 72 69 74 79  |hown for clarity|
00000150  2e 0a 0a 2e 69 72 71 68  61 6e 64 6c 65 72 0a 4d  |....irqhandler.M|
00000160  4f 56 57 46 20 69 72 71  77 6f 72 6b 0a 53 57 61  |OVWF irqwork.SWa|
00000170  50 46 20 73 74 61 74 75  73 2c 57 0a 4d 4f 56 57  |PF status,W.MOVW|
00000180  46 20 69 72 71 73 74 61  74 75 73 0a 0a 2e 69 72  |F irqstatus...ir|
00000190  71 74 65 73 74 73 0a 42  54 46 53 43 20 74 69 6d  |qtests.BTFSC tim|
000001a0  65 72 30 66 6c 61 67 20  20 5c 48 61 73 20 74 69  |er0flag  \Has ti|
000001b0  6d 65 72 20 7a 65 72 6f  20 74 69 6d 65 64 20 6f  |mer zero timed o|
000001c0  75 74 3f 0a 47 4f 54 4f  20 74 69 6d 65 72 30 69  |ut?.GOTO timer0i|
000001d0  72 71 20 20 5c 54 68 69  73 20 69 73 20 77 68 65  |rq  \This is whe|
000001e0  72 65 20 74 68 65 20 68  61 6e 64 6c 65 72 20 69  |re the handler i|
000001f0  73 0a 42 54 46 53 43 20  64 65 6c 74 61 42 66 6c  |s.BTFSC deltaBfl|
00000200  61 67 20 20 5c 57 61 73  20 69 74 20 61 20 70 6f  |ag  \Was it a po|
00000210  72 74 20 42 20 63 68 61  6e 67 65 20 69 6e 74 65  |rt B change inte|
00000220  72 72 75 70 74 3f 0a 47  4f 54 4f 20 64 65 6c 74  |rrupt?.GOTO delt|
00000230  61 42 69 72 71 20 20 5c  54 68 69 73 20 69 73 20  |aBirq  \This is |
00000240  77 68 65 72 65 20 74 68  65 20 68 61 6e 64 6c 65  |where the handle|
00000250  72 20 69 73 0a 0a 2e 69  72 71 73 65 72 76 69 63  |r is...irqservic|
00000260  65 64 0a 53 57 61 50 46  20 69 72 71 73 74 61 74  |ed.SWaPF irqstat|
00000270  75 73 2c 57 0a 4d 4f 56  57 46 20 73 74 61 74 75  |us,W.MOVWF statu|
00000280  73 20 20 5c 52 65 73 74  6f 72 65 20 27 73 74 61  |s  \Restore 'sta|
00000290  74 75 73 27 0a 53 57 61  50 46 20 69 72 71 77 6f  |tus'.SWaPF irqwo|
000002a0  72 6b 2c 46 0a 53 57 61  50 46 20 69 72 71 77 6f  |rk,F.SWaPF irqwo|
000002b0  72 6b 2c 57 20 20 5c 52  65 73 74 6f 72 65 20 27  |rk,W  \Restore '|
000002c0  57 27 2c 62 65 69 6e 67  20 63 61 72 65 66 75 6c  |W',being careful|
000002d0  20 6e 6f 74 20 74 6f 20  64 61 6d 61 67 65 20 27  | not to damage '|
000002e0  73 74 61 74 75 73 27 20  72 65 67 69 73 74 65 72  |status' register|
000002f0  0a 52 45 54 46 49 45 0a  0a 2e 74 69 6d 65 72 30  |.RETFIE...timer0|
00000300  69 72 71 0a 5c 44 6f 20  73 6f 6d 65 74 68 69 6e  |irq.\Do somethin|
00000310  67 0a 47 4f 54 4f 20 69  72 71 73 65 72 76 69 63  |g.GOTO irqservic|
00000320  65 64 0a 0a 2e 64 65 6c  74 61 42 69 72 71 0a 5c  |ed...deltaBirq.\|
00000330  44 6f 20 73 6f 6d 65 74  68 69 6e 67 0a 47 4f 54  |Do something.GOT|
00000340  4f 20 69 72 71 73 65 72  76 69 63 65 64 0a 0a 54  |O irqserviced..T|
00000350  68 69 73 20 73 68 6f 75  6c 64 20 77 6f 72 6b 20  |his should work |
00000360  6f 6e 20 74 68 65 20 31  36 43 36 31 2c 31 36 43  |on the 16C61,16C|
00000370  37 31 2c 61 6e 64 20 31  36 43 38 34 2c 62 75 74  |71,and 16C84,but|
00000380  20 6e 6f 74 20 6f 6e 20  70 61 72 74 73 20 77 69  | not on parts wi|
00000390  74 68 20 70 61 67 65 64  0a 72 65 67 69 73 74 65  |th paged.registe|
000003a0  72 73 2e                                          |rs.|
000003a3