balasiva2020
Newbie level 3
- Joined
- Feb 10, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,318
This is my code(i2c with EEPROM INTERFACE) which is not working. So please help me
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 #include <LPC214X.H> #define bitset(var,bitno) ((var)|=1<<(bitno)) #define bitclr(var,bitno) ((var)&=~(1<<(bitno))) // Timer.h for lpc2148 #define PLOCK 0x00000400 #define PRESCALE 60000 //================================ typedef unsigned long int int32; typedef unsigned char int8; //================================ void set_clock(void); void timer_init(void); void delay_ms(int32); typedef unsigned char int8; void I2C_START(); void I2C_WRITE(int8 data); void I2C_STOP(); void i2c_init(void); void delay(int); void lcd_ini(); void lcdcmd(char); void lcddat(char); int main() { char temp; set_clock(); PINSEL0=0X00000050; PINSEL1=0X00000000; IODIR0=0XFFFFFFF0; IOCLR0=0xFFFFFFFF; lcd_ini(); i2c_init(); while(1) { I2C_START(); I2C_WRITE(0xA0); I2C_WRITE(0); I2C_WRITE('K'); I2C_STOP(); delay(1000); I2C_START(); I2C_WRITE(0xA0); I2C_WRITE(0); I2C_START(); I2C_WRITE(0xA1); temp=(I2C0DAT); lcddat(temp); I2C_STOP(); } } void I2C_START() { I2C0CONCLR=0x08; I2C0CONSET=0x20; while(!(I2C0STAT&0x08)); I2C0CONCLR=0x20; } void I2C_WRITE(int8 data) { I2C0DAT=data; I2C0CONCLR=0x08; while(!(I2C0STAT&0x18)); } void I2C_STOP() { I2C0CONCLR=0x00; I2C0CONSET=0x14; while(!(I2C0STAT&0xA0)); } void i2c_init() { I2C0CONCLR=0XFF; I2C0CONSET=0X44; // CLEAR ALL FLAGS I2C0CONSET = 0x20; //Enable the I2C interface I2C0SCLH=0x0C; // Clock High 147 I2C0SCLL=0x0D; // CLOCK Low 147 } void lcd_ini() { lcdcmd(0x38); lcdcmd(0x0e); lcdcmd(0x06); lcdcmd(0x01); lcdcmd(0x80); } void lcdcmd(char dat) { IOCLR0|=0XFF<<16; bitclr(IOPIN0,10); //RS=0 bitset(IOPIN0,13); // EN=1 IOPIN0|=dat<<16; delay(1000); bitclr(IOPIN0,13); //EN=0 } void lcddat(char dat) { IOCLR0|=0XFF<<16; bitset(IOPIN0,10); //RS=1 bitset(IOPIN0,13); // EN=1 IOPIN0|=dat<<16; delay(1000); bitclr(IOPIN0,13); //EN=0 } void delay(int y) { int r,t; for(r=0;r<y;r++) for(t=0;t<60;t++); } //================================ void set_clock(void) { PLL0CON = 0x01; PLL0CFG = 0x24; // PCLK = (5*Fosc) => 60MHz PLL0FEED = 0xAA; // Feed sequence to enable the Control & config data PLL0FEED = 0x55; while( !(PLL0STAT & PLOCK )); PLL0CON = 0x03; PLL0FEED = 0xAA; // Feed sequence to enable the Control & config data PLL0FEED = 0x55; VPBDIV = 0x01; // Assigning PCLK = CCLK }
Last edited by a moderator: