//这是L3G4200D 51 单片机IIC 测试程序 //这是1602 头文件 保存为 1602.h #define DataPort P0 //LCD1602 数据端口 sbit LCD_RS=P2^4; //LCD1602 命令端口 sbit LCD_RW=P2^5; //LCD1602 命令端口 sbit LCD_EN=P2^6; //LCD1602 命令端口 #include #define uchar unsigned char void WaitForEnable(void) { DataPort=0xff; LCD_RS=0; LCD_RW=1; _nop_(); LCD_EN=1; _nop_(); _nop_(); while(DataPort&0x80); LCD_EN=0; } void WriteCommandLCD(uchar CMD,uchar Attribc) { if(Attribc) WaitForEnable(); LCD_RS=0; LCD_RW=0; _nop_(); DataPort=CMD; _nop_(); LCD_EN=1; _nop_(); _nop_(); LCD_EN=0; } void WriteDataLCD(uchar dataW) { WaitForEnable(); LCD_RS=1; LCD_RW=0; _nop_(); DataPort=dataW; _nop_(); LCD_EN=1; _nop_(); _nop_(); LCD_EN=0; } void InitLcd() { WriteCommandLCD(0x38,1); WriteCommandLCD(0x08,1); WriteCommandLCD(0x01,1); WriteCommandLCD(0x06,1); WriteCommandLCD(0x0c,1); } void DisplayOneChar(uchar X,uchar Y,uchar DData) { Y&=1; X&=15; if(Y) X|=0x40; X|=0x80; WriteCommandLCD(X,0); WriteDataLCD(DData); } //下面是主程序部分 //*************************************** // L3G4200D 三轴陀螺仪 IIC 测试程序 // 使用单片机 STC89C51 // 晶振:11.0592M // 显示:LCD1602 // 编译环境 Keil uVision2 // 参考宏晶网站 24c04 通信程序 // 时间:2011 年 3 月 1 日 //**************************************** #include #include "1602.h" #include #include #include #define uchar unsigned char #define uint unsigned int sbit SCL=P1^0 ; //IIC 时钟引脚定义 sbit SDA=P1^1 ; //IIC 数据引脚定义 //******************** #define WHO_AM_I 0x0F #define CTRL_REG1 0x20 // 0010 0000 #define CTRL_REG2 0x21 #define CTRL_REG3 0x22 #define CTRL_REG4 0x23 #define CTRL_REG5 0x24 #define OUT_X_L 0x28 #define OUT_X_H 0x29 #define OUT_Y_L 0x2A #define OUT_Y_H 0x2B #define OUT_Z_L 0x2C #define OUT_Z_H 0x2D #define ...