PIC microcontroller control DS1302 subroutine

Single Chip Microcontroller STM32L151CCU6
1206 RGB (Single)
0201 Package SLP0603 ESD Diode, 5V Unidirectional ESD
Mobile Phone Crystal: 3.2 x 2.5mm 3225, 26MHz, 7.5PF, 10PPM, 20PPM, 30PPM

;========================================================== ; DS1302 Control Subroutine ;========================================================== The following program includes the initialization of the DS1302, functions to write and read time data. ; DS1302 Initialization ; Set_DS1302: Write time to DS1302 ; Get_DS1302: Read time from DS1302 ;========================================================== ;================== DS1302 Definitions ====================== #define T_IOPORTE 2 ; DS1302 I/O pin #define T_CLKPORTE 1 ; DS1302 clock pin #define T_RSTPORTE 0 ; DS1302 reset pin #define DS1302_RX 20H ; Receive buffer for data #define DS1302_TX 28H ; Transmit buffer for data Count equ xxxh Cnt equ xxxh ;******************************************************* ; DS1302 Initialization Procedure ;******************************************************* DS1302_init ; Not implemented yet return ;******************************************************* ; Subprogram Name: Set_DS1302 ; Function: Set initial time on DS1302 and start the timer ; Description: ; Calls: Write_byte ; Entry Parameters: Initial time values: W_Second, W_Minute, W_Hour, W_Day, W_Month, W_Week, W_YearL (consecutive) ; Export Parameters: None ; Resources Used: Counter, SecAddr (predefined) ; Designer: Zheng Yanbo Date: April 21, 2005 ;******************************************************* Set_DS1302: bcf T_RST bcf T_CLK bsf T_RST movlw 8Eh movwf DS1302_TX call Write_byte movlw 00h movwf DS1302_TX call Write_byte bsf T_CLK bcf T_RST movlw W_Second movwf FSR movlw D'7' movwf counter movlw 80h movwf SecAddr S13021: bcf T_RST bcf T_CLK bsf T_RST movf SecAddr, W movwf DS1302_TX call Write_byte movf INDF, W movwf DS1302_TX call Write_byte incf FSR incf SecAddr incf SecAddr bsf T_CLK bcf T_RST decfsz counter, F goto S13021 bcf T_RST bcf T_CLK bsf T_RST movlw 8Eh movwf DS1302_TX call Write_byte movlw 80h movwf DS1302_TX call Write_byte bsf T_CLK bcf T_RST return ;******************************************************* ; Subprogram Name: Get_DS1302 ; Function: Read time from DS1302 ; Description: ; Calls: Write_byte, Read_byte ; Entry Parameters: Time will be saved in R_Second, R_Minute, R_Hour, R_Day, R_Month, R_Week, R_YearL ; Export Parameters: None ; Resources Used: Counter, SecAddr (predefined) ; Designer: Zheng Yanbo Date: April 21, 2005 ;******************************************************* Get_DS1302: movlw R_Second movwf FSR movlw D'7' movwf counter movlw 81h movwf SecAddr G13021: bcf T_RST bcf T_CLK bsf T_RST movf SecAddr, W movwf DS1302_TX call Write_byte call Read_byte movf DS1302_RX, W movwf INDF incf FSR incf SecAddr incf SecAddr bsf T_CLK bcf T_RST decfsz counter, F goto G13021 return ;******************************************************* ; Function: Write one byte to DS1302 (internal subroutine) ; Entry: Data is already in DS1302_TX ; Exit: None ; Resources Used: cnt (predefined) ;******************************************************* Write_byte: movlw D'8' movwf tmp_cnt W_shift: rrf DS1302_TX, F ; Shift with carry (LSB first) btfsc STATUS, C goto send_1 bcf T_IO goto send_0 send_1: bsf T_IO send_0: bsf T_CLK ; Rising edge nop bcf T_CLK decfsz cnt, F goto W_shift return ;******************************************************* ; Function: Read one byte from DS1302 (internal subroutine) ; Entry: None ; Exit: Data stored in DS1302_RX ; Resources Used: cnt (predefined) ;******************************************************* Read_byte: bsf STATUS, RP0 ; Bank 1 bsf TRISE, 2 ; Set serial data port as input bcf STATUS, RP0 ; Bank 0 movlw D'8' movwf cnt R_shift: btfsc T_IO goto get_1 bcf STATUS, C goto get_0 get_1: bsf STATUS, C get_0: rrf DS1302_RX, F bsf T_CLK nop bcf T_CLK ; Falling edge decfsz cnt, F goto R_shift ; Reset output bsf STATUS, RP0 ; Bank 1 bcf TRISE, 2 ; Set T_IO as output bcf STATUS, RP0 ; Bank 0 return ; This code assumes that PORTA is configured as an A/D port by default. ; If you change it to another port, refer to the PIC datasheet for proper configuration. ;========================================================= ; Initialize Port ;========================================================= Port_Init: bsf STATUS, RP0 ; Bank 1 bcf ADCON1, PCFG0 bsf ADCON1, PCFG1 bsf ADCON1, PCFG2 bcf ADCON1, PCFG3 ; Set PORTA and PORTE as digital I/O bcf STATUS, RP0 ; Bank 0 return

Custom Molded Wire Assembly

High temperature wire, high temperature resistant wire, please don't take the safety of electricity as a bet, but the quality and credibility of your own products as a bet. If you want to find a regular cable, and find a regular manufacturer, our cables are instantly conductive, stronger and safer than others, refreshing your imagination of materials. We will spend a lifetime of continuous improvement, just to achieve the real environmental protection level of materials and reduce carcinogens. Only for health, a truly environmentally friendly material. Safety check, every product has been tested. High-precision wires have lower resistance, lower heat, and lasting and stable conductivity. Real-time monitoring of wire eccentricity and outer diameter to ensure uniform thickness of insulation layer and sheath. Eliminate the addition of heavy metals and non-environmentally friendly substances such as lead, mercury and other harmful substances. Does not contain any harmful substances to avoid adverse effects on the human body and the environment.

We eliminate mold costs and save money for customers by providing hundreds of thousands of inventory overmolding. For highly customized molded cable manufacturing projects, our advanced technology allows us to produce custom overmoldings at a price and quality level that clearly sets us ahead of our competitors.

Custom molded wire assembly, overmolded IP67/68 connectors assembling,customized waterproofing cable assembly

ETOP WIREHARNESS LIMITED , https://www.etopwireharness.com