Hardware Reference
In-Depth Information
if (IBSR & RXAK)
/* if DS1307 did not acknowledge, send error code */
return 2 1;
IBCR & 5 , MSSL;
/* generate a stop condition */
return 0;
}
Example 11.4
Write a function to read the time and calendar information from the DIP switches and store
them in a buffer to be sent to the DS1307. The DIP switches are driven by Port AD1.
Solution: The user must be informed to enter the time and calendar. Since there are 7 bytes of
time and calendar information, the user will need to use the DIP switches to enter data seven
times. The procedure for entering a byte of information is as follows:
1. The function outputs a message to ask the user to enter a value. The prompt message is
Enter xxxx :
2. The user sets up a value using the DIP switches and presses the button connected to
the PJ0 pin to remind the MCU to read the value.
3. The MCU reads the value of the DIP switches and sends it to the DS1307.
The function that reads the time and calendar information and stores them in a buffer is as
follows:
#include “c:\miniIDE\hcs12.inc”
org
$1000
buf
ds.b
7
tready
ds.b
1
; flag to indicate a new time info. is ready
getTime pshx
pshy
ldy
#buf
; Y is the pointer to the buffer
movb
#$FF,ATD1DIEN
; enable Port AD1 for digital inputs
bclr
DDRJ,BIT0
; enable PJ0 pin for input
bset
PERJ,BIT0
; enable pull-up or pull-down on PJ0 pin
bclr
PPSJ,BIT0
; enable pull-down, interrupt is rising edge triggered
bset
PIEJ,BIT0
; enable PJ0 interrupt
cli
;
ldaa
#$80
; set LCD cursor to the upper left corner
jsr
cmd2LCD
;
ldx
#prompty
; output the prompt “Enter year:”
jsr
putsLCD
;
waity
tst
tready
; is new year info. ready?
beq
waity
;
movb
PTAD1,1,y 1
; save year info. in buffer
movb
#0,tready
ldaa
#$80
; set LCD cursor to the upper left corner
jsr
cmd2LCD
;
ldx
#promptm
; output the prompt “Enter month:”
 
Search WWH ::




Custom Search