Hardware Reference
In-Depth Information
IBSR
5
IBIF;
/* clear the IBIF flag */
if (IBSR & RXAK)
return
2
1;
IBDR
5
hibyte;
/* send out the high byte of TH */
while(!(IBSR & IBIF));
IBSR
5
IBIF;
if (IBSR & RXAK)
return
2
1;
IBDR
5
lobyte;
/* send out the low byte of TH */
while(!(IBSR & IBIF));
IBSR
5
IBIF;
if (IBSR & RXAK)
return
2
1;
IBCR &
5
,
MSSL;
/* generate a stop condition */
return 0;
}
▲
Example 11.13
▼
Write a function to read the Config register from the DS1631A and return its value in ac-
cumulator B.
Solution:
The procedure for reading the Config register is as follows:
Step 1
Assert the start condition and send the control byte 0x92 with R/W 5 0.
Step 2
Wait until the control byte is shifted out and check to see if the DS1631A acknowledges.
If not, exit.
Step 3
Send an Access Config command (0xAC) to the DS1631A.
Step 4
Wait until the command is shifted out and check to see if the DS1631A acknowledges.
If not, exit.
Step 5
Assert a restart condition.
Step 6
Send the control byte 0x93 with R/W 5 1, which tells the DS1631A that a read is being
performed.
Step 7
Wait until the control byte is shifted out and check to see if the DS1631A acknowledges.
If not, exit.
Step 8
Read the Config register.
Step 9
Make sure that the bus is idle and send back a NACK to the DS1631A.
Search WWH ::
Custom Search