Esercitazione4_1

Dependencies:   mbed

Committer:
dfalanga
Date:
Mon Nov 28 10:35:04 2016 +0000
Revision:
0:723d0d8c0d09
Esercitazione4_1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dfalanga 0:723d0d8c0d09 1 /* Program Example 1: Declaration of objects and functions in LCD.cpp file 2. */
dfalanga 0:723d0d8c0d09 2 #include "LCD.h"
dfalanga 0:723d0d8c0d09 3 DigitalOut RS(D12);
dfalanga 0:723d0d8c0d09 4 DigitalOut E(D11);
dfalanga 0:723d0d8c0d09 5 BusOut data(D5, D4, D3, D2);
dfalanga 0:723d0d8c0d09 6 void toggle_enable(void)
dfalanga 0:723d0d8c0d09 7 {
dfalanga 0:723d0d8c0d09 8 E=1;
dfalanga 0:723d0d8c0d09 9 wait(0.001);
dfalanga 0:723d0d8c0d09 10 E=0;
dfalanga 0:723d0d8c0d09 11 wait(0.001);
dfalanga 0:723d0d8c0d09 12 }
dfalanga 0:723d0d8c0d09 13
dfalanga 0:723d0d8c0d09 14 void LCD_init(void) {
dfalanga 0:723d0d8c0d09 15 wait(0.02); // pause for 20 ms
dfalanga 0:723d0d8c0d09 16 RS=0; // set low to write control data
dfalanga 0:723d0d8c0d09 17 E=0; // set low 20. //function mode 21.
dfalanga 0:723d0d8c0d09 18 data=0x2; // 4 bit mode (data packet 1, DB4-DB7) 22.
dfalanga 0:723d0d8c0d09 19 toggle_enable();
dfalanga 0:723d0d8c0d09 20 data=0x8; // 2-line, 7 dot char (data packet 2, DB0-DB3) 24.
dfalanga 0:723d0d8c0d09 21 toggle_enable(); //display mode 26.
dfalanga 0:723d0d8c0d09 22 data=0x0; // 4 bit mode (data packet 1, DB4-DB7)
dfalanga 0:723d0d8c0d09 23 toggle_enable();
dfalanga 0:723d0d8c0d09 24 data=0xF; // display on, cursor on, blink on
dfalanga 0:723d0d8c0d09 25 toggle_enable(); //clear display
dfalanga 0:723d0d8c0d09 26 data=0x0; //
dfalanga 0:723d0d8c0d09 27 toggle_enable();
dfalanga 0:723d0d8c0d09 28 data=0x1; // clear
dfalanga 0:723d0d8c0d09 29 toggle_enable();
dfalanga 0:723d0d8c0d09 30 } //display function
dfalanga 0:723d0d8c0d09 31
dfalanga 0:723d0d8c0d09 32 void display_to_LCD(char value)
dfalanga 0:723d0d8c0d09 33 {
dfalanga 0:723d0d8c0d09 34 RS=1; // set high to write character data
dfalanga 0:723d0d8c0d09 35 data=value>>4; // value shifted right 4 = upper nibble
dfalanga 0:723d0d8c0d09 36 toggle_enable();
dfalanga 0:723d0d8c0d09 37 data=value; // value bitmask with 0x0F = lower nibble
dfalanga 0:723d0d8c0d09 38 toggle_enable();
dfalanga 0:723d0d8c0d09 39 } //locate function
dfalanga 0:723d0d8c0d09 40 void set_location(char location)
dfalanga 0:723d0d8c0d09 41 {
dfalanga 0:723d0d8c0d09 42 RS=0;
dfalanga 0:723d0d8c0d09 43 data=(location|0x80)>>4; // upper nibble
dfalanga 0:723d0d8c0d09 44 toggle_enable();
dfalanga 0:723d0d8c0d09 45 data=location&0x0F; // lower nibble
dfalanga 0:723d0d8c0d09 46 toggle_enable();
dfalanga 0:723d0d8c0d09 47 }