                        .module lab2mv15.c
                        .area data
 0000           _rticount::
 0000                   .blkb 2
                        .area idata
 0000 0000              .word 0
                        .area data
                        .area text
 0000           _RTIhandler::
 0000           ; /**********************************
 0000           ; 	Nick Sitarski
 0000           ; 	Vladi Gergov
 0000           ; 	Lab 2
 0000           ; 	ECE 473 W 2003
 0000           ; 	Professor Shaout
 0000           ; 	Master
 0000           ; **********************************/
 0000           ; 
 0000           ; #include <HC11.h>
 0000           ; #include <stdio.h>
 0000           ; #include <VECTOR.H>
 0000           ; 
 0000           ; /*********************************
 0000           ; 	EQUATES
 0000           ; **********************************/
 0000           ; 
 0000           ; #define	RTIF		0x40
 0000           ; #define	DELAY		30000
 0000           ; 
 0000           ; /**********************************
 0000           ; 	BIT MASK
 0000           ; **********************************/
 0000           ; 
 0000           ; #define	bit0		0x01
 0000           ; #define	bit1		0x02
 0000           ; #define	bit2		0x04
 0000           ; #define	bit3		0x08
 0000           ; #define	bit4		0x10
 0000           ; #define	bit5		0x20
 0000           ; #define	bit6		0x40
 0000           ; #define	bit7		0x80
 0000           ; 
 0000           ; /**********************************
 0000           ; 	GLOBAL VARIABLES
 0000           ; **********************************/
 0000           ; 
 0000           ; unsigned int rticount=0;		/* Global variable to count the number of times the RTI interrupt has happend */
 0000           ; unsigned int switchon;			/* FLAG used to know when a switch has been pressed */
 0000           ; unsigned char dummy; 			/* Dummy variable to  clear the SPIF flag */
 0000           ; 
 0000           ; /**********************************
 0000           ; 	PRAGMA DEFINES
 0000           ; **********************************/
 0000           ; 
 0000           ; #pragma interrupt_handler RTIhandler()
 0000           ; #pragma interrupt_handler TOC5handler()
 0000           ; #pragma interrupt_handler TIC1handler()
 0000           ; #pragma interrupt_handler TIC2handler()
 0000           ; #pragma interrupt_handler TIC3handler()
 0000           ; 
 0000           ; /**********************************
 0000           ; 	FUNCTION PROTOTYPES
 0000           ; **********************************/
 0000           ; 
 0000           ; void OCoffICon( void );
 0000           ; void OConICoff( void );
 0000           ; 
 0000           ; /*************************************************************
 0000           ; Function: RIThandler
 0000           ; Purpose: This interrupt is used to toggle the status LDE of the
 0000           ; master board every one second.
 0000           ; Inputs: None
 0000           ; Outputs: None
 0000           ; **************************************************************/
 0000           ; 
 0000           ; void RTIhandler(void){
 0000           ; 	if((TFLG2&0x4F)!=0x40)	/* Illegal interrupt detection */
 0000           	; vol
 0000 F61025            ldab 0x1025
 0003 C44F              andb #79
 0005 C140              cmpb #64
 0007 2701              beq L4
 0009           ;               asm("swi");                     /* If illegal interrupt detected exit */
 0009 3F                        swi
 000A           
 000A           L4:
 000A           ; 	TFLG2=RTIF;				/* Acknowledge by clearing ( set to clear ) RTIF */
 000A C640              ldab #64
 000C F71025            stab 0x1025
 000F           ;       if(rticount==30){               /* If count reaches 30 then     toggle status LED and reset count */
 000F FC0000            ldd _rticount
 0012 1A83001E          cpd #30
 0016 2610              bne L6
 0018           ;               rticount=0;
 0018 CC0000            ldd #0
 001B FD0000            std _rticount
 001E           ;               PORTA^=bit6;            /* Toggle PORTD pin 1 which strobes the LED */
 001E                   ; vol
 001E F61000            ldab 0x1000
 0021 C840              eorb #64
 0023 F71000            stab 0x1000
 0026           ;       }
 0026 2009              bra L7
 0028           L6:
 0028           ; 	else
 0028           ; 		rticount++;			/* Otherwise increment the counter */
 0028 FC0000            ldd _rticount
 002B C30001            addd #1
 002E FD0000            std _rticount
 0031           L7:
 0031           ; }
 0031           L3:
 0031                   .dbline 0 ; func end
 0031 3B                rti
 0032           _TOC5handler::
 0032           ; 
 0032           ; /*************************************************************
 0032           ; Function: TOC5handler
 0032           ; Purpose: This interrupt occurs after any switch is pressed
 0032           ; 		 to avoid reading signal while the switch is bouncing.  The
 0032           ; 		 interrupt inables the IC interupts and disables the OC interupts
 0032           ; 		 for the next time the switch is pressed.
 0032           ; Inputs: None
 0032           ; Outputs: None
 0032           ; **************************************************************/
 0032           ; 
 0032           ; void TOC5handler(void){
 0032           ; 	printf("\nWaiting for switch debounce...");
 0032 CC0182            ldd #L9
 0035 BD0000            jsr _printf
 0038           ;       OCoffICon();                    /* Arm IC dissarm OC5 */
 0038 BD00B6            jsr _OCoffICon
 003B           ;       TFLG1=(bit0|bit1);              /* Clear the ICFlags */
 003B C603              ldab #3
 003D F71023            stab 0x1023
 0040           ;       }
 0040           L8:
 0040                   .dbline 0 ; func end
 0040 3B                rti
 0041           _TIC1handler::
 0041           ; 
 0041           ; /*************************************************************
 0041           ; Function: TIC1handler
 0041           ; Purpose: This interrupt occurs after switch one is pressed
 0041           ; 		 The interrupt enables OC5 for debouncing and dissables
 0041           ; 		 IC interupts.  Additionally, it sets the global variable
 0041           ; 		 switchon to the corresponding switch code 1 for switch one
 0041           ; 		 2 for switch two and 4 for switch three.
 0041           ; Inputs: None
 0041           ; Outputs: None
 0041           ; **************************************************************/	
 0041           ; 	
 0041           ; void TIC1handler(void){
 0041           ; 	OConICoff();			/* turn OC interupt on and IC interupts off */
 0041 BD00C6            jsr _OConICoff
 0044           ;       TOC5=TCNT+DELAY;                /* reschedule the OC5 interrupt */
 0044                   ; vol
 0044 FC100E            ldd 0x100e
 0047 C37530            addd #30000
 004A FD101E            std 0x101e
 004D           ;       TFLG1=bit3;                             /* Reset the OC5 flag */
 004D C608              ldab #8
 004F F71023            stab 0x1023
 0052           ;       switchon=bit0;                  /* Set the global variable with the switch pressed code */
 0052 CC0001            ldd #1
 0055 FD0001            std _switchon
 0058           ;       
 0058           ;       printf("\nSwitch 1 Pressed");
 0058 CC0170            ldd #L11
 005B BD0000            jsr _printf
 005E           ;       }
 005E           L10:
 005E                   .dbline 0 ; func end
 005E 3B                rti
 005F           _TIC2handler::
 005F           ; 
 005F           ; /*************************************************************
 005F           ; Function: TIC2handler
 005F           ; Purpose: This interrupt occurs after switch two is pressed
 005F           ; 		 The interrupt enables OC5 for debouncing and dissables
 005F           ; 		 IC interupts.  Additionally, it sets the global variable
 005F           ; 		 switchon to the corresponding switch code 1 for switch one
 005F           ; 		 2 for switch two and 4 for switch three.
 005F           ; Inputs: None
 005F           ; Outputs: None
 005F           ; **************************************************************/	
 005F           ; 	
 005F           ; void TIC2handler(void){
 005F           ; 	OConICoff();			/* turn OC interupt on and IC interupts off */
 005F BD00C6            jsr _OConICoff
 0062           ;       TOC5=TCNT+DELAY;                /* reschedule the OC5 interrupt */
 0062                   ; vol
 0062 FC100E            ldd 0x100e
 0065 C37530            addd #30000
 0068 FD101E            std 0x101e
 006B           ;       TFLG1=bit3;                             /* Reset the OC5 flag */
 006B C608              ldab #8
 006D F71023            stab 0x1023
 0070           ;       switchon=bit1;                  /* Set the global variable with the switch pressed code */
 0070 CC0002            ldd #2
 0073 FD0001            std _switchon
 0076           ;       
 0076           ;       printf("\nSwitch 2 Pressed");
 0076 CC015E            ldd #L13
 0079 BD0000            jsr _printf
 007C           ;       }
 007C           L12:
 007C                   .dbline 0 ; func end
 007C 3B                rti
 007D           _TIC3handler::
 007D           ; 
 007D           ; /*************************************************************
 007D           ; Function: TIC3handler
 007D           ; Purpose: This interrupt occurs after switch three is pressed
 007D           ; 		 The interrupt enables OC5 for debouncing and dissables
 007D           ; 		 IC interupts.  Additionally, it sets the global variable
 007D           ; 		 switchon to the corresponding switch code 1 for switch one
 007D           ; 		 2 for switch two and 4 for switch three.
 007D           ; Inputs: None
 007D           ; Outputs: None
 007D           ; **************************************************************/	
 007D           ; 
 007D           ; void TIC3handler(void){
 007D           ; 	OConICoff();			/* turn OC interupt on and IC interupts off */
 007D BD00C6            jsr _OConICoff
 0080           ;       TOC5=TCNT+DELAY;                /* reschedule the OC5 interrupt */
 0080                   ; vol
 0080 FC100E            ldd 0x100e
 0083 C37530            addd #30000
 0086 FD101E            std 0x101e
 0089           ;       TFLG1=bit3;                             /* Reset the OC5 flag */
 0089 C608              ldab #8
 008B F71023            stab 0x1023
 008E           ;       switchon=bit2;                  /* Set the global variable with the switch pressed code */
 008E CC0004            ldd #4
 0091 FD0001            std _switchon
 0094           ;       
 0094           ;       printf("\nSwitch 3 Pressed");
 0094 CC014C            ldd #L15
 0097 BD0000            jsr _printf
 009A           ;       }
 009A           L14:
 009A                   .dbline 0 ; func end
 009A 3B                rti
 009B           _initRTI::
 009B           ; 	
 009B           ; /*************************************************************
 009B           ; Function: initRTI
 009B           ; Purpose: This function is used to initialize the RTI on the HC11.
 009B           ; Inputs: None
 009B           ; Outputs: None
 009B           ; **************************************************************/	
 009B           ; 
 009B           ; void initRTI(void){				/* Initialize our RTI and enable RTI interupts to start toggleing the status LED */
 009B           ; 	PACTL=(0xFC&TMSK2)|3|bit7;	/* Set RTI rate to 3, 32.77ms */
 009B           	; vol
 009B F61024            ldab 0x1024
 009E C4FC              andb #252
 00A0 CA03              orab #3
 00A2 CA80              orab #128
 00A4 F71026            stab 0x1026
 00A7           ;       TMSK2|=bit6;                            /* Arm RTI */
 00A7 18CE1024          ldy #0x1024
 00AB 181C0040          bset 0,y,#64
 00AF           ;       rticount=0;                                     /* Initialize global data structures */
 00AF CC0000            ldd #0
 00B2 FD0000            std _rticount
 00B5           ;       }
 00B5           L16:
 00B5                   .dbline 0 ; func end
 00B5 39                rts
 00B6           _OCoffICon::
 00B6           ; 
 00B6           ; /*************************************************************
 00B6           ; Function: OCoffICon
 00B6           ; Purpose: This function is used to initialize the IC and also turn
 00B6           ; the IC interupts on and the OC5 interupts off.
 00B6           ; Inputs: None
 00B6           ; Outputs: None
 00B6           ; **************************************************************/	
 00B6           ; 
 00B6           ; void OCoffICon(void){
 00B6           ; 	TMSK1=(bit0|bit1|bit2);		/* Sets the Input Capture ON for PORTA pins 1,2,3 */
 00B6 C607              ldab #7
 00B8 F71022            stab 0x1022
 00BB           ;       TFLG1=(bit0|bit1|bit2);         /* Clears the Input Capture Flags for IC1, IC2, IC3*/
 00BB C607              ldab #7
 00BD F71023            stab 0x1023
 00C0           ;       TCTL2 = (bit0|bit2|bit4);       /* Set IC1 and IC2 interrupts on any edge */
 00C0 C615              ldab #21
 00C2 F71021            stab 0x1021
 00C5           ;       }
 00C5           L17:
 00C5                   .dbline 0 ; func end
 00C5 39                rts
 00C6           _OConICoff::
 00C6           ; 
 00C6           ; /*************************************************************
 00C6           ; Function: OConICoff
 00C6           ; Purpose: This function is used to initialize the OC and also turn
 00C6           ; the IC interupts off and the OC5 interupts on.
 00C6           ; Inputs: None
 00C6           ; Outputs: None
 00C6           ; **************************************************************/	
 00C6           ; 	
 00C6           ; void OConICoff(void){
 00C6           ; 	TMSK1=bit3;					/* Sets the OC5 interupt ON */
 00C6 C608              ldab #8
 00C8 F71022            stab 0x1022
 00CB           ;       TFLG1=bit3;                                     /* Clear the OC5 Flag */
 00CB C608              ldab #8
 00CD F71023            stab 0x1023
 00D0           ;       }
 00D0           L18:
 00D0                   .dbline 0 ; func end
 00D0 39                rts
 00D1           _initSwitch::
 00D1           ; 
 00D1           ; /*************************************************************
 00D1           ; Function: initSwitch
 00D1           ; Purpose: This function is used to initialize the global variable
 00D1           ; switchon.
 00D1           ; Inputs: None
 00D1           ; Outputs: None
 00D1           ; **************************************************************/	
 00D1           ; 	
 00D1           ; void initSwitch(void){
 00D1           ; 	switchon=0x00;				/* Clear the gloabal variable switchon */
 00D1 CC0000            ldd #0
 00D4 FD0001            std _switchon
 00D7           ;       }
 00D7           L19:
 00D7                   .dbline 0 ; func end
 00D7 39                rts
 00D8           _initSPCR::
 00D8           ; 
 00D8           ; /*************************************************************
 00D8           ; Function: initSPCR
 00D8           ; Purpose: This function is used to initialize the IC and also turn
 00D8           ; the IC interupts on and the OC5 interupts off.
 00D8           ; Inputs: None
 00D8           ; Outputs: None
 00D8           ; **************************************************************/	
 00D8           ; 
 00D8           ; void initSPCR(void){
 00D8           ; 	SPCR = 0x50;
 00D8 C650              ldab #80
 00DA F71028            stab 0x1028
 00DD           ;       PORTD |= (bit5);                        /* Enable Device as the master */
 00DD 18CE1008          ldy #0x1008
 00E1 181C0020          bset 0,y,#32
 00E5           ;       DDRD |= 0x38;                           /* Initialize PortD */
 00E5 18CE1009          ldy #0x1009
 00E9 181C0038          bset 0,y,#56
 00ED           ;       dummy = SPSR;
 00ED                   ; vol
 00ED F61029            ldab 0x1029
 00F0 F70000            stab _dummy
 00F3           ;       dummy = SPDR;
 00F3                   ; vol
 00F3 F6102A            ldab 0x102a
 00F6 F70000            stab _dummy
 00F9           ;       }
 00F9           L20:
 00F9                   .dbline 0 ; func end
 00F9 39                rts
 00FA           _main::
 00FA           ; 	
 00FA           ; /*************************************************************
 00FA           ; Function: main
 00FA           ; Purpose: This is the main function and is used to call the
 00FA           ; initilization funcions as well as set up the vectors to their
 00FA           ; corresponding addresses. It also sends the switchon variable
 00FA           ; to the slave via SPI.
 00FA           ; Inputs: None
 00FA           ; Outputs: None
 00FA           ; **************************************************************/
 00FA           ; 
 00FA           ; void main ( void ) {
 00FA           ; 	asm("sei");						/* Stop interupts */
 00FA 0F                        sei
 00FB           
 00FB           ; 
 00FB           ;       /****
 00FB           ;       INITILIZATIONS FUNCTIONS
 00FB           ;       ****/
 00FB           ;       initRTI();
 00FB BD009B            jsr _initRTI
 00FE           ;       initSPCR();
 00FE BD00D8            jsr _initSPCR
 0101           ;       initSwitch();
 0101 BD00D1            jsr _initSwitch
 0104           ;       OCoffICon();
 0104 BD00B6            jsr _OCoffICon
 0107           ; 
 0107           ;       /****
 0107           ;       ISR VECTORS ADDRESSES FROM VECTOR.H
 0107           ;       ****/
 0107           ;     RTIvector = &RTIhandler;
 0107 CC0000            ldd #_RTIhandler
 010A DDEC              std 0xec
 010C           ;     TOC5vector = &TOC5handler;
 010C CC0032            ldd #_TOC5handler
 010F DDD4              std 0xd4
 0111           ;     TIC3vector = &TIC3handler;
 0111 CC007D            ldd #_TIC3handler
 0114 DDE3              std 0xe3
 0116           ;     TIC2vector = &TIC2handler;
 0116 CC005F            ldd #_TIC2handler
 0119 DDE6              std 0xe6
 011B           ;     TIC1vector = &TIC1handler;
 011B CC0041            ldd #_TIC1handler
 011E DDE9              std 0xe9
 0120           ; 
 0120           ;       asm("cli");                                             /* Start interupts */
 0120 0E                        cli
 0121           
 0121 2026              bra L23
 0123           L22:
 0123           ; 
 0123           ; 	while(1)
 0123           ; 	{
 0123           ; 		if(switchon!=0)
 0123 FC0001            ldd _switchon
 0126 2721              beq L25
 0128           ;               {
 0128           ;                       SPDR=switchon;                  /* Send the switchon variable via the SPI */
 0128 FC0001            ldd _switchon
 012B F7102A            stab 0x102a
 012E           L27:
 012E           L28:
 012E           ; 
 012E           ; 			while((SPSR&bit7)==0);	/* While the SPI is sending wait untill its done */
 012E 18CE1029          ldy #0x1029
 0132 181F0080F7        brclr 0,y,#128,L27
 0137           ;                       
 0137           ;                       switchon=0;                             /* Reset the switchon variable after it has been sent via the SPI */
 0137 CC0000            ldd #0
 013A FD0001            std _switchon
 013D           ;                       dummy=SPCR;                             /* Clear the SPIF by dumping the SPCR into a dummy variable */
 013D                   ; vol
 013D F61028            ldab 0x1028
 0140 F70000            stab _dummy
 0143           ;                       dummy=SPDR;                             /* Clear the SPIF by dumping the SPCR into a dummy variable */
 0143                   ; vol
 0143 F6102A            ldab 0x102a
 0146 F70000            stab _dummy
 0149           ;               }
 0149           L25:
 0149           L23:
 0149 20D8              bra L22
 014B           X0:
 014B           ; 	}
 014B           ; }
 014B           L21:
 014B                   .dbline 0 ; func end
 014B 39                rts
                        .area bss
 0000           _dummy::
 0000                   .blkb 1
 0001           _switchon::
 0001                   .blkb 2
                        .area text
 014C           L15:
 014C 0A537769746368203320507265737365  .byte 10,'S,'w,'i,'t,'c,'h,32,51,32,'P,'r,'e,'s,'s,'e
 015C 6400              .byte 'd,0
 015E           L13:
 015E 0A537769746368203220507265737365  .byte 10,'S,'w,'i,'t,'c,'h,32,50,32,'P,'r,'e,'s,'s,'e
 016E 6400              .byte 'd,0
 0170           L11:
 0170 0A537769746368203120507265737365  .byte 10,'S,'w,'i,'t,'c,'h,32,49,32,'P,'r,'e,'s,'s,'e
 0180 6400              .byte 'd,0
 0182           L9:
 0182 0A57616974696E6720666F7220737769  .byte 10,'W,'a,'i,'t,'i,'n,'g,32,'f,'o,'r,32,'s,'w,'i
 0192 746368206465626F756E63652E2E2E00  .byte 't,'c,'h,32,'d,'e,'b,'o,'u,'n,'c,'e,46,46,46,0
