Hardware Reference
In-Depth Information
#include “c:\miniIDE\lcd_util_dragon12.asm”
#include “c:\miniIDE\delay.asm”
prompts dc.b
“Enter seconds:”,0
promptmi dc.b
“Enter minutes:”,0
prompth dc.b
“Enter hours:”,0
promptd dc.b
“Enter day:”,0
prompte dc.b
“Enter date:”,0
promptm dc.b
“Enter month:”,0
prompty dc.b
“Enter year:”,0
end
This function is interrupt-driven. It clears the fl ag tready to 0 after outputting the prompt mes-
sage. When setting the DIP switches, the designer presses the button connected to the PJ0 pin.
Pressing the PJ0 button causes an interrupt to be requested to the MCU. The interrupt service
routine simply sets the fl ag tready to 1 and returns. Since the getTime function is polling this
fl ag, it will detect the value change and read the value of the DIP switches. The PJ0 pin inter-
rupt service routine is very simple.
PJ_ISR
movb
#1,tready
movb
#1,PIFJ
; clear the PIFJ0 flag
rti
The C language version of the function will be left as an exercise problem.
Example 11.5
Write a function to send the time and calendar information to the DS1307. The time and
calendar information is pointed to by X. The device ID and the starting register address are
passed in A and B, respectively. X points to the value of year and the second's value is located
at [X] 1 6.
Solution: The function that sends time and calendar information to the DS1307 is as follows:
sendTime
jsr
sendSlaveID
; send out device ID of the DS1307
brclr
IBSR,RXAK,sndTimeOK1
; did DS1307 acknowledge?
ldab
#$FF
; return error code 2 1 if not acknowledged
rts
sndTimeOK1
stab
IBDR
; send out register address for seconds
brclr
IBSR,IBIF,*
; wait until seconds' address has been shifted out
movb
#IBIF,IBSR
; clear the IBIF flag
brclr
IBSR,RXAK,sndTimeOK2
; did 1307 acknowledge?
ldab
#$FF
; return error code 2 1 if not acknowledged
rts
sndTimeOK2
ldy
#7
; byte count
tfr
X,D
; set X to point to second's value
addd
#6
;
tfr
D,X
;
sndloop
movb
1,x 2 ,IBDR
; send out 1 byte
brclr
IBSR,IBIF,*
movb
#IBIF,IBSR
 
Search WWH ::




Custom Search