Esercitazione4_1
Dependencies: mbed
Revision 0:723d0d8c0d09, committed 2016-11-28
- Comitter:
- dfalanga
- Date:
- Mon Nov 28 10:35:04 2016 +0000
- Commit message:
- Esercitazione4_1
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD.cpp Mon Nov 28 10:35:04 2016 +0000 @@ -0,0 +1,47 @@ +/* Program Example 1: Declaration of objects and functions in LCD.cpp file 2. */ +#include "LCD.h" +DigitalOut RS(D12); +DigitalOut E(D11); +BusOut data(D5, D4, D3, D2); + void toggle_enable(void) + { + E=1; + wait(0.001); + E=0; + wait(0.001); + } + + void LCD_init(void) { + wait(0.02); // pause for 20 ms + RS=0; // set low to write control data + E=0; // set low 20. //function mode 21. + data=0x2; // 4 bit mode (data packet 1, DB4-DB7) 22. + toggle_enable(); + data=0x8; // 2-line, 7 dot char (data packet 2, DB0-DB3) 24. + toggle_enable(); //display mode 26. + data=0x0; // 4 bit mode (data packet 1, DB4-DB7) + toggle_enable(); + data=0xF; // display on, cursor on, blink on + toggle_enable(); //clear display + data=0x0; // + toggle_enable(); + data=0x1; // clear + toggle_enable(); + } //display function + + void display_to_LCD(char value) + { + RS=1; // set high to write character data + data=value>>4; // value shifted right 4 = upper nibble + toggle_enable(); + data=value; // value bitmask with 0x0F = lower nibble + toggle_enable(); + } //locate function + void set_location(char location) + { + RS=0; + data=(location|0x80)>>4; // upper nibble + toggle_enable(); + data=location&0x0F; // lower nibble + toggle_enable(); + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD.h Mon Nov 28 10:35:04 2016 +0000 @@ -0,0 +1,9 @@ +/* Program Example 1: LCD.h header file 2. */ + #ifndef LCD_H + #define LCD_H + #include "mbed.h" + void toggle_enable(void); //function to toggle/pulse the enable bit + void LCD_init(void); //function to initialize the LCD + void display_to_LCD(char value); //function to display characters + void set_location(char location); + #endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 28 10:35:04 2016 +0000 @@ -0,0 +1,19 @@ +/* Program Example 1 Utilizing LCD functions in the main.cpp file 2. */ +#include "LCD.h" +int main() +{ + char loc=0x40; + LCD_init(); // call the initialize function + display_to_LCD(0x46); // + display_to_LCD(0x6F); // + display_to_LCD(0x72); // + display_to_LCD(0x7A); // + display_to_LCD(0x61); // + set_location(loc); + display_to_LCD(0x4E); // + display_to_LCD(0x61); // + display_to_LCD(0x70); // + display_to_LCD(0x6F); // + display_to_LCD(0x6c); // + display_to_LCD(0x69); // + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 28 10:35:04 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3 \ No newline at end of file