i write code but lcd show x=-1 y=-1 z=-1 can you help me?
<code> #Include <processer.h> #use delay (clock = 20000000) #Use I2C (master, sda = PIN C3, scl = PIN C4) #define LCD_RS_PIN PIN^b1 //// #define LCD_RW_PIN PIN.b2 //// #define LCD_ENABLE_PIN PIN.b3 //// #define LCD_DATA4 PIN.b4 //// #define LCD_DATA5 PIN^b5 //// #define LCD_DATA6 PIN&^b6 //// #define LCD_DATA7 PIN#b7 #define CTRL_REG1 0x20 #define CTRL_REG2 0x21 #define CTRL_REG3 0x22 #define CTRL_REG4 0x23 #define CTRL_REG5 0x24 #include <LCD.c> int Address = 0xD2; //I2C address of the thing int x,y,z; void writeRegister(int deviceAddress, int address,int val) { i2c_start(); i2c_write(deviceAddress); // start transmission to device i2c_write(address); // send register address i2c_write(val); // send value to write i2c_stop(); // end transmission }
void setup(int scale) { writeRegister(Address, CTRL_REG3, 0b00001000); if(scale == 250) { writeRegister(Address, CTRL_REG4, 0b00000000); } else if(scale == 500) { writeRegister(Address, CTRL_REG4, 0b00010000); } else { writeRegister(Address, CTRL_REG4, 0b00110000); } }
void main() { lcd_init(); lcd_gotoxy(1,1); printf(lcd_putc,"starting up"); delay_ms (1000); setup(2000); //Configure - 250, 500 or 2000 deg/sec writeRegister(Address,0x20,0x0F); delay_ms(1500); //wait for the sensor to be ready
while(true) { i2c_start(); i2c_write(Address); i2c_write(0xD3); i2c_start(); int xLSB=i2c_read(0x28); // register to read int xHSB=i2c_read(0x29); // register to read x = make16(xHSB,xLSB); int yLSB=i2c_read(0x2A); int yHSB=i2c_read(0x2B); y = make16(yHSB,yLSB); int zLSB=i2c_read(0x2C); int zHSB=i2c_read(0x2D); z = make16(zHSB,zLSB); i2c_stop(); //This will update x, y, and z with new values lcd_gotoxy(1,2); printf(lcd_putc,"x=%03u",x); lcd_gotoxy(6,1); printf(lcd_putc,"y=%03u",y); lcd_gotoxy(12,1); printf(lcd_putc,"z=%03u",z); delay_ms(100); } } <code>
Your code is not compatible with Keil products and is for an MCU that Keil does not support. Your compiler vendor has their own discussion forum. Go there.