Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 #define EE_READ 0x400 // 10 XXXXXXXXX(A8-A0) 00004 #define EE_WRITE 0x200 // 01 XXXXXXXXX(A8-A0) 00005 #define EE_EWEN 0x1FF // 00 11XXXXXXX(X is DONT CARE) 00006 #define EE_EWDS 0x000 // 00 00XXXXXXX(X is DONT CARE) 00007 #define EE_ERASE 0x600 // 11 XXXXXXXXX(A8-A0) 00008 00009 Serial device(PA_9, PA_10); // tx, rx 00010 DigitalOut CS(PC_0); 00011 DigitalOut CK(PB_13); 00012 DigitalIn DI(PB_14); 00013 DigitalOut DO(PB_15); 00014 00015 void vSend(unsigned short usCommand) 00016 { 00017 signed char i=10; 00018 DO=1; //SB 00019 CS=1; // Chip Select High 00020 wait_us(1); // SB Clock Generation 00021 CK=1; 00022 wait_us(1); 00023 CK=0; 00024 while(i>=0) 00025 { 00026 DO = (usCommand>>i)&0x01; 00027 i--; 00028 wait_us(1); 00029 CK=1; 00030 wait_us(1); 00031 CK=0; 00032 } 00033 } 00034 void vWriteEnable() 00035 { 00036 vSend(EE_EWEN); 00037 wait_us(1); 00038 CS=0; //Chip Select Low 00039 } 00040 void vWriteDisable() 00041 { 00042 vSend(EE_EWDS); 00043 wait_us(1); 00044 CS=0; //Chip Select Low 00045 } 00046 void vErase(unsigned short usAddr) 00047 { 00048 vSend(EE_ERASE|usAddr); 00049 wait_us(1); 00050 CS=0; 00051 /** wait busy flag clear */ 00052 wait_us(1); // tcs > 250ns @2.7V 00053 CS=1; 00054 wait_us(1); // tsv < 250ns @2.7V 00055 while(DI==0); // 0.1ms < twp < 10ms 00056 CS=0; 00057 } 00058 void vWrite(unsigned short usAddr, unsigned char ucData) 00059 { 00060 signed char i=7; 00061 vSend(EE_WRITE|usAddr); 00062 for(i=7;i>=0;i--) 00063 { 00064 DO = (int)( (ucData>>i)&0x0001 ); 00065 wait_us(1); 00066 CK=1; 00067 wait_us(1); 00068 CK=0; 00069 } 00070 CS=0; 00071 /** wait busy flag clear */ 00072 wait_us(1); // tcs > 250ns @2.7V 00073 CS=1; 00074 wait_us(1); // tsv < 250ns @2.7V 00075 while(DI==0); // 0.1ms < twp < 10ms 00076 CS=0; 00077 } 00078 unsigned char ucRead(unsigned short usAddr) 00079 { 00080 unsigned char data=0; 00081 signed char i=7; 00082 00083 vSend(EE_READ|usAddr); 00084 wait_us(1); 00085 00086 for(i=7;i>=0;i--) 00087 { 00088 CK=1; 00089 wait_us(1); 00090 CK=0; 00091 data = data | (DI<<i); 00092 wait_us(1); 00093 } 00094 CS=0; 00095 00096 return data; 00097 } 00098 int main() 00099 { 00100 unsigned char ucI=0; 00101 00102 CS = 0; //default state for Chip Select and Clock 00103 CK = 0; 00104 00105 device.baud(19200); 00106 device.printf("The Program demostrating the IC AT93C56 EEPROM \r\n"); 00107 00108 device.printf("Going to Write Enable \r\n"); 00109 vWriteEnable(); 00110 00111 device.printf("Going to Erase Addr 0 \r\n"); 00112 vErase(0); 00113 device.printf("Going to Write Value AA to Addr 0 \r\n"); 00114 vWrite(0,0xAA); 00115 device.printf("Read Back Value %04X\r\n,",ucRead(0)); 00116 00117 device.printf("Going to Erase Addr 1 \r\n"); 00118 vErase(1); 00119 device.printf("Going to Write Value BB to Addr 1 \r\n"); 00120 vWrite(1,0xBB); 00121 device.printf("Read Back Value %04X\r\n,",ucRead(1)); 00122 00123 device.printf("Going to Erase Addr 2 \r\n"); 00124 vErase(2); 00125 device.printf("Going to Write Value CC to Addr 2 \r\n"); 00126 vWrite(2,0xCC); 00127 device.printf("Read Back Value %04X\r\n,",ucRead(2)); 00128 00129 device.printf("Going to Write Disable \r\n"); 00130 00131 vWriteDisable(); 00132 00133 while(1) 00134 { 00135 for(ucI=0;ucI<64;ucI++) 00136 { 00137 device.printf("%04X ============== %d\r\n,",ucRead(ucI),ucI); 00138 wait(0.5); 00139 } 00140 } 00141 }
Generated on Fri Jul 29 2022 03:29:04 by
1.7.2