中文字幕无码不卡一区二区三区_少妇被又大又粗又爽毛片久久黑人_91精品国产在热久久无毒不卡_久久久久久亚洲综合网站

技術(shù)熱線: 4007-888-234
設(shè)計開發(fā)

專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命

開發(fā)工具

提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享

技術(shù)支持

從全面的產(chǎn)品導(dǎo)入到強大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產(chǎn)品競爭力

新聞中心

提供最新的單片機資訊,行業(yè)消息以及公司新聞動態(tài)

CCSC i2c.c程序訪問MCD2demo 24C02EEPROM

更新時間: 2019-03-23
閱讀量:1893

十年專注單片機方案開發(fā)的方案公司英銳恩,分享CCSC i2c.c程序訪問MCD2demo 24C02EEPROM。英銳恩現(xiàn)提供服務(wù)產(chǎn)品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。

/*=============================================================================
I2C總線訪問24C02,運行程序:
        24C02 ready   -> LED0亮,
        Test  OK      -> LED7亮,
        Write&Read OK -> LED1/3/5/7亮。
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
// MPLAB IDE V7.11 + CCS C3.18
// i2c access 24C02 for MCD2-demo
//
// by LW7807@163.com
// 2005/06/21
///////////////////////////////////////////////////////////////////////////////
#include <16F877A.h>                            // PIC16F877 header file
#use delay(clock=4000000)                       // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP              // for debug mode

#define EEPROM_24C02_SDA        PIN_B5
#define EEPROM_24C02_SCL        PIN_B4
#define EEPROM_24C02_SIZE       256
#use i2c(master, sda=EEPROM_24C02_SDA, scl=EEPROM_24C02_SCL)


///////////////////////////////////////////////////////////////////////////////
//
void init_eeprom_24c02(void)
{
        port_b_pullups(true);                   // !!!internal pullup resister

        output_float(EEPROM_24C02_SCL);
        output_float(EEPROM_24C02_SDA);
}//end init_24c02()

///////////////////////////////////////////////////////////////////////////////
//
int8 eeprom_24c02_ready(void)
{
        int1 ack;

  i2c_start();                            // If write cmd is acknowledged,
        ack = i2c_write(0xa0);                  // then the device is ready.
        i2c_stop();

        return (0==ack) ? 0xff : 0;
}//end eeprom_24c02_ready()

///////////////////////////////////////////////////////////////////////////////
//
void eeprom_24c02_write(int8 addr, int8 data)
{
        while(0 == eeprom_24c02_ready());       // wait 24c02 ready
        i2c_start();
        i2c_write(0xa0);
        i2c_write(addr);
        i2c_write(data);
        i2c_stop();
}//end eeprom_24c02_write()

///////////////////////////////////////////////////////////////////////////////
//
int8 eeprom_24c02_read(int8 addr)
{
        int8 data;

        while(0 == eeprom_24c02_ready());       // wait 24c02 ready
        i2c_start();
        i2c_write(0xa0);
        i2c_write(addr);
        i2c_start();
        i2c_write(0xa1);
        data = i2c_read(0);
        i2c_stop();

        return(data);
}//end eeprom_24c02_read()

///////////////////////////////////////////////////////////////////////////////
//
int8 eeprom_24c02_test(void)
{
        int16 i;

        // write 0x55 test
        for(i=0; i<eeprom_24c02_size;>                {

      eeprom_24c02_write(i, 0x55);
                }
        for(i=0; i<eeprom_24c02_size;>                {
                if(0x55 != eeprom_24c02_read(i)) return 0;
                }

        // write 0xaa test
        for(i=0; i<eeprom_24c02_size;>                {
                eeprom_24c02_write(i, 0xaa);
                }
        for(i=0; i<eeprom_24c02_size;>                {
                if(0xaa != eeprom_24c02_read(i)) return 0;
                }
        
        // write eeprom 0
        for(i=0; i<eeprom_24c02_size;>                {
                eeprom_24c02_write(i, 0x00);
                }
        return 0xff;
}//end eeprom_24c02_test()


/*===========================================================================*/
void main(void)
{
        init_eeprom_24c02();

 // 24c02 is ready
        if(0 != eeprom_24c02_ready())
                {
                output_high(PIN_C0);
                }

        // test 24c02
        if(0 != eeprom_24c02_test())
                {
                output_high(PIN_C7);
                delay_ms(1000);                
                }
        
        // write 24c02
        eeprom_24c02_write(0, 0xaa);
        

// read 24c02
        output_c(eeprom_24c02_read(0));

}//end main()

广安市| 普安县| 洪泽县| 丹巴县| 桐梓县| 万宁市| 疏附县| 南岸区| 根河市| 玉门市| 河北省| 庆安县| 三亚市| 东源县| 渑池县| 和平县| 喀什市| 翁牛特旗| 手游| 满洲里市| 鹤庆县| 青铜峡市| 四子王旗| 焉耆| 文山县| 普洱| 阳原县| 亚东县| 获嘉县| 阜宁县| 莫力| 揭东县| 灵璧县| 宁化县| 澳门| 大理市| 繁昌县| 乐东| 丹巴县| 疏勒县| 横峰县|