Read and write driver based on AT2402 microcontroller

Publisher:创新驿站Latest update time:2016-02-26 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//This part is the driver of AT2402 using I2C bus connection

#include

// AT2402 function

//                    Send multi-byte data function to a sub-address device               
//Function prototype: bit  ISendStr(UCHAR sla,UCHAR suba,ucahr /s,UCHAR no); 
//Function:     The whole process from starting the bus to sending address, sub-address, data, and ending the bus, from the device
//         address sla, sub-address suba, the content to be sent is the content pointed to by s, and no bytes are sent.
//          If 1 is returned, it means the operation is successful, otherwise the operation is wrong.
//Note:    The bus must be ended before use.

bit ISendStr(unsigned char  sla,unsigned char  suba,unsigned char  *s,unsigned char  no)
{
   unsigned char i;

  Start_I2c();               //Start the bus//
  SendByte(sla);             //Send device address//
  if(ack==0)return(0);
  SendByte(suba);            //Send device sub-address//
  if(ack==0)return(0);       //Here represents the internal ROM address

  for(i=0;i        //The slave sends data to the host
   
    SendByte(*s);            //Send data//
    if(ack==0)return(0);
    s++;
  }
  Stop_I2c();                //End the bus//

   return(1);
}

//                    Function to read multi-byte data from a device with a sub-address               
//Function prototype: bit  RecndStr(UCHAR sla,UCHAR suba,ucahr /s,UCHAR no); 
//Function:     From starting the bus to sending the address, sub-address, reading data, and ending the bus, from the device
//         address sla, sub-address suba, the read content is placed in the storage area pointed to by s, and no bytes are read.
//           If 1 is returned, it means the operation is successful, otherwise the operation is wrong.
//Note:    The bus must be ended before use.
bit IRcvStr(unsigned char  sla,unsigned char  suba,unsigned char  *s,unsigned char  no)
{
  unsigned char i;

  Start_I2c();                  //Start the bus//
  SendByte(sla);                //Send device address//
  if(ack==0)return(0);
  SendByte(suba);               //Send device sub-address//
  if(ack==0)return(0);          //Here represents the internal ROM address

  Start_I2c();                 //Restart the bus//
  SendByte(sla+1);           //Indicates reading data from the host
  if(ack==0)return(0);
  for(i=0;i    
    /s=RcvByte();               //Send data//
     Ack_I2c(0);                //Send the acknowledgment bit// 
    s++;
  }
  /s=RcvByte();
  Ack_I2c(1);                   //Send the non-acknowledgment bit//
  Stop_I2c();                   //End the bus//
  return(1);
}

Keywords:MCU Reference address:Read and write driver based on AT2402 microcontroller

Previous article:C51 single chip computer address pointer and its application
Next article:51 MCU PWM waveform example

Recommended ReadingLatest update time:2024-11-16 17:27

PIC microcontroller example 2: SAA1064 digital tube display based on I2C
1. Schematic diagram Functions: The four digital tubes are divided into two groups, and the four buttons are also divided into two groups. Each group controls the addition and subtraction of the corresponding digital tube display data. The data is displayed cyclically between 0--99, and has a power-off protection
[Microcontroller]
PIC microcontroller example 2: SAA1064 digital tube display based on I2C
NRF24l01 wireless module stc89c52 microcontroller program
Program 24l01 wireless module stc89c52 The microcontroller source program is as follows: /********************************************************************************* **********************************************************************************/ #include "reg52.h" /*Include STC microcontroller header file
[Microcontroller]
NRF24l01 wireless module stc89c52 microcontroller program
The STM8 microcontroller serial port recognizes both the custom protocol and the Modbus protocol
  In the development of single-chip microcomputers, the serial port is the most commonly used channel for exchanging data with the outside world. To use the serial port, a communication protocol is essential. The communication protocol is the language used by the single-chip microcomputer to communicate with the outsi
[Microcontroller]
The STM8 microcontroller serial port recognizes both the custom protocol and the Modbus protocol
NXP i.MX RT106L crossover microcontroller meets smart home voice needs
NXP Semiconductors NV (NASDAQ: NXPI) today announced the launch of its voice solution SLN-LOCAL-IOT. This is a fully integrated development platform for offline voice control. The solution includes a complete hardware module design and the necessary related software for implementing far-field voice control with custom
[Internet of Things]
NXP i.MX RT106L crossover microcontroller meets smart home voice needs
pic microcontroller, linker description file (*.lkr) meaning
Combined with 18f4620.lkr to explain the meaning of the code in the link description file // $Id: 18f4620.lkr,v 1.3 2004/04/26 18:09:00 curtiss Exp $  // File: 18f4620.lkr  // Sample linker script for the PIC18F4620 processor  //Search the current directory library/object for the path. . represents the current di
[Microcontroller]
PIC microcontroller serial port transmission and key press
This is a PIC microcontroller serial port transmission experiment that I tried while learning PIC microcontroller debugging. When the button RB0 is pressed, num is incremented, and the LED connected to the RC0 port flips, and the number num is passed to the transmission register and sent to the computer end. The baud
[Microcontroller]
Astable multivibrator used to drive signal lights
Astable multivibrator used to drive signal lights
[Analog Electronics]
Astable multivibrator used to drive signal lights
MCU Program Development
In the final analysis, the development of single-chip microcomputer programs depends on diligent study, more practice, and more accumulation. There are too few people like Newton and Einstein in this world, and few people have real innovative thinking ability. I think that generally speaking, the so-called innovative a
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号