Barış Bilgin Şenol
/
LCD_Test
12864 GLCD
Revision 0:c46d8f8adbd7, committed 2019-05-29
- Comitter:
- Bilgin
- Date:
- Wed May 29 18:36:43 2019 +0000
- Commit message:
- Microp
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GLCD.lib Wed May 29 18:36:43 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/dupuyb/code/GLCD/#e3bff63312e5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 29 18:36:43 2019 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "myLCD.h" +#include "glcd.h" + +DigitalOut myled(LED1); +PinName DI(PTC7); +PinName RW(PTC0); +PinName E(PTC3); +PinName CS1(PTC10); +PinName CS2(PTC11); +DigitalOut RESET(PTC5); +BusInOut lcdbus(PTA2, PTA1, PTD4, PTA12, PTA4, PTA5, PTC8, PTC9); + +int main() { + myled = 1; + wait(1); + GLCD myLCD(DI, RW, E, CS1, CS2, &lcdbus); + wait(1); + myLCD.reset_pins(0); + wait(1); + myLCD.init(1); + wait(1); + myLCD.fillScreen(1); + wait(3); + myLCD.fillScreen(0); + wait(1); + while(1){} + /**myLCD myLCD(DI, RW, E, CS1, CS2, &lcdbus); + RESET = 1; + myLCD.lcd_on(); + myLCD.draw_point(2, 2, 0); + myLCD.draw_point(4, 4, 1); + while(1){ + } + unsigned short u, v; + myled = 1; + RESET = 0; + wait_us(2); + RESET = 1; + myLCD.lcd_on(); + myLCD.clear(); + myLCD.set_xy(0, 0); + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + for(u=0; u<64; u+=6) + for (v=0; v<128; v+=2) + myLCD.draw_point(v, u, 1); + wait_ms(1000); + myLCD.clear(); + wait_ms(1000); + }*/ +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 29 18:36:43 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myLCD/myLCD.cpp Wed May 29 18:36:43 2019 +0000 @@ -0,0 +1,133 @@ +#include "myLCD.h" +/** +myLCD::myLCD(PinName _DI, PinName _RW, PinName _EN, PinName _CS1, PinName _CS2, BusInOut *BUSLCD){ + DI = new DigitalOut(_DI); + RW = new DigitalOut(_RW); + EN = new DigitalOut(_EN); + CS1 = new DigitalOut(_CS1); + CS2 = new DigitalOut(_CS2); + LCD_PORT = BUS_LCD; + }*/ +myLCD::myLCD(PinName _DI, PinName _RW, PinName _EN, PinName _CS1, PinName _CS2, BusInOut *BUSLCD):DI(_DI),RW(_RW),EN(_EN),CS1(_CS1),CS2(_CS2){ + LCD_PORT = BUSLCD; +} + +void myLCD::pulse_en(){ + EN = 1; + wait_us(8); + EN = 0; + wait_us(8); +} + +void myLCD::lcd_on(){ + DI = 0; + RW = 0; + EN = 0; + CS1 = 0; + CS2 = 0; + LCD_PORT->output(); + wait_us(2); + LCD_PORT->write(0x3F); + wait_us(2); + pulse_en(); +} + +void myLCD::write_byte(unsigned short byte){ + DI = 1; //high -> data + RW = 0; //low -> write + LCD_PORT->write(byte); + wait_us(2); + pulse_en(); +} + +//returns the value into @param &byte +short myLCD::read_byte(unsigned short col, unsigned short page){ + unsigned short temp; + set_xy(col, page); // this function reads data from current location + LCD_PORT->input(); //set as input + DI = 1; //high -> data + RW = 1; //high -> read + CS1 = (col>63); + CS2 = !CS1; + wait_us(1); + EN = 1; //latches data into output register + wait_us(1); + + EN = 0; //dummy read + wait_us(5); //waits while lcd fetches data + EN = 1; //latch data from output register into data register + wait_us(1); + + temp = LCD_PORT->read(); //data is saved onto byte from the caller + EN = 0; //remove data from the bus + wait_us(1); + LCD_PORT->output(); //set bus as output again + wait_us(2); + return temp; +} + +//@param col should be 0<=col<128 +void myLCD::set_col(unsigned short col){ + unsigned short col_data; + DI = 0; //low -> instruction + RW = 0; //low -> write + + //0-63 + if(col < 64){ + CS1 = 0; //select chip1 + CS2 = 1; //deselect chip2 + col_data = col; + } + else //64-127 + { + CS1 = 1; //deselect chip1 + CS2 = 0; //select chip2 + col_data = col - 64; + } + //command formatting 01CCCCC -> C: column + col_data = (col_data | 0x40) & 0x7F; + LCD_PORT->write(col_data); + wait_us(2); + pulse_en(); +} + +void myLCD::set_row(unsigned short row){ + unsigned short row_data; + DI = 0; //low -> instruction + RW = 0; //low -> write + //command formatting 10111PPP -> P: page + row_data = (row | 0xB8) & 0xBF; //or with 10111000, and with 10111111. last 3 bits is the page + LCD_PORT->write(row_data); + wait_us(2); + pulse_en(); +} + +void myLCD::set_xy(unsigned short col, unsigned short page){ + set_col(col); + set_row(page); +} + +void myLCD::clear(){ + for(short n = 0; n < 8; n++){ + set_xy(0,n); + set_xy(64,n); //at this point, cs2 is selected + CS1 = 1; //select cs1 as well + for(short i = 0; i < 64; i++) + write_byte(0); + } +} + +//@param color = true, draws white. clears otherwise +void myLCD::draw_point(unsigned short x, unsigned short y, bool color){ + short data; + short byte = read_byte(x, (y/8)); //byte has the point's 8bit data + + if(color){ //paint the point + data = ~(1 << (y % 8)) & byte; + } + else{ //clear the point + data = (1 << (y % 8)) | byte; + } + set_xy(x, y/8); + write_byte(data); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myLCD/myLCD.h Wed May 29 18:36:43 2019 +0000 @@ -0,0 +1,27 @@ +#ifndef MYLCD_H +#define MYLCD_H + +#include "mbed.h" + +class myLCD { + public: + myLCD(PinName _DI, PinName _RW, PinName _EN, PinName _CS1, PinName _CS2, BusInOut *BUSLCD); + void pulse_en(); + void lcd_on(); + void write_byte(unsigned short byte); + short read_byte(unsigned short col, unsigned short page); + void set_col(unsigned short col); //0-127 sets col + void set_row(unsigned short row); //0-7 sets page + void set_xy(unsigned short col, unsigned short page); + void clear(); + void draw_point(unsigned short x, unsigned short y, bool color); //true prints white, xy coordinates in 0-127, 0-63 + + private: + BusInOut* LCD_PORT; + DigitalOut DI; + DigitalOut RW; + DigitalOut EN; + DigitalOut CS1; + DigitalOut CS2; +}; +#endif \ No newline at end of file