Specifications

51
RTS ;RETURN TO MAIN
Initialisation for port A simply involves setting the three used pins for data input and
setting all of the pins to initially start with logic low. This ensures no sensor readings
take place until the sensor actually detects an object.
***************INITIALISE PORT A********************************************
INITPA MOVB #%11111000,DDRA ;SET PORT A BITS FOR OUT AND IN 0 =
INPUT
MOVB #%00000000,PORTA ;ENSURE PORT A INPUTS ARE ZEROES
WAITING FOR ACITVE HIGH
RTS
Initialising port G for key wake up behaviour involves setting conditions in four
separate registers. DDRG sets the data direction for port G, the used pins need to be
data input while the rest can be either. Writing to KWIFG clears the wake up flags on
the desired pins and KWIEG enables the selected pins to be key wake up interrupts.
This means that as soon as the edge is detected the interrupt will automatically service.
The PUCR register is used to enable or in this case disable all of the pull up resistors on
selected ports. As no pull up resistors are desired on any ports in use it is simplest to
write all zeroes to this register. Storing the opcode for the jump command into the
pseudo vector notifies the interrupt what to do when the interrupt is triggered. Also
mentioned here is the address to jump to. This is the interrupt service routine that was
outlined above. It is essential that the interrupt mask bit is cleared after these registers
have been initialised.
**************INITIALISE PORT G FOR KEY WAKE UP***************************
INITKWG MOVB #%11111100,DDRG ;BITS 0-1 AS INPUT
MOVB #%00000011,KWIFG ;CLEAR WAKE UP FLAG 0-1
MOVB #%00000011,KWIEG ;ENABLE KEY WAKE UP INTERRUPTS
MOVB #%00000000,PUCR ;SET PORT G, H IRQ AND XIRQ FOR PULL
DOWN (DISAHLE ALL PULL UPS(ALL 0'S))
LDAA #$06 ;JMP COMMAND OPCODE
STAA $07B8 ;RTI PSEUDO VECTOR
LDD #KWGISR ;ADDRESS TO JUMP TO, KWG ISR
STD $07B9
CLI ;CLEAR INTERUPT MASK
RTS