Operácie

MEMS cvičenie 3

Z SensorWiki

Verzia z 18:48, 5. marec 2016, ktorú vytvoril Balogh (diskusia | príspevky)

Pripojenie LED a LCD displeja a lokálne zobrazenie meranej veličiny


Programovateľný LCD displej

LCD Modul

ParallaxLCDAppMod.jpg

Vlastnosti:

  • 2x8 LCD Displej bez podsvetlenia
  • 4 Tlačítka
  • Trimer na zmenu kontrastu

Technické parametre:

  • Napájanie: 5 V @ 15 mA
  • Pripojenie: 4-Bit parallel interface (Hitachi HD44780 compatible)
  • Rozmery: 60 x 50 x 20 mm
  • Pracovná teplota: 0 až +70 °C


Acrob LCD Schematic.png
Acrob LCD Schema2.png


Úlohy

Najprv sa snažte pochopiť, ako je vytvorený vzorový program, ako sa konfiguruje pripojenie LCD k portom, skontrolujte konfiguráciu. Potom s pomocou manuálu k displeju zobrazte na displeji nejaký text a zrealizujte nasledovné funkcie:

  1. posun kurzora doprava / dolava
  2. posun obsahu displeja doprava / dolava
  3. napíšte funkciu void lcdGotoXY(riadok, stlpec)
  4. clear displeja (a obnovenie povodneho obsahu displeja)
  5. zadefinujte si vlastné znaky a zobrazte ich spolu s iným textom. Povinne aspoň jeden znak s diakritikou a znak stupeň, zobrazte teplotu.

Literatúra

Arduino

Nasledovný príklad je pre Arduino.

/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 8x2 LCD display.  
 
   The circuit:
 * LCD RS pin to digital pin 3
 * LCD R/W pin to digital pin 2
 * LCD Enable pin to digital pin 1
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7                    
 */

#include <LiquidCrystal.h>           // include the library 

// initialize the library with the numbers of the interface pins
//  LiquidCrystal(RS, RW, EN, D4, D5, D6, D7) 
LiquidCrystal lcd( 3,  2,  1,  4,  5,  6,  7);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(8, 2);
  // Print a message to the LCD.
  lcd.print("Ahoj!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
  // print the status of buttons:
  lcd.setCursor(6, 0);
  lcd.print(ReadButtons(),HEX);
  
}


/* ------------------------------------------------------- */
/*  Read and debounce the LCD AppMod buttons               */
/*                                                         */
/*  Returns 0 if nothing  is pressed                       */
/*  Returns 1 if button A is pressed                       */
/*  Returns 2 if button B is pressed                       */
/*  Returns 4 if button C is pressed                       */
/*  Returns 8 if button D is pressed                       */
/*  Returns combination if more is pressed (e.g. 6 for B+C)*/
/*                                                         */
/* ------------------------------------------------------- */

unsigned char ReadButtons()
{
  DDRD  = 0b00001110;                // make LCD bus inputs
  unsigned char state = 0xFF;           // assume nothing pressed
  
  for(int scan = 1; scan<=10; scan++)
  {
   state = state & ((PIND&0xF0)>>4); // make sure button held
   delay(5);                     // debounce 10 x 5 ms
  }

  DDRD  = 0b11111110;				 // return bus to outputs
  
  return(state);
}

Misc:

Prečo je takto napísaná a ako vlastne funguje lepšie zistíte, keď si preštudujete schému zapojenia:

LCD App Mod Schematic.png


Návrat na zoznam cvičení...