• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 讀寫24LCxx系列的EEPROM的C語言程序?qū)嵗?/p>

    讀寫24LCxx系列的EEPROM的C語言程序?qū)嵗?/h1>
    作者: 時間:2012-07-18 來源:網(wǎng)絡(luò) 收藏

    PIC:C

    本文引用地址:http://www.czjhyjcfj.com/article/171142.htm

    //*********************************************************
    //* Using I2C Master Mode for access Slave (EEPRM)
    //*
    //* Written by: Richard Yang
    //* Sr. Corporate Application Engineer
    //* Microchip Technology Inc.
    //* Date: Oct. 3nd '2002
    //* Revision: 1.00
    //* Language tools : MPLAB-C18 v2.09.13
    //* MPLINK v3.10
    //* MPLAB-IDE v6.00.17 ICD2
    //***********************************************************
    /* Include Header files */

    #i nclude p18f452.h>
    #i nclude i2c.h> // Load I2C Header file from defult direct
    #i nclude timers.h>
    #i nclude P18LCD.h // Load P18LCD Header file form current working direct

    /* Declare the Function Prototype */

    void Initialize_I2C_Master(void);
    void EE_Page_Write(unsigned char,unsigned char,unsigned char,unsigned char *);
    void EE_SEQU_Read(unsigned char,unsigned char,unsigned char,unsigned char *);
    void _Write(unsigned char,unsigned char,unsigned char);
    void _ACK(unsigned char);
    unsigned char EEPROM_Read(unsigned char,unsigned char);
    void I2C_Done(void);
    void Initialize_Timer2(void);
    void isr_high_direct(void);
    void isr_high(void);

    #pragma romdata My_romdata=0x1000
    const rom far unsigned char LCD_MSG1[]=SW2: Byte Write ;
    const rom far unsigned char LCD_MSG2[]=SW6: Random Read;
    const rom far unsigned char LCD_MSG3[]=Byte Write Mode ;
    const rom far unsigned char LCD_MSG4[]=Random Read Mode;
    const rom far unsigned char LCD_MSG5[]=Sended: ;
    const rom far unsigned char LCD_MSG6[]=Send: ;
    const rom unsigned char I2C_Write_Buffer[]=Microchip Technology;
    #pragma romdata

    /* Define following array in data memory */

    unsigned char I2C_Read_Buffer [32];

    /* define following variable in data memory at Access Bank */
    #pragma udata access My_RAM
    near unsigned char Debounce;
    near unsigned char Send_Addr;
    near unsigned char Send_Data;
    near unsigned char Send_Length;
    near unsigned char Read_Data;
    near unsigned char P_SW2;
    near unsigned char P_SW6;
    #pragma udata

    #define Page_Length 8
    #define SW2 PORTAbits.RA4
    #define SW6 PORTEbits.RE1
    #define Bounce_Time 6
    #define EE_CMD 0xA0

    //***********************************************************
    /* */
    /* Main Program */
    /* */
    //***********************************************************


    void main(void)
    {
    ADCON1=0b00000110; // Disable A/D Function
    TRISAbits.TRISA4=1; // Set SW2 for input
    TRISEbits.TRISE1=1; // Set SW6 for Input
    Initialize_Timer2( );
    Initialize_I2C_Master( );
    OpenLCD( );

    if (SW2 SW6)Debounce=0;
    else Debounce = Bounce_Time;

    while(1)
    {
    LCD_Set_Cursor(0,0); // Put LCD Cursor on (0,0)
    putrsLCD(LCD_MSG1);
    LCD_Set_Cursor(1,0); // Put LCD Cursor on (1,0)
    putrsLCD(LCD_MSG2);

    P_SW2=P_SW6=0;
    Send_Addr=0;

    while(1)
    {
    if (P_SW2)
    {
    P_SW2=0;
    Debounce = Bounce_Time;
    LCD_Set_Cursor(0,0); // Put LCD Cursor on (0,0)
    putrsLCD(LCD_MSG3);
    LCD_Set_Cursor(1,0); // Put LCD Cursor on (0,0)
    putrsLCD(LCD_MSG5);

    do
    {
    while (!P_SW2);
    P_SW2=0;
    LCD_Set_Cursor(1,8);
    Send_Data=I2C_Write_Buffer[Send_Addr];
    EEPROM_Write(EE_CMD,Send_Addr,Send_Data);
    puthexLCD(EE_CMD);
    putcLCD(' ');
    puthexLCD(Send_Addr);
    putcLCD(' ');
    puthexLCD(Send_Data);
    EEPROM_ACK(EE_CMD);
    Send_Addr++;
    } while (I2C_Write_Buffer[Send_Addr]!=0x00);
    break;
    }

    if (P_SW6)
    {
    P_SW6=0;
    Debounce = Bounce_Time;
    LCD_Set_Cursor(0,0); // Put LCD Cursor on (0,0)
    putrsLCD(LCD_MSG4);
    LCD_Set_Cursor(1,0); // Put LCD Cursor on (0,0)
    putrsLCD(LCD_MSG6);


    while(1)
    {
    if (P_SW6)
    {
    P_SW6=0;
    LCD_Set_Cursor(1,5);
    Read_Data = EEPROM_Read(EE_CMD,Send_Addr);
    puthexLCD(EE_CMD);
    putcLCD(' ');
    puthexLCD(Send_Addr);
    putcLCD(' ');
    puthexLCD(EE_CMD);
    putcLCD(' ');
    puthexLCD(Read_Data);
    Send_Addr++;
    }
    if (P_SW2) break;
    }
    if (P_SW2) break;
    }
    if (P_SW2)
    {
    P_SW2=0;
    break;
    }
    }
    }
    }
    //************************************************
    //* #pragma Interrupt Declarations *
    //* *
    //* Function: isr_high_direct *
    //* - Direct execution to the actual *
    //* high-priority interrupt code. *
    //************************************************
    #pragma code isrhighcode = 0x0008

    void isr_high_direct(void)
    {
    _asm //begin in-line assembly
    goto isr_high //go to isr_high function
    _endasm //end in-line assembly
    }

    c語言相關(guān)文章:c語言教程



    上一頁 1 2 3 下一頁


    評論


    相關(guān)推薦

    技術(shù)專區(qū)

    關(guān)閉
    主站蜘蛛池模板: 十堰市| 新昌县| 普兰店市| 潢川县| 赤城县| 信丰县| 兴安县| 兴宁市| 连平县| 静安区| 措勤县| 中卫市| 孝昌县| 图们市| 神池县| 隆回县| 通化市| 玛纳斯县| 鄄城县| 隆昌县| 萝北县| 天津市| 曲阳县| 新丰县| 东平县| 阿城市| 东丰县| 西城区| 冕宁县| 南丹县| 宜都市| 沙田区| 锡林浩特市| 页游| 松江区| 山东省| 鱼台县| 霍城县| 揭阳市| 杭锦后旗| 南澳县|