FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    STC microcontroller control DS1302 program (C procedure)

     

    #include "reg51.h" #include "intrins.h" TypedEfunsignedCharbyte; sbitSCLK = P1 ^ 0; // DS1302 clock port P1.0 sbitIO = P1 ^ 1; // DS1302 data port P1.1 sbitRST = P1 ^ 2; // DS1302 chip select port P1.2 // second day Monday in sharing BYTEcodeinit [] = {0x00,0x00,0x20,0x01,0x01,0x05,0x10}; BYTEdatanow [7]; voidDS1302_Initial (); voidDS1302_SetTime (BYTE * p); voidDS1302_GetTime (BYTE * p); voidmain () { DS1302_Initial (); // initialize DS1302 DS1302_SetTime (init); // set the initial time DS1302_GetTime (now); // read the current time While (1); } / ********************************************** Delay of X microseconds (STC12C5A60S2 @ 12M) Different working environment, this function needs to be adjusted This delay function is used to calculate the instruction cycle of 1T, and different from the conventional MCU 12T *********************************************** / voidDelay () { _nop_(); _nop_(); } / ********************************************** 1-byte data read from DS1302 *********************************************** / BYTEDS1302_ReadByte () { BYTEI; BYTEdat = 0; for (i = 0;. i.1882 = 1; // data to the right one if (IO) dat | = 0x80; // read data SCLK = 1; // clock line pulled Delay (); // delay waiting for } returndat; } / ********************************************** 1-byte write data to the DS1302 *********************************************** / voidDS1302_WriteByte (BYTEdat) { chari; for (i = 0;. i.1882 = 1; // move-out data IO = CY; // sent to the port SCLK = 1; // clock line pulled Delay (); // delay waiting for } } / ********************************************** Read data to an address of the DS1302 *********************************************** / BYTEDS1302_ReadData (BYTEaddr) { BYTEdat; RST = 0; Delay (); SCLK = 0; Delay (); RST = 1; Delay (); DS1302_WriteByte (addr); // write address dat = DS1302_ReadByte (); // read data SCLK = 1; RST = 0; returndat; } / ********************************************** Write data to an address of DS1302 *********************************************** / voidDS1302_WritEDAta (BYTEaddr, BYTEdat) { RST = 0; Delay (); SCLK = 0; Delay (); RST = 1; Delay (); DS1302_WriteByte (addr); // write address DS1302_WriteByte (dat); // write data SCLK = 1; RST = 0; } / ********************************************** Write the initial time *********************************************** / voidDS1302_SetTime (BYTE * p) { BYTEaddr = 0x80; BYTEn = 7; DS1302_WriteData (0x8e, 0x00); // allow a write operation while (n--) { DS1302_WriteData (addr, * p ++); addr + = 2; } DS1302_WriteData (0x8e, 0x80); // write protection } / ********************************************** Read the current time *********************************************** / voidDS1302_GetTime (BYTE * p) { BYTEaddr = 0x81; BYTEn = 7; while (n--) { * P ++ = DS1302_ReadData (addr); addr + = 2; } } / ********************************************** Initialization DS1302 *********************************************** / voidDS1302_Initial () { RST = 0; SCLK = 0; DS1302_WriteData (0x8e, 0x00); // allow a write operation DS1302_WriteData (0x80,0x00); // clock starts DS1302_WriteData (0x90,0xa6); // a resistance of the charging diode + 4K DS1302_WriteData (0x8e, 0x80); // write protection }, Read the full text

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us