This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C Read,Write

Hi,
I have come over the problem with LCD.
Thankx to all.Any one req. LCD C code can contact me by posting his/her email on this thread.

Now i have connected P2.0 to SDA and P2.1 to SCL of AT24C04 EEPROM.
Can any one give me his codes for refrance regarding how to READ and WRITE to 24C04.


*RU2

  • Hey People,

    Anyone have not exprimented on I2C EEPROM AT24C04.No replies !!!

    Let me know if there is other popular EEPROM.

    rutu.

  • Anyone have not exprimented on I2C EEPROM AT24C04.No replies !!!
    Many have, no replies because

    Can any one give me his codes for refrance

    Because we all know what "for reference" means.

    Erik

  • Have you tried the Atmel website? The application notes there will be most informative.

  • hi,

    dear erik there can be person who in reality need only to study and not to copy and put there own tag.If all think the same way then we want have learned advance things.Anyway thanks for time u spend in replying.

    hi Barry
    thanks for u r suggestion, i have already tried all the possible manual on I2C.Now i am through with the pins on 24C04 but don't know how to implement it in C on microcontroller.That is my main problem.

    Thanks all
    rutu

  • by the way:chinese language


    文件: PCF8563T.C 2001-11-27, 18:39:20


    1 /**————————————————————


    2 〖说明〗I2C总线驱动程序(用两个普通IO模拟I2C总线)


    3 包括100Khz(T=10us)的标准模式(慢速模式)选择,


    4 和400Khz(T=2.5us)的快速模式选择,


    5 默认11.0592Mhz的晶振。


    6 〖文件〗PCF8563T.C ﹫2001/11/2 7


    7 〖作者〗





    8 〖修改〗


    9 〖版本〗V1.00A Build 0803


    10 —————————————————————*/


    11


    12 #ifndef SDA


    13 #define SDA P0_0


    14 #define SCL P0_1


    15 #endif


    16


    17 extern uchar SystemError;


    18


    19 #define uchar unsigned char


    20 #define uint unsigned int


    21 #define Byte unsigned char


    22 #define Word unsigned int


    23 #define bool bit


    24 #define true 1


    25 #define false 0


    26


    27 #define SomeNOP(); _nop_();_nop_();_nop_();_nop_();


    28


    29 /**--------------------------------------------------------------------------------


    30 调用方式:void I2CStart(void) ﹫2001/07/0 4


    31 函数说明:私有函数,I2C专用


    32 ---------------------------------------------------------------------------------*/


    33 void I2CStart(void)


    34 {


    35 EA=0;


    36 SDA=1; SCL=1; SomeNOP();//INI


    37 SDA=0; SomeNOP(); //START


    38 SCL=0;


    39 }


    40


    41 /**--------------------------------------------------------------------------------


    42 调用方式:void I2CStop(void) ﹫2001/07/0 4


    43 函数说明:私有函数,I2C专用


    44 ---------------------------------------------------------------------------------*/


    45 void I2CStop(void)


    46 {


    47 SCL=0; SDA=0; SomeNOP(); //INI


    48 SCL=1; SomeNOP(); SDA=1; //STOP


    49 EA=1;


    50 }


    51


    52 /**--------------------------------------------------------------------------------


    53 调用方式:bit I2CAck(void) ﹫2001/07/0 4


    54 函数说明:私有函数,I2C专用,等待从器件接收方的应答


    55 ---------------------------------------------------------------------------------*/


    56 bool WaitAck(void)


    57 {


    58 uchar errtime=255;//因故障接收方无ACK,超时值为255。


    59 SDA=1;SomeNOP();


    60 SCL=1;SomeNOP();


    61 while(SDA) {errtime--; if (!errtime) {I2CStop();SystemError=0x11;return false;}}


    62 SCL=0;


    63 return true;


    第1 页


    文件: PCF8563T.C 2001-11-27, 18:39:20


    64 }


    65


    66 /**--------------------------------------------------------------------------------


    67 调用方式:void SendAck(void) ﹫2001/07/0 4


    68 函数说明:私有函数,I2C专用,主器件为接收方,从器件为发送方时,应答信号。


    69 ---------------------------------------------------------------------------------*/


    70 void SendAck(void)


    71 {


    72 SDA=0; SomeNOP();


    73 SCL=1; SomeNOP();


    74 SCL=0;


    75 }


    76


    77 /**--------------------------------------------------------------------------------


    78 调用方式:void SendAck(void) ﹫2001/07/0 4


    79 函数说明:私有函数,I2C专用,主器件为接收方,从器件为发送方时,非应答信号。


    80 }**--------------------------------------------------------------------------------


    81 void SendNotAck(void)


    82 {


    83 SDA=1; SomeNOP();


    84 SCL=1; SomeNOP();


    85 SCL=0;


    86 }


    87


    88 /**--------------------------------------------------------------------------------


    89 调用方式:void I2CSend(uchar ch) ﹫2001/07/0 5


    90 函数说明:私有函数,I2C专用


    91 ---------------------------------------------------------------------------------*/


    92 void I2CSendByte(Byte ch)


    93 {


    94 uchar i=8;


    95 while (i--)


    96 {


    97 SCL=0;_nop_();


    98 SDA=(bit)(ch&0x80); ch<<=1; SomeNOP();


    99 SCL=1; SomeNOP();


    100 }

  • 101 SCL=0;



    102 }



    103



    104 /**--------------------------------------------------------------------------------



    105 &#35843;&#29992;&#26041;&#24335;&#65306;uchar I2CReceive(void) &#65131;2001/07/0 5



    106 &#20989;&#25968;&#35828;&#26126;&#65306;&#31169;&#26377;&#20989;&#25968;&#65292;I2C&#19987;&#29992;



    107 ---------------------------------------------------------------------------------*/



    108 Byte I2CReceiveByte(void)



    109 {



    110 uchar i=8;



    111 Byte ddata=0;



    112 SDA=1;



    113 while (i--)



    114 {



    115 ddata<<=1;



    116 SCL=0;SomeNOP();



    117 SCL=1;SomeNOP();



    118 ddata|=SDA;



    119 }



    120 SCL=0;



    121 return ddata;



    122 }



    123



    124



    125 //---------------------------------------------------------------------------



    126 //&#24320;&#22987;PCF8563T&#39537;&#21160;&#31243;&#24207;



    &#31532;2 &#39029;



    &#25991;&#20214;: PCF8563T.C 2001-11-27, 18:39:20



    127 /**--------------------------------------------------------------------------------



    128 &#35843;&#29992;&#26041;&#24335;&#65306;void GetPCF8563(uchar firsttype,uchar count,uchar *buff) &#65131;2001/08/0 7



    129 &#20989;&#25968;&#35828;&#26126;&#65306;&#35835;&#21462;&#26102;&#38047;&#33455;&#29255;PCF8563&#30340;&#26102;&#38388;&#65292;&#35774;&#32622;&#35201;&#35835;&#30340;&#31532;&#19968;&#20010;&#26102;&#38388;&#31867;&#22411;firsttype&#65292;&#24182;&#35774;&#32622;&#35835;&#21462;



    130 &#30340;&#23383;&#33410;&#25968;&#65292;&#21017;&#20250;&#19968;&#27425;&#25226;&#26102;&#38388;&#35835;&#21462;&#21040;buff&#20013;&#12290;&#39034;&#24207;&#26159;&#65306;



    131 0x02:&#31186;/0x03:&#20998;/0x04:&#23567;&#26102;/0x05:&#26085;/0x06:&#26143;&#26399;/0x07:&#26376;(&#19990;&#32426;)/0x08:&#24180;



    132 ---------------------------------------------------------------------------------*/



    133 void GetPCF8563(uchar firsttype,uchar count,uchar *buff)



    134 {



    135 uchar i;



    136 I2CStart();



    137 I2CSendByte(0xA2);



    138 WaitAck();



    139 I2CSendByte(firsttype);



    140 WaitAck();



    141



    142 I2CStart();



    143 I2CSendByte(0xA3);



    144 WaitAck();



    145



    146 for (i=0;i<count;i++)



    147 {



    148 buff[i]=I2CReceiveByte();



    149 if (i!=count-1) SendAck();//&#38500;&#26368;&#21518;&#19968;&#20010;&#23383;&#33410;&#22806;&#65292;&#20854;&#20182;&#37117;&#35201;&#20174;MASTER&#21457;&#24212;&#31572;&#12290;



    150 }



    151



    152 SendNotAck();



    153 I2CStop();



    154 }



    155



    156



    157 /**--------------------------------------------------------------------------------



    158 &#35843;&#29992;&#26041;&#24335;&#65306;void SetPCF8563(uchar timetype,uchar value) &#65131;2001/08/0 7



    159 &#20989;&#25968;&#35828;&#26126;&#65306;&#35843;&#25972;&#26102;&#38047;&#12290;timetype&#26159;&#35201;&#25913;&#30340;&#26102;&#38388;&#31867;&#22411;&#65292;value&#26159;&#26032;&#35774;&#32622;&#30340;&#26102;&#38388;&#20540;(BCD&#26684;&#24335;)&#12290;



    160 0x02:&#31186;/0x03:&#20998;/0x04:&#23567;&#26102;/0x05:&#26085;/0x06:&#26143;&#26399;/0x07:&#26376;(&#19990;&#32426;)/0x08:&#24180;



    161 ---------------------------------------------------------------------------------*/



    162 void SetPCF8563(uchar timetype,uchar value)



    163 {



    164 I2CStart();



    165 I2CSendByte(0xA2);



    166 WaitAck();



    167 I2CSendByte(timetype);



    168 WaitAck();



    169 I2CSendByte(value);



    170 WaitAck();



    171 I2CStop();



    172 }



    173



    174 /**--------------------------------------------------------------------------------



    175 &#35843;&#29992;&#26041;&#24335;&#65306;void SetAlarmHour(uchar count) &#65131;2001/08/0 7



    176 &#20989;&#25968;&#35828;&#26126;&#65306;&#35774;&#32622;&#25253;&#35686;&#38393;&#38047;&#22312;&#19968;&#22825;&#30340;&#31532;count&#28857;&#25253;&#35686;&#12290;&#20363;&#22914;&#65306;count&#65309;23&#65292;&#21017;&#22312;&#26202;&#19978;11&#28857;&#25253;&#35686;&#12290;



    177 ---------------------------------------------------------------------------------*/



    178 void SetAlarm(uchar alarmtype,uchar count)



    179 {



    180 SetPCF8563(0x01,0x02);



    181 SetPCF8563(alarmtype,count);



    182 }



    183



    184 /**--------------------------------------------------------------------------------



    185 &#35843;&#29992;&#26041;&#24335;&#65306;void CleanAlarm(void) &#65131;2001/08/0 7



    186 &#20989;&#25968;&#35828;&#26126;&#65306;&#28165;&#38500;&#25152;&#26377;&#25253;&#35686;&#35774;&#32622;&#12290;



    187 ---------------------------------------------------------------------------------*/



    188 void CleanAlarm(void)



    189 {



    &#31532;3 &#39029;



    &#25991;&#20214;: PCF8563T.C 2001-11-27, 18:39:20



    190 SetPCF8563(0x01,0x00);



    191 SetPCF8563(0x09,0x80);



    192 SetPCF8563(0x0A,0x80);



    193 SetPCF8563(0x0B,0x80);



    194 SetPCF8563(0x0C,0x80);



    195 // SetPCF8563(0x0D,0x00);



    196 // SetPCF8563(0x0E,0x03);



    197 }



    198



    199



    200 /*--------------------------------------------------------------------------------


  • 201 &#35843;&#29992;&#26041;&#24335;&#65306;uchar read1380(uchar command )



    202 &#20989;&#25968;&#35828;&#26126;&#65306;read1380()&#36820;&#22238;&#24403;&#21069;&#26102;&#38388;, command&#25351;&#35201;&#36820;&#22238;&#30340;&#26102;&#38388;&#31867;&#22411;&#12290;



    203 &#31186;:81H &#20998;&#38047;:83H &#23567;&#26102;:85H &#26085;&#26399;:87H &#26143;&#26399;:89H &#26143;&#26399;&#20960;:8BH &#24180;:8D H



    204 ---------------------------------------------------------------------------------*/



    205 uchar read1380 (uchar command)



    206 {



    207 uchar time;



    208 GetPCF8563(command,1,&time);



    209 return time;



    210 }



    211



    212 /*--------------------------------------------------------------------------------



    213 &#35843;&#29992;&#26041;&#24335;&#65306;void write1380(uchar command ,uchar time )



    214 &#20989;&#25968;&#35828;&#26126;&#65306;write1380()&#24448;HT1380&#20889;&#21629;&#20196;&#21644;&#25968;&#25454;&#65292;command&#26159;&#21629;&#20196;&#23383;, time&#26159;&#21518;&#20889;&#20837;&#30340;&#25968;&#25454;



    215 ---------------------------------------------------------------------------------*/



    216 void write1380(uchar command ,uchar time)



    217 {



    218 SetPCF8563(command,time);



    219 }



    220



    221



    222 /*--------------------------------------------------------------------------------



    223 &#35843;&#29992;&#26041;&#24335;&#65306;void time_display(uchar x0,uchar y0 )



    224 &#20989;&#25968;&#35828;&#26126;&#65306;time_display()&#22312;&#25351;&#23450;&#30340;x0,y0&#22352;&#26631;&#65292;&#20197;00:00:00&#26684;&#24335;&#26174;&#31034;&#24403;&#21069;&#26102;&#38388;&#12290;



    225 ---------------------------------------------------------------------------------*/



    226 //uchar time[]="00:11:11";



    227



    228 void time_display(uchar x0,uchar y0,bit type) //&#28082;&#26230;&#26102;&#38388;&#26174;&#31034;



    229 {



    230 uchar time[]="00:00:00";



    231 uchar con[3];



    232 uchar time_type;



    233 GetPCF8563(0x02,3,con);



    234



    235 time[0]=(con[2]>>4)+'0';



    236 time[1]=(con[2]&0x0f)+'0';



    237 time[3]=(con[1]>>4)+'0';



    238 time[4]=(con[1]&0x0f)+'0';



    239 time[6]=(con[0]>>4)+'0';



    240 time[7]=(con[0]&0x0f)+'0';



    241



    242 time[8]=0;



    243 if(type==1)



    244 {



    245 time_type=0xff;



    246 }



    247 else



    248 {



    249 time_type=0;



    250 }



    251 dipchar0(x0,y0,F57,1,time_type,time);



    252 }



    &#31532;4 &#39029;



    &#25991;&#20214;: PCF8563T.C 2001-11-27, 18:39:20

  • Thankx haha,

    I will surely let u know if i do any modification or optimization or addition to u r refrance code.

    please give me u r email so that i can share some of my codes with u.

    rutu

  • hi rutu and all:)
    u're welcome.and the code is no mine:),but you can use it anywhere~
    my e-mail:feichen201@hotmail.com