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

Parents
  • 101 SCL=0;



    102 }



    103



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



    105 调用方式:uchar I2CReceive(void) ﹫2001/07/0 5



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



    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 /*--------------------------------------------------------------------------------


Reply
  • 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 /*--------------------------------------------------------------------------------


Children
  • 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