The DS1302 RTC (Real Time Clock) is a chip that acts as an electronic time keeper. It has the ability to keep time and date in real-time. We will show you how to implement this clock chip into your application.
Pin | Function | I/O Direction | Explanation |
---|---|---|---|
RST | Reset | Input | Data transfer when High |
SCLK | System Clock | Input | Clock signal |
I/O | Data Input/Output | Input / Output | Data input/output |
Const Device = CB220 Const iorst = 7 Const iodio = 6 Const ioclk = 5 Dim i As Integer Dim adr As Byte High iorst ShiftOut ioclk,iodio,0,&h8e,8 ShiftOut ioclk,iodio,0,0,8 Low iorst Delay 1 High iorst ShiftOut ioclk,iodio,0,&h80,8 ShiftOut ioclk,iodio,0,&H50,8 Low iorst Do High iorst adr = &h81 ShiftOut ioclk,iodio,0,adr,8 i = ShiftIn(ioclk,iodio,4,8) Debug Hex i,cr Low iorst Delay 1000 Loop
The code above will read address 0, the seconds value, and display it in the debug window. At the beginning of the program, writes are enabled to the DS1302 chip and address 0 is set to 50 seconds. Within the Do Loop, data is read from the DS1302. The DS1302 has 6 addresses as shown below:
These addresses can be used to read and write to the DS1302. Please note that the data is in BCD code format.