;Lab4 Part C
;Andrew Fowler
;Damian Szmulewicz Section: 3276
; Keypad operation


;*****************************************************************



		.global		_c_int00
		
GPCMUX1		.set		0x6FA6
GPCMUX2		.set		0x6FA8
GPBMUX1		.set		0x6F96		
PCLKCR3 	.set		0x7020
data_sect	.set		0xa000			;constant that is actually the starting addr of .data section
bss_sect	.set		0xb000			;constant that is actually the starting addr of .bss section
GPAMUX1 	.set 		0x6F86
GPAMUX2 	.set 		0x6F87
WDCR		.set		0x7029
GPADIR 		.set		0x6F8A
GPASET		.set		0x6FC2
GPADAT 		.set 		0x6FC0
;*****************************************************************

		.data				

;char    .byte    	'4' 	;define string, ASCII characters placed in memory as WORDS!

	    ; .bss		results,256	;reserves 256 words at label 'results' in the .bss section	
		
;		.global		char		;.global directive lets you to see the assigned addresses in map file.	
		
;****************** Part A ***********************
		.text					; Program section, see the command linker file, program code 
								; should be placed in the text section which starts at 0x9000
						
_c_int00:						; This label tells the linker where the entry (starting) point for 
		EALLOW 						; Allow access to protected registers
		SETC 	OBJMODE 			; Allow 32 bit mov instructions
								; WDCR is watchdog timer control register
								; In constants section need to set WDCR=0x7029
		MOV 	AL,#1101000b 	; Disable the watchdog timer.
								; Must have 101 in bits 5, 4, 3 for
								; any writes to WDCR. 1 in bit 6
								; disables watchdog
		MOV 	AR1,#WDCR
		MOV		*AR1, AL 		; Disables watchdog timer
		
		MOV		AR1, #GPCMUX1+1	; Data pins
		MOV		ACC, #0xFFFF	; Makes the pins D0-D7 pins
		MOV		*AR1, ACC		; Finally sets them.
		
		MOV		AR1, #GPCMUX2
		MOV		AL, #0xFFFF		; Makes the Adress pins A0-15 set
		MOV		*AR1, AL
		
		MOV		AR1, #GPBMUX1
		MOV		AL, #0xFFFF		; Have no idea where the read signal is So just make all the signals work
		MOV 	*AR1, AL
		
		MOV		AR1, #PCLKCR3
		MOV		AL, #0x1000		; Turns on XCLKIN
		MOV 	*AR1, AL
		
Loop	MOV		ACC, #0x0
		MOV		AR1, #0x4000
		MOV		AL, *AR1
		
		MOV		AR1, #0x4000
		MOV		*AR1, AL
		B		Loop, UNC
		