天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

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

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

開發(fā)工具

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

技術(shù)支持

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

新品推廣

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

新聞中心

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

CCSC i2c.c程序訪問MCD2demo 24C02EEPROM

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

十年專注單片機方案開發(fā)的方案公司英銳恩,分享CCSC i2c.c程序訪問MCD2demo 24C02EEPROM。英銳恩現(xiàn)提供服務產(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()

联系我们: 星座| 休宁县| 巫溪县| 玛沁县| 穆棱市| 巴东县| 资讯| 松滋市| 彝良县| 靖西县| 英吉沙县| 陆川县| 镇原县| 峨眉山市| 威海市| 惠安县| 邛崃市| 甘南县| 合山市| 武功县| 桂东县| 大石桥市| 镇雄县| 云龙县| 广东省| 博爱县| 宜兰市| 荣昌县| 上杭县| 勃利县| 介休市| 榆中县| 锡林浩特市| 安福县| 嘉禾县| 托克逊县| 河北区| 江源县| 武冈市| 毕节市| 大安市|