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.
i2c.cpp
00001 #if 0 00002 00003 /*************************************************************************** 00004 * Titel : I2C.C 00005 * 00006 * Beschreibung : IIC - Interface 00007 * 00008 * Kategorie : 00009 * 00010 * Verantwortlich : Jens Altenburg 00011 * 00012 * Modulhistory : 00013 * 00014 ---------------------------------------------------------------------------- 00015 Date | Author | Change 00016 ---------------------------------------------------------------------------- 00017 28.09.03 | J. Altenburg | Ersterstellung 00018 ---------------------------------------------------------------------------- 00019 00020 ****************************************************************************/ 00021 00022 /*************************************************************************** 00023 * HEADER-FILES (Only those that are needed in this file) 00024 ****************************************************************************/ 00025 /* Own headerfiles */ 00026 #include "i2c.h" /* */ 00027 00028 00029 00030 /*************************************************************************** 00031 * FILE LOCAL DEFINITIONS 00032 * 00033 * In this section define 00034 * - all file local macros 00035 * - all file local define-constants 00036 * - all file local ROM-constants (static) 00037 * - all file local type definitions 00038 * - all file local variables (static) 00039 ****************************************************************************/ 00040 #define nShortDelay 20 /* Verzögerungszeit für I2C */ 00041 00042 00043 /*************************************************************************** 00044 * Variablendefinitionen 00045 ****************************************************************************/ 00046 00047 00048 /*************************************************************************** 00049 * Definition der einzelnen I2C-Befehle 00050 ****************************************************************************/ 00051 #define _0 0xb0 00052 #define _1 0xb1 00053 #define _2 0xb2 00054 #define _3 0xb3 00055 #define _4 0xb4 00056 #define _5 0xb5 00057 #define _6 0xb6 00058 #define _7 0xb7 00059 #define _8 0xb8 00060 #define _9 0xb9 00061 00062 const byte abInit[] = {0x74, 0x00, 0x25, 0x06, 0x24, 0x0f, 0x84}; 00063 const byte abCls[] = {0x74, 0x00, 0x84}; 00064 const byte abText1[] = {0x74, 0x40, 0xe3, 0xa7, 0xf4, 0xad, 0xd2, 0xef, 0xe2}; 00065 const byte abZeile2[] = {0x74, 0x00, 0xc4}; 00066 const byte abNr0[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _0}; 00067 const byte abNr1[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _1}; 00068 const byte abNr2[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _2}; 00069 const byte abNr3[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _3}; 00070 const byte abNr4[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _4}; 00071 const byte abNr5[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _5}; 00072 const byte abNr6[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _6}; 00073 const byte abNr7[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _7}; 00074 const byte abNr8[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _8}; 00075 const byte abNr9[] = {0x74, 0x40, 0xd3, 0xf4, 0xe1, 0xf4, 0xe5, 0xa0, _9}; 00076 00077 00078 /***************************************************************************** 00079 Name: vStarti2c() 00080 Parameters: none 00081 Returns: nothing 00082 Description: Generiert das Startsignal für I2C-Bus 00083 00084 ******************************************************************************/ 00085 void vStarti2c(void){ 00086 vDelay(nShortDelay); 00087 SDA(); /* data high */ 00088 vDelay(nShortDelay); 00089 SCL(); /* clk high */ 00090 vDelay(nShortDelay); 00091 _SDA(); /* data low */ 00092 vDelay(nShortDelay); 00093 _SCL(); /* clk low */ 00094 vDelay(nShortDelay); 00095 } 00096 00097 /***************************************************************************** 00098 Name: vStopi2c() 00099 Parameters: none 00100 Returns: nothing 00101 Description: Generiert das Stopsignal für I2C-Bus 00102 00103 ******************************************************************************/ 00104 void vStopi2c(void){ 00105 vDelay(nShortDelay); 00106 _SDA(); /* data low */ 00107 vDelay(nShortDelay); 00108 SCL(); /* clk high */ 00109 vDelay(nShortDelay); 00110 SDA(); /* data high */ 00111 vDelay(nShortDelay); 00112 } 00113 00114 00115 /***************************************************************************** 00116 Name: vWriteBi2c() 00117 Parameters: Byte 00118 Returns: nothing 00119 Description: Schreibt in Byte auf den I2C-Bus 00120 00121 ******************************************************************************/ 00122 void vWriteBi2c(byte bData){ 00123 byte i = 0; 00124 vDelay(nShortDelay); 00125 _SCL(); 00126 vDelay(nShortDelay); 00127 for ( i = 0; i < 8; i++){ 00128 if ((bData & 0x80) == 0x80){ 00129 SDA(); /* Bit := 1 */ 00130 } 00131 else{ 00132 _SDA(); /* Bit := 0 */ 00133 } 00134 bData <<= 1; 00135 vDelay(nShortDelay); 00136 SCL(); 00137 vDelay(nShortDelay); 00138 _SCL(); 00139 vDelay(nShortDelay); 00140 } 00141 _SDA(); 00142 vDelay(nShortDelay); 00143 SCL(); 00144 vDelay(nShortDelay); 00145 _SCL(); 00146 vDelay(nShortDelay); 00147 } 00148 00149 /***************************************************************************** 00150 Name: vDelay() 00151 Parameters: Byte 00152 Returns: nothing 00153 Description: Laufzeitschleife 00154 00155 ******************************************************************************/ 00156 void vDelay(byte bTime){ 00157 while(bTime){ 00158 bTime--; 00159 } 00160 } 00161 00162 /***************************************************************************** 00163 Name: vSendI2C() 00164 Parameters: Zeichenanzahl, String 00165 Returns: nothing 00166 Description: Schickt den String zum I2C Bus 00167 00168 ******************************************************************************/ 00169 void vSendI2C(byte bLen, byte *pStr){ 00170 word w = 500; 00171 while(w--); 00172 vStarti2c(); 00173 while(bLen){ 00174 vWriteBi2c(*pStr); 00175 pStr++; 00176 bLen--; 00177 } 00178 vStopi2c(); 00179 } 00180 00181 /*************************************************************************** 00182 * Kurzbeschreibung : OV6620 (OV6630) initialisieren 00183 * Uebergabeparameter : -- 00184 * Return Value : -- 00185 * Author : Jens Altenburg 00186 ****************************************************************************/ 00187 void I2C_vInit( void ){ 00188 vSendI2C(sizeof(abInit), (byte *) &abInit[0]); 00189 vSendI2C(sizeof(abCls), (byte *) &abCls[0]); 00190 vSendI2C(sizeof(abText1), (byte *) &abText1[0]); 00191 vSendI2C(sizeof(abZeile2), (byte *) &abZeile2[0]); 00192 vSendI2C(sizeof(abNr0), (byte *) &abNr0[0]); 00193 } 00194 00195 void I2C_vState(byte bState){ 00196 vSendI2C(sizeof(abZeile2), (byte *) &abZeile2[0]); 00197 switch(bState){ 00198 case 0: 00199 vSendI2C(sizeof(abNr0), (byte *) &abNr0[0]); 00200 break; 00201 case 1: 00202 vSendI2C(sizeof(abNr1), (byte *) &abNr1[0]); 00203 break; 00204 case 2: 00205 vSendI2C(sizeof(abNr2), (byte *) &abNr2[0]); 00206 break; 00207 case 3: 00208 vSendI2C(sizeof(abNr3), (byte *) &abNr3[0]); 00209 break; 00210 case 4: 00211 vSendI2C(sizeof(abNr4), (byte *) &abNr4[0]); 00212 break; 00213 case 5: 00214 vSendI2C(sizeof(abNr5), (byte *) &abNr5[0]); 00215 break; 00216 case 6: 00217 vSendI2C(sizeof(abNr6), (byte *) &abNr6[0]); 00218 break; 00219 case 7: 00220 vSendI2C(sizeof(abNr7), (byte *) &abNr7[0]); 00221 break; 00222 case 8: 00223 vSendI2C(sizeof(abNr8), (byte *) &abNr8[0]); 00224 break; 00225 case 9: 00226 vSendI2C(sizeof(abNr9), (byte *) &abNr9[0]); 00227 break; 00228 } 00229 } 00230 /*************************************************************************** 00231 * EOF: SWMODxC1.C 00232 ****************************************************************************/ 00233 #endif
Generated on Wed Aug 3 2022 18:44:12 by
1.7.2