Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCDBang.h Source File

LCDBang.h

00001 /*  
00002       This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
00003       Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
00004       Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00005       You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
00006 */
00007 #ifndef LCDBANG_H
00008 #define LCDBANG_H
00009 #include "mbed.h" // mbed.h lib
00010 #include "I2CBang.h"
00011 
00012 void lcdbang_writenibble(I2C i2c, char c, bool command = false){
00013     const int addr = 0x40;
00014     char cmd[2];
00015     c <<= 4;
00016     c &= 0xF0;
00017     c |= 0x01;
00018     if(!command) c |= 0x02;
00019 
00020     cmd[0] = 0x0C;
00021     cmd[1] = c;
00022     i2c.write(addr, cmd, 2);
00023     cmd[1] = c | 0x08;
00024     i2c.write(addr, cmd, 2);
00025     cmd[1] = c;
00026     i2c.write(addr, cmd, 2);
00027 //    wait_ms(1);
00028 }
00029 
00030 void lcdbang_write(I2C i2c, char c, bool command = false){
00031     if(command){
00032         lcdbang_writenibble(i2c, c, command);
00033     }else{
00034         lcdbang_writenibble(i2c, c >> 4, command);
00035         lcdbang_writenibble(i2c, c, command);
00036     }
00037 }
00038 
00039 void lcdbang_init(I2C i2c){
00040     const int addr = 0x40;
00041     char cmd[2];
00042     cmd[0] = 0x1C;
00043     cmd[1] = 0x00;
00044     i2c.write(addr, cmd, 2);
00045 
00046     lcdbang_write(i2c, 0x3, true);
00047     wait_ms(50);
00048     lcdbang_write(i2c, 0x3, true);
00049     wait_ms(10);
00050     lcdbang_write(i2c, 0x3, true);
00051     wait_ms(10);
00052     lcdbang_write(i2c, 0x2, true);
00053     wait_ms(1);
00054 
00055     lcdbang_write(i2c, 0x2, true);
00056     lcdbang_write(i2c, 0x8, true);
00057     wait_ms(1);
00058 
00059     lcdbang_write(i2c, 0x0, true);
00060     lcdbang_write(i2c, 0x8, true);
00061     wait_ms(1);
00062 
00063     lcdbang_write(i2c, 0x0, true);
00064     lcdbang_write(i2c, 0x1, true);
00065     wait_ms(1);
00066 
00067     lcdbang_write(i2c, 0x0, true);
00068     lcdbang_write(i2c, 0x6, true);
00069     wait_ms(1);
00070 
00071     lcdbang_write(i2c, 0x0, true);
00072     lcdbang_write(i2c, 0x2, true);
00073     wait_ms(1);
00074 
00075     lcdbang_write(i2c, 0x0, true);
00076     lcdbang_write(i2c, 0xC, true);
00077     wait_ms(1);
00078 }
00079 
00080 void lcdbang_print(I2C i2c, const char* msg){
00081     for(int i=0;msg[i];i++){
00082         lcdbang_write(i2c, msg[i]);
00083     }
00084 }
00085 
00086 void lcdbang_contrast(I2C i2c, int contrast){
00087     // set dac pins as output and set dac
00088     i2cbang_init(i2c);
00089     i2cbang_start(i2c);
00090     i2cbang_write(i2c, 0xC0);
00091     i2cbang_write(i2c, 0x60);
00092     i2cbang_write(i2c, contrast >> 8);
00093     i2cbang_write(i2c, (contrast << 8) & 0xF0 );
00094     i2cbang_stop(i2c);
00095 }
00096 
00097 #endif // LCDBANG_H
00098