![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Predfined parameters
Fork of Programmable_IR_Beacon by
display.cpp
- Committer:
- jah128
- Date:
- 2014-03-19
- Revision:
- 0:d88fd55a27a6
File content as of revision 0:d88fd55a27a6:
/* University of York Robotics Laboratory MBED Library * Display Driver for Midas I2C 2x16 Display * Part number MCCOG21605-D6W-BNMLWI * Rapid Electronics Cat Number 57-2340 [or 57-2334] * Farnell Cat Number 2063206 [or 2063205] * * File: display.cpp * * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York * * October 2013 * */ #include "mbed.h" #include "display.h" Display::Display(PinName sda, PinName scl, PinName reset) : Stream("display"), _i2c(sda,scl), _reset(reset) { } Display::Display() : Stream("display"), _i2c(p9,p10), _reset(p12) { } int Display::i2c_message(char byte){ char bytes [2]; bytes[0]=0x80; bytes[1]=byte; int ret=_i2c.write(LCD_ADDRESS,bytes,2); wait(0.01); return ret; } int Display::disp_putc(int c){ char message [2]; message[0]=0x40; message[1]=c; _i2c.write(LCD_ADDRESS,message,2); wait(0.01); return c; } void Display::init_display(){ //Set initial states: display on, cursor off display_on = 1; cursor_on = 0; blink_on = 0; _reset=1; wait(0.02); //Set reset low _reset=0; wait(0.001); _reset=1; wait(0.03); i2c_message(0x38); i2c_message(0x39); i2c_message(0x14); i2c_message(0x79); i2c_message(0x50); i2c_message(0x6c); _set_display(); clear_display(); } void Display::write_string(char * message, char length){ char to_send [length+1]; to_send[0]=0x40; for(int i=0;i<length;i++){ to_send[i+1] = message[i]; } _i2c.write(LCD_ADDRESS,to_send,length+1); } void Display::set_position(char row, char column){ if(row < 2 && column < 16){ char pos = 128 +((row * 64)+column); i2c_message(pos); } } void Display::set_cursor(char enable){ cursor_on=enable; _set_display(); } void Display::set_blink(char enable){ blink_on=enable; _set_display(); } void Display::set_display(char enable){ display_on=enable; _set_display(); } void Display::clear_display(){ i2c_message(0x01); } void Display::home(){ i2c_message(0x02); } void Display::_set_display(){ char mode = 8; if(display_on>0) mode += 4; if(cursor_on>0) mode += 2; if(blink_on>0) mode ++; i2c_message(mode); } int Display::_putc (int c) { putc(c); return(c); } int Display::_getc (void) { char r = 0; return(r); } /* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */