FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    MCU STC12C5A60S2 controls AT24C04 program (C language)

     

    / ********************************************** Main chip: STC12C5A60S2 (1T) Working frequency: 12.000MHz *********************************************** / #include "reg51.h" #include "intrins.h" TypedEfunsignedCharbyte; TypeDefunSignedshWord; SBITSCL = P3 ^ 4; // AT24C04 clock SBITSDA = P3 ^ 5; // AT24C04 data Bytebuf [16]; // data buffer area Bytecodestdata [] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xFF } VoidDelay5us (); VoidDelay5ms (); Voidat24c04_start (); Voidat24c04_stop (); Voidat24c04_sendack (bitack); Bitat24c04_recvack (); Voidat24c04_sendbyte (bytated); BYTEAT24C04_RECVBYTE (); Voidat24c04_readpage (); Voidat24c04_writepage (); voidmain () { AT24C04_WritePage (); DELAY5MS (); AT24C04_READPAGE (); While (1); } / ********************************************** Write 1 page (16-byte) data to AT24C04 16 test data starting with TestData, such as 00 ~ 0f address of the device *********************************************** / Voidat24c04_writepage () { BYTEI; AT24C04_Start (); // Start signal AT24C04_sendByte (0xA0); // Send device address + write signal AT24C04_sendByte (0x00); // Send storage unit address For (i = 0; i "16; i ++) { BUF [I] = AT24C04_RECVBYTE (); IF (i == 15) { AT24c04_sendack (1); // The last data needs NAK } Else { AT24C04_sendack (0); // Respond to ACK } } AT24C04_Stop (); // Stop signal } / ********************************************** Delay 5 microsecond (STC12C5A60S2 @ 12M) Different working environments need to be adjusted to adjust this function This delay function is calculated using a 1T instruction cycle, different from the traditional 12T MCU *********************************************** / void delay5us () { BYTE N = 4; While (N--) { _nop_(); _nop_(); } } / ********************************************** Delayed 5 milliseconds (STC12C5A60S2 @ 12M) Different working environments need to be adjusted to adjust this function This delay function is calculated using a 1T instruction cycle, different from the traditional 12T MCU *********************************************** / void delay5ms () { Word n ​​= 2500; While (N--) { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } } / ********************************************** Start signal *********************************************** / Void AT24C04_Start () { SDA = 1; // pull high data cable SCL = 1; // pull high clock line DELAY5US (); // delay SDA = 0; // Produce a falling edge DELAY5US (); // delay SCL = 0; // pull low clock line } / ********************************************** Stop signal *********************************************** / Void AT24C04_STOP () { SDA = 0; // pull low data line SCL = 1; // pull high clock line DELAY5US (); // delay SDA = 1; // Produce rising edge DELAY5US (); // delay } / ********************************************** Send a response signal Entrance parameters: ACK (0: ACK 1: NAK) *********************************************** / Void AT24C04_SENDACK (Bit Ack) { SDA = Ack; // Write acknowledge signal SCL = 1; // pull high clock line DELAY5US (); // delay SCL = 0; // pull low clock line DELAY5US (); // delay } / ********************************************** Receive response signal *********************************************** / Bit AT24C04_RECVACK () { SCL = 1; // pull high clock line DELAY5US (); // delay Cy = SDA; // Read response signal SCL = 0; // pull low clock line DELAY5US (); // delay Return Cy; } / ********************************************** Send a byte data to the IIC bus *********************************************** / Void AT24C04_sendByte (byte DAT) { BYTE I; For (i = 0; i<8; i ++) // 8 bit counter { DAT << = 1; // The highest bit of the transfer SDA = cy; // send data port SCL = 1; // pull high clock line DELAY5US (); // delay SCL = 0; // pull low clock line DELAY5US (); // delay } AT24C04_RECVACK (); } / ********************************************** Receive one byte data from the IIC bus *********************************************** / BYTE AT24C04_RECVBYTE () { BYTE I; BYTE DAT = 0; SDA = 1; // Enable internal pull-up, prepare to read data For (i = 0; i<8; i ++) // 8 bit counter { DAT << = 1; SCL = 1; // pull high clock line DELAY5US (); // delay DAT | = SDA; // Read data SCL = 0; // pull low clock line DELAY5US (); // delay } Return Dat; }, 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