IntroducTIonThe DS1307 Serial Real Time Clock, which incorporates a 2-wire serial interface, can be controlled using an 8051-compatible microcontroller. The DS1307 in this example is connected directly to two of the I / O ports on a DS5000 microcontroller and the 2- wire handshaking is handled by low-level drivers, which are discussed in this application note. DS1307 DescriptionThe DS1307 Serial Real Time Clock is a low-power, full BCD clock / calendar plus 56 bytes of nonvolatile SRAM. Address and data are transferred serially via the 2-wire bi-directional bus. The clock / calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with less than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM / PM indicator. The DS1307 has a built-in power sense circuit which detects power failures and automatically switches to the battery supply. DS1307 Operat ionThe DS1307 operates as a slave device on the serial bus. Access is obtained by implementing a START condition and providing a device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STOP condition is executed. The START and STOP conditions are generated using the low level drives, SEND_START and SEND_STOP found in the attached DS5000 code. Also the subroutines SEND_BYTE and READ_BYTE provide the 2-wire handshaking required for writing and reading 8-bit words to and from the DS1307. Hardware Configuration The system is configured as shown in Figure 1. The DS1307 has the 2-wire bus connected to two I / O port pins of the DS5000: SCL-P1.0, SDA-P1.1. The VDD voltage is 5V, RP = 5KΩ and the DS5000 is using a 12-MHz crystal. The other peripheral device could be any other device that recognizes the 2-wire protocol, such as the DS1621 Digital Thermometer and Thermostat. The interface with the D5000 was accomplished using the DS5 000T Kit hardware and software. This development kit allows the PC to be used as a dumb terminal using the DS5000's serial ports to communicate with the keyboard and monitor.
Figure 1. Typical 2-wire bus configuration.
The following bus protocol has been defined (see Figure 2).
During data transfer, the data line must remain stable whenever the clock line is high. Changes in the data line while the clock line is high will be interpreted as control signals.
Accordingly, the following bus conditions have been defined:
Start data transfer: A change in the state of the data line from high to low, while the clock line is high, defines a START condition.
Stop data transfer: A change in the state of the data line from low to high, while the clock line is high, defines the STOP condition.
Data valid: The state of the data line represents valid data when, after a START condition, the data line is stable for the duration of the high period of the clock signal. The data on the line must be changed during the low period of the clock signal. There is one clock pulse per bit of data.
Each data transfer is initiated with a START condition and terminated with a STOP condition. The number of data bytes transferred between the START and the STOP conditions is not limited, and is determined by the master device. The information is transferred byte-wise and each receiver acknowledges with a ninth bit.
Acknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the reception of each byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit.
A device that acknowledges must pull down the SDA line during the acknowledge clock pulse in such a way that the SDA line is stable low during the high period of the acknowledge related clock pulse. Of course, setup and hold times must be taken into account. A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that has been clocked out of the slave. In this case, the slave must leave the data line high to enable the master to generate the STOP condition.
Figure 2 details how data transfer is accomplished on the 2-wire bus. Depending on the state of the R / active-low W bit, two types of data transfer are possible: Data transfer from a master transmitter to a slave receiver. The first byte transmitted by the master is the slave address. Next follows a number of data bytes. The slave returns an acknowledge bit after each received byte. Data is transferred with the most significant bit (MSB) first. Data transfer from a slave transmitter to a master receiver. The first byte (the slave address) is transmitted by the master. The slave then returns an acknowledge bit. This is followed by the slave transmitting a number of data bytes. The master returns an acknowledge bit after all received bytes other than the last byte. At the end of the last received byte, a not acknowledge is returned.
Figure 2. Data transfer on 2-wire serial bus.
The master device generates all of the serial clock pulses and the START and STOP conditions. A transfer is ended with a STOP condition or with a repeated START condition. Since a repeated START condition is also the beginning of the next serial transfer, the bus will not be released. Data is transferred with the most significant bit (MSB) first.
The DS1307 may operate in the following two modes:
Slave receiver mode (DS1307 write mode): Serial data and clock are received through SDA and SCL. After each byte is received, an acknowledge bit is transmitted. START and STOP conditions are recognized as the beginning and end of a serial transfer. Address recognition is performed by hardware after reception of the slave address and direction bit (see Figure 3). The address byte is the first byte received after the start condition is generated by the master. The address byte contains the 7-bit DS1307 address, which is 1101000, followed by the direction bit (R / active-low W) which for a write is a 0. After receiving and decoding the address byte, the DS1307 outputs an acknowledge on the SDA line. After the DS1307 acknowledges the slave address + write bit, the master transmits a register address to the DS1307. This will set the register pointer on the DS1307. The master will then begin transmitting each byte of data with the DS1307 acknowledging each byte received. The master will genera te a stop condition to terminate the data write.
Figure 3. Data write—slave receiver mode.
Slave transmitter mode (DS1307 read mode): The first byte is received and handled as in the slave receiver mode. However, in this mode, the direction bit will indicate that the transfer direction is reversed. Serial data is transmitted on SDA by the DS1307 while the serial clock is input on SCL. START and STOP conditions are recognized as the beginning and end of a serial transfer (See Figure 4). The address byte is the first byte received after the start condition is generated by the master. The address byte contains the 7-bit DS1307 address, which is 1101000, followed by the direction bit (R / active-low W), which for a read is a 1. After receiving and decoding the address byte, the DS1307 inputs an acknowledge on the SDA line. The DS1307 then begins to transmit data starting with the register address pointed to by the register pointer. If the register pointer is not written to before the initiation of a read mode, the first address that is read is the last one stored in the register p ointer. The DS1307 must be sent a Not-Acknowledge bit by the master to terminate a read.
Figure 4. Data read—slave transmitter mode. Software Operation DS5000 Interface The software presented in Appendix 1 is written to interface the DS5000 with the DS1307 over the 2-wire interface. The DS5000 was programmed using Dallas Semiconductor's DS5000T Evaluation Kit, which allows a PC to be used as a dumb terminal. The KIT5K software environment supplied with the DS5000T Evaluation Kit provides a high-level interface for loading application software to the DS5000 or for setting its configuration parameters via the Program command. The KIT5K software includes a dumb terminal emulator to allow users to run application software in the DS5000, which communicates with the user via a PC COM port.
DS1307 Source CodeThe first section of the code found in the Appendix is ​​used to configure the DS5000 for serial communication with the PC. Also at the beginning of the code is the MASTER_CONTROLLER subroutine which is used to control the demonstration software.
The subroutines that immediately follow the MASTER_CONTROLLER subroutine are the low level drivers for controlling the 2-wire interface. They are not specific to the DS1307 but can be used with any 2-wire compatible slave-only device. These subroutines are: SEND_START This subroutine is used to generate the Start condition on the 2-wire bus. SEND_STOP This subroutine is used to generate the Stop condition on the 2-wire bus. SEND_BYTE This subroutine sends an 8-bit word, MSB first, over the 2-wire bus with a 9th clock pulse for the Acknowledge pulse. READ_BYTE This subroutine reads an 8-bit word over the 2-wire bus. It checks for the LASTREAD flag to be cleared indicating when the last read from the slave device is to occur. If it is not the last read, the DS5000 sends an Acknowledge pulse on the 9th clock and if it is the last read from the slave device, the DS5000 sends a Not-Acknowledge. SCL_HIGH This subroutine transitions the SCL line low-to-high and ensures the SCL line is high be fore continuing. DELAY and DELAY_4 These two subroutines have been included to ensure that the 2-wire bus timing is maintained. The rest of the code included in the appendix is ​​specifically designed to demonstrate the functions of the DS1307. The functions that are demonstrated are :
Setting Time The time is read in from the keyboard and stored in the DS5000 scratchpad memory. It is then transferred, over the 2-wire interface, to the DS1307. Set RAM A single hex byte is read in from the keyboard and written to the entire user RAM of the DS1307. Read Date / Time The date and time are read, over the 2-wire bus, and stored in the DS5000 scratchpad memory. It is then written to the screen. This continues until a key is pressed on the keyboard.> Read RAM The entire user RAM of the DS1307 is read into the DS5000 scratchpad memory and then written to the PC monitor. OSC On / OSC Off The DS1307 clock oscillator can be turned on or off. SQW / OUT On / SQW / OUT Off The SQW / OUT can be turned on or off. It will toggle at 1 Hz. ConclusionIt has been shown that it is very straight forward to interface the DS1307 or any other 2-wire slave device to an 8051-compatible microcontroller. The only concern must be that the 2-wire timing specification is not violated by the low level drivers o n the microcontroller. The delay subroutines have been inserted into the code for this purpose. The values ​​in Table 1 are the actual timing parameters observed in the hardware setup used to develop this application note.
Table 1. AC Electrical Characteristics
Parameter | Symbol | Actual | Units |
SCL Clock Frequency | fSCL | 59 | kHz |
Bus Free Time Between a STOP and START condition | tBUF | 5.7 | µs |
Hold Time (repeated) START Condition | tHD: STA | 6.2 | µs |
LOW Period of SCL Clock | tLOW | 10.5 | µs |
HIGH Period of SCL Clock | tHIGH | 6.5M | µs |
Set-up Time for a Repeated START Condition | tSU: STA | 5.3 | µs |
Data Hold Time | tHD: DAT | 5.5 | µs |
Data Set-up Time | tSU: DAT | 3.1 | µs |
Set-up Time for STOP Condition | tSU: STO | 5.4 | µs |
The function of Led Diving Flashlight has 1-5 modes, easy to change according to your situation where you stay at.
LED Diving Flashlight usually high power and super bright, when you go to dive, the brightest flashlight adapt for you.
The products are waterproof, shockproof and tactical, so you need not to worry about its quality.
Most of the products are simple on/off push button operation;
By the way, our products are saled with factory price, and the quality can guarantee, lastly we provide warranty for 1 year;
LED Diving Flashlight
High Power Led Flashlight,Rechargeable Led Flashlight,Zoomable Led Flashlight,Led Diving Flashlight
Ningbo Henglang Import & Export Co.,Ltd , https://www.odistarflashlight.com