Takeuchi Kouichi
/
25h0922_IMU2_V2
Tamagawaseiki IMU2 Ver2
Fork of AQM0802_test by
Revision 1:bbac27fb013c, committed 2013-09-22
- Comitter:
- takeuchi
- Date:
- Sun Sep 22 03:03:05 2013 +0000
- Parent:
- 0:0543430a6bd1
- Commit message:
- Tamagawa IMU2 Ver2
Changed in this revision
diff -r 0543430a6bd1 -r bbac27fb013c I2cLCD.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2cLCD.cpp Sun Sep 22 03:03:05 2013 +0000 @@ -0,0 +1,176 @@ +#include "I2cLCD.h" +#include "mbed.h" + +#define I2CLCD_ADDR 0x7C + +#define RS_CMD 0x00 +#define RS_DATA 0x40 + +#define FUNC_SET1 0x38 +#define FUNC_SET2 0x39 +#define INT_OSC 0x14 + +#define CNTR_DEF 0x20 + +unsigned char icon_data[]= +{ + 0x00, 0x10, + 0x02, 0x10, + 0x04, 0x10, + 0x06, 0x10, + + 0x07, 0x10, + 0x07, 0x08, + 0x09, 0x10, + 0x0B, 0x10, + + 0x0D, 0x08, + 0x0D, 0x04, + 0x0D, 0x02, + 0x0D, 0x10, + + 0x0F, 0x10, +}; + +I2cLCD::I2cLCD(PinName sda, PinName scl, PinName rp) : _rs( rp ) , _i2c( sda , scl ){ + + contrast = CNTR_DEF; + icon = 0; + + wait(0.015); + // reset LOW->HIGH + _rs = 0; + wait(0.01); + _rs = 1; + wait(0.05); + + writeCommand(FUNC_SET1); + writeCommand(FUNC_SET2); + writeCommand(INT_OSC); + + writeCommand(0x70 | (contrast & 0xF)); + writeCommand(0x5C | ((contrast >> 4) & 0x3)); + + writeCommand(0x6C); + wait(0.3); + + writeCommand(0x38); // function set + writeCommand(0x0C); // Display On + + cls(); // Clear Display + +} + + + +void I2cLCD::character(int column, int row, int c) { + int a = address(column, row); + writeCommand(a); + writeData(c); +} + +void I2cLCD::cls() { + writeCommand(0x01); // cls, and set cursor to 0 + wait(0.00164f); // This command takes 1.64 ms + locate(0, 0); +} + +void I2cLCD::locate(int column, int row) { + _column = column; + _row = row; +} + +int I2cLCD::_putc(int value) { + if (value == '\n') { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } else { + character(_column, _row, value); + _column++; + if (_column >= columns()) { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } + } + return value; +} + +int I2cLCD::_getc() { + return -1; +} + +void I2cLCD::writeCommand( int cmd ) +{ + char cmds[2]; + + cmds[0] = RS_CMD; + cmds[1] = cmd; + + _i2c.write(I2CLCD_ADDR, cmds, 2); +} + +void I2cLCD::writeData( int data ) +{ + char cmd[2]; + + cmd[0] = RS_DATA; + cmd[1] = data; + + _i2c.write(I2CLCD_ADDR, cmd, 2); +} + +int I2cLCD::address(int column, int row) { + + return 0x80 + (row * 0x40) + column; +} + +int I2cLCD::columns() { + return 16; +} + +int I2cLCD::rows() { + return 2; +} + +void I2cLCD::seticon(IconType type) +{ + icon |= type; + puticon( icon ); +} + +void I2cLCD::clearicon(IconType type) +{ + icon &= ~type; + puticon( icon ); +} + + +void I2cLCD::puticon(int flg) +{ + static unsigned char icon_buff[16]; + unsigned char i; + + for(i=0;i<sizeof(icon_data)/2;i++) + { + if(flg & (0x1000>>i)) + { + icon_buff[icon_data[i*2]] |= icon_data[i*2+1]; + } + else + { + icon_buff[icon_data[i*2]] &= ~icon_data[i*2+1]; + } + } + + for(i=0;i<16;i++){ + writeCommand(0x39); + writeCommand(0x40+i); + writeData(icon_buff[i]); + } +}
diff -r 0543430a6bd1 -r bbac27fb013c I2cLCD.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2cLCD.h Sun Sep 22 03:03:05 2013 +0000 @@ -0,0 +1,58 @@ + +#ifndef MBED_I2CLCD_H +#define MBED_I2CLCD_H + +#include "mbed.h" + +class I2cLCD : public Stream { +public: + + enum IconType { + Mark = 0x0001, + Battery_1 = 0x0004, + Battery_2 = 0x0002, + Battery_3 = 0x0010, + Battery_4 = 0x0008, + NoSound = 0x0020, + Lock = 0x0040, + ArrowDown = 0x0080, + ArrowUp = 0x0100, + Input = 0x0200, + Alarm = 0x0400, + Tell = 0x0800, + Antenna = 0x1000, + }; + + I2cLCD(PinName sda, PinName scl, PinName rp); +#if DOXYGEN_ONLY + int putc(int c); + int printf(const char* format, ...); +#endif + void locate(int column, int row); + void cls(); + int rows(); + int columns(); + void seticon(IconType type); + void clearicon(IconType type); + void puticon(int flg); + +protected: + virtual int _putc(int value); + virtual int _getc(); + + int address(int column, int row); + void character(int column, int row, int c); + void writeCommand( int cmd ); + void writeData( int data ); + + DigitalOut _rs; + I2C _i2c; + int _column; + int _row; + + char contrast; + int icon; + +}; + +#endif \ No newline at end of file
diff -r 0543430a6bd1 -r bbac27fb013c main.cpp --- a/main.cpp Wed Jun 19 15:58:03 2013 +0000 +++ b/main.cpp Sun Sep 22 03:03:05 2013 +0000 @@ -1,208 +1,122 @@ -/* - * LCD module "AQM0802A-RN-GBW" sample program - * - * AQM0802A-RN-GBW is an I2C text LCD panel (Controller: Sitronix ST7032i) - * I bought this from AKIZUKI DENSHI TSUSHO CO.,LTD. - * http://akizukidenshi.com/catalog/g/gP-06669/ (Online shop page (Japanese)) - * http://akizukidenshi.com/download/ds/sitronix/st7032.pdf (datasheet of the chip) - * - * Original Arduino version was developed by - * Copyright (c) 2013 Masahiro WAKAYAMA at SWITCH SCIENCE - * - * Copyright (c) 2013 Yoshihiro TSUBOI - * - * Released under the MIT License: http://mbed.org/license/mit - * - * revision 1.0 19-June-2013 a. 1st release - * - */ - - #include "mbed.h" +// IMU2 Ver2 +// hx "*" hyouji + +#include "mbed.h" +#include "I2cLCD.h" -I2C i2c(p28, p27); // sda, scl -const int AQCM0802_addr = 0x7C; +I2cLCD lcd(p28,p27,p26); //sda scl reset +Serial IMU(p9,p10);// p9=Tx,p10=Rx -unsigned char mode; -unsigned char contrast = 0; // 0-63 -unsigned char contrastFlag = false; -int CGcounter; -int FADEcounter; - -void lcd_cmd(char x) { - char data[2]; - data[0] = 0x00; // CO = 0,RS = 0 - data[1] = x; - i2c.write(AQCM0802_addr, data, 2); -} +DigitalOut mled0(LED1); +DigitalOut mled1(LED2); +DigitalIn tsw(p11); -void lcd_contdata(char x) { - char data[2]; - data[0] = 0xC0; //0b11000000 CO = 1, RS = 1 - data[1] = x; - i2c.write(AQCM0802_addr, data, 2); -} +#define ON 1 +#define OFF 0 +#define XON 0 +#define XOFF 1 -void lcd_lastdata(char x) { - char data[2]; - data[0] = 0x40; //0b11000000 CO = 0, RS = 1 - data[1] = x; - i2c.write(AQCM0802_addr, data, 2); -} +double rx,px,hx; +double rx_imu,px_imu,hx_imu; -void lcd_printStr(const char *s) { - while(*s) { - if(*(s + 1)) { - lcd_contdata(*s); - } else { - lcd_lastdata(*s); - } - s++; - } -} - -void lcd_printHex(unsigned char num) { - lcd_contdata(num); -} - -void lcd_init() { - wait(0.04); - // LCD initialize - lcd_cmd(0x38); // function set - lcd_cmd(0x39); // function set - lcd_cmd(0x04); // EntryModeSet - lcd_cmd(0x14); // interval osc - lcd_cmd(0x70 | (contrast & 0xF)); // contrast Low - lcd_cmd(0x5C | ((contrast >> 4) & 0x3)); // contast High/icon/power - lcd_cmd(0x6C); // follower control - wait(0.2); - lcd_cmd(0x38); // function set - lcd_cmd(0x0C); // Display On - lcd_cmd(0x01); // Clear Display - wait(0.2); // need additional wait to Clear Display -} - -void lcd_setCursor(unsigned char x,unsigned char y) { - lcd_cmd(0x80 | (y * 0x40 + x)); +void offset_can(){ + int i; + lcd.cls(); + IMU.printf("$TSC,OFC,10*CC\r\n"); + IMU.printf("$TSC,HRST*75\r\n"); + lcd.printf("now System init\n"); + for(i=0;i<5;i++){ + lcd.printf("."); + wait(0.2); + } + lcd.cls(); } -unsigned char cg[13 * 8] = { -/* - 0b00001111,0b00010000,0b00010000,0b00001110,0b00000001,0b00000001,0b00011110,0b00000000, - 0b00010001,0b00010001,0b00010001,0b00010101,0b00010101,0b00010101,0b00001010,0b00000000, - 0b00001110,0b00000100,0b00000100,0b00000100,0b00000100,0b00000100,0b00001110,0b00000000, - 0b00011111,0b00000100,0b00000100,0b00000100,0b00000100,0b00000100,0b00000100,0b00000000, - 0b00001110,0b00010001,0b00010000,0b00010000,0b00010000,0b00010001,0b00001110,0b00000000, - 0b00010001,0b00010001,0b00010001,0b00011111,0b00010001,0b00010001,0b00010001,0b00000000, -*/ - 0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S - 0x11,0x11,0x11,0x15,0x15,0x15,0x0A,0x00, // W - 0x0E,0x40,0x40,0x40,0x40,0x40,0x0E,0x00, // I - 0x1F,0x40,0x40,0x40,0x40,0x40,0x40,0x00, // T - 0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C - 0x11,0x11,0x11,0x1F,0x11,0x11,0x11,0x00, // H -/* - 0b00001111,0b00010000,0b00010000,0b00001110,0b00000001,0b00000001,0b00011110,0b00000000, - 0b00001110,0b00010001,0b00010000,0b00010000,0b00010000,0b00010001,0b00001110,0b00000000, - 0b00001110,0b00000100,0b00000100,0b00000100,0b00000100,0b00000100,0b00001110,0b00000000, - 0b00011111,0b00010000,0b00010000,0b00011110,0b00010000,0b00010000,0b00011111,0b00000000, - 0b00010001,0b00010001,0b00011001,0b00010101,0b00010011,0b00010001,0b00010001,0b00000000, - 0b00001110,0b00010001,0b00010000,0b00010000,0b00010000,0b00010001,0b00001110,0b00000000, - 0b00011111,0b00010000,0b00010000,0b00011110,0b00010000,0b00010000,0b00011111,0b00000000, -*/ - 0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S - 0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C - 0x0E,0x40,0x40,0x40,0x40,0x40,0x0E,0x00, // I - 0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00, // E - 0x11,0x11,0x19,0x15,0x13,0x11,0x11,0x00, // N - 0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C - 0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00 // E -}; +void IMU_get(){ + int i; + unsigned char c1,c2; -void setCG(int src,int dst,int len) { - lcd_cmd(0x38); - lcd_cmd(0x40 + dst); - if (src >= 0) { - for (int i = 0;i < len;i++) lcd_printHex(cg[src + i]); - } else { - for (int i = 0;i < len;i++) lcd_printHex(0); + while(IMU.getc()!='$'){ + } + for(i=1;i<=8;i++){ + c1=IMU.getc(); + } + for(i=1;i<=20;i++){ + c1=IMU.getc(); } + c1=IMU.getc(); + c2=IMU.getc(); + rx_imu=float((c1 << 8) | c2); + c1=IMU.getc(); + c2=IMU.getc(); + px_imu=float((c1 << 8) | c2); + c1=IMU.getc(); + c2=IMU.getc(); + hx_imu=float((c1 << 8) | c2); + + rx=180*rx_imu/32768; + px=180*px_imu/32768; + hx=180*hx_imu/32768; + + // for hx + if(hx >= 0 && hx <=90){ + hx=hx+90; + } + else if(hx >90 && hx <180){ + hx=180; + } + else if(hx >= 180 && hx <270){ + hx=0; + } + else if(hx >= 270 && hx <=360){ + hx=hx-270; + } + } -void setContrast(unsigned char c) { - lcd_cmd(0x39); - lcd_cmd(0x70 | (c & 0x0f)); // contrast Low - lcd_cmd(0x5C | ((c >> 4) & 0x03)); // contast High/icon/power - lcd_cmd(0x38); -} int main() { - lcd_init(); - while(1) { - switch(mode) { - case 0: // init - lcd_setCursor(0, 0); - for (int i = 0;i < 6;i++) lcd_printHex(i); - lcd_setCursor(1, 1); - lcd_printStr(" "); - setCG(-1,0,6 * 8); - contrast = 35; - setContrast(contrast); - CGcounter = 0; - mode++; - break; - case 1: // SWITCH - if(CGcounter <= (6 * 8)) { - setCG((CGcounter / 8) * 8,((CGcounter / 8) * 8) + 7 - (CGcounter % 8),CGcounter % 8); - CGcounter++; - } else { - lcd_setCursor(0, 0); - lcd_printStr("SWITCH"); - setCG(-1,0,3 * 8); - lcd_setCursor(1, 1); - for (int i = 0;i < 3;i++) lcd_printHex(i); - CGcounter = 0; - mode++; - } - break; - case 2: // SCI - if(CGcounter <= (3 * 8)) { - setCG(((CGcounter / 8) + 6) * 8,((CGcounter / 8) * 8) + 7 - (CGcounter % 8),CGcounter % 8); - CGcounter++; - } else { - lcd_setCursor(1, 1); - lcd_printStr("SCI"); - setCG(-1,0,4 * 8); - lcd_setCursor(4, 1); - for (int i = 0;i < 4;i++) lcd_printHex(i); - CGcounter = 0; - mode++; - } - break; - case 3: // ENCE - if(CGcounter <= (4 * 8)) { - setCG(((CGcounter / 8) + 9) * 8,((CGcounter / 8) * 8) + 7 - (CGcounter % 8),CGcounter % 8); - CGcounter++; - } else { - lcd_setCursor(4, 1); - lcd_printStr("ENCE"); - FADEcounter = 0; - mode++; - } - break; - case 4: - if (contrastFlag == false) { - if (++contrast >= 54) contrastFlag = true; - } else { - if (--contrast <= 17) { - contrastFlag = false; - if(++FADEcounter >= 2) { - mode = 0; - } - } - } - setContrast(contrast); - break; + + int hx_lc=7,hx_lc_old=7; + IMU.baud(119200); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("IMU2 Test03\n"); + lcd.printf("Init now..."); + IMU.printf("$TSC,HRST*75\r\n"); + wait(0.1); + IMU.printf("$TSC,RAW,10\r\n"); + wait(0.1); + + lcd.cls(); + wait(0.1); + mled0=OFF; + + while (1) { + if(tsw==XON){ + mled0=ON; + offset_can(); } - wait(0.05); - } -} + mled0=OFF; + + IMU_get(); + + lcd.locate(0,0); + lcd.printf("rx:%3.0f,px:%3.0f",rx,px); + //lcd.locate(0,1); + //lcd.printf("h:%5.1f",180*hx/32768); + hx_lc=hx/11.25; + if(hx_lc >=16){ + hx_lc=15; + } + //lcd.locate(0,1); + //lcd.printf("%2d,%2d",hx_lc,hx_lc_old); + + lcd.locate(hx_lc_old,1); + lcd.printf(" "); + lcd.locate(hx_lc,1); + lcd.printf("*"); + hx_lc_old=hx_lc; + + }//while +}//main \ No newline at end of file