Projekte

  |   Rolladensteuerung   |   Belichtungstimer   |   Drehzahlmesser   |   AVRFK   |   Dunstabzugsklappe   |   FB-Orgel   |   Termowächter   |   Erinnermich   |   LED-Dimmer   |  

  |   Timer Template Klasse   |   Tastatur Klasse   |   LCD Klasse   |  


LCD Klasse

HMC16223.h

   1:  /********************************************************************
   2:  *     Copyright (C) 2011  Philipp Klostermann
   3:  *
   4:  *    HMC16223.h
   5:  *
   6:  *    This program is free software: you can redistribute it and/or modify
   7:  *    it under the terms of the GNU General Public License as published by
   8:  *    the Free Software Foundation, either version 3 of the License, or
   9:  *    any later version.
  10:  *
  11:  *    This program is distributed in the hope that it will be useful,
  12:  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13:  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14:  *    GNU General Public License for more details.
  15:  *
  16:  *    You should have received a copy of the GNU General Public License
  17:  *    along with this program.  If not, see here
  18:  *
  19:  *	Email the autor: philipp.klostermann@pksl.de
  20:  *	Address: 
  21:  *	 Philipp Klostermann
  22:  *	 Luchert 45
  23:  *	 56593 Horhausen
  24:  *	 Germany
  25:  *********************************************************************/
  26:  
  27:  #ifndef __AVRFK_HMC16223_H_INCLUDED__
  28:  #define __AVRFK_HMC16223_H_INCLUDED__
  29:  
  30:  #ifndef LCD_ONE_PORT
  31:  	#define LCD_ONE_PORT 0
  32:  #endif

  33:  #ifndef LCD_ONE_PORT
  34:  	#define LCD_CTRL_PORT PORTD
  35:  #endif

  36:  #ifndef LCD_ONE_PORT
  37:  	#define LCD_CTRL_PORT_DDR DDRD
  38:  #endif

  39:  #ifndef LCD_ONE_PORT
  40:  	#define LCD_DATA_PORT PORTB
  41:  #endif

  42:  #ifndef LCD_ONE_PORT
  43:  	#define LCD_DATA_PORT_DDR DDRB
  44:  #endif

  45:  #ifndef LCD_ONE_PORT
  46:  	#define LCD_EN 7
  47:  #endif

  48:  #ifndef LCD_ONE_PORT
  49:  	#define LCD_RS 6
  50:  #endif

  51:  
  52:  #include <avrfk/delay.h>
  53:  
  54:  class CHMC16223
  55:  {
  56:  public:
  57:  	CHMC16223()
  58:  	{
  59:  	#if (LCD_ONE_PORT)
  60:  		LCD_DATA_PORT_DDR |= (0x0f | (1 << LCD_EN) | (1 << LCD_RS));
  61:  	#else
  62:  		LCD_DATA_PORT_DDR |= 0x0f;
  63:  		LCD_CTRL_PORT_DDR |= ((1 << LCD_EN) | (1 << LCD_RS));
  64:  	#endif
  65:  		LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0);
  66:  		Delay_ms(250);
  67:  		LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0) | 3;
  68:  		PulseEnable();
  69:  		Delay_ms(5);
  70:  		PulseEnable();
  71:  		Delay_ms(5);
  72:  		PulseEnable();
  73:  		Delay_ms(5);
  74:  		LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0) | 2;
  75:  		PulseEnable();
  76:  		Delay_ms(5);
  77:  		TransmitCommand(0x28); // 4Bit / 2 Zeilen / 5x8
  78:  		Delay_us(50);
  79:  		TransmitCommand(0x0c); // Display ein / Cursor aus / kein Blinken
  80:  		Delay_us(50);
  81:  		TransmitCommand(0x06); // inkrement / kein Scrollen
  82:  		Delay_us(50);
  83:  	}	
  84:  
  85:  	inline void Clear()
  86:  	{
  87:  		TransmitCommand(0x01);
  88:  		Delay_ms(5);
  89:  	}
  90:  
  91:  
  92:  	inline void PulseEnable()
  93:  	{
  94:  		LCD_CTRL_PORT |= (1 << LCD_EN);
  95:  		Delay_1_us();
  96:  		LCD_CTRL_PORT &= ~(1 << LCD_EN);
  97:  	}
  98:  
  99:  	inline void TransmitByte(uint8_t c)
 100:  	{
 101:  		LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0) | (c >> 4);
 102:  		PulseEnable();
 103:  		LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0) | (c & 0xf);
 104:  		PulseEnable();
 105:  	}
 106:  
 107:  	inline void TransmitCommand(uint8_t c)
 108:  	{
 109:  		TransmitByte(c);
 110:  	}
 111:  
 112:  	inline void TransmitData(uint8_t c)
 113:  	{
 114:  		LCD_CTRL_PORT |= (1 << LCD_RS);
 115:  		TransmitByte(c);
 116:  		LCD_CTRL_PORT &= ~(1 << LCD_RS);
 117:  	}
 118:  
 119:  	inline bool TransmitDataDelay(uint8_t c)
 120:  	{
 121:  		TransmitData(c);
 122:  		Delay_ms(5);
 123:  		return true;
 124:  	}
 125:  
 126:  	inline void Home()
 127:  	{
 128:  		TransmitCommand(0x02);
 129:  		Delay_ms(5);
 130:  	}
 131:  
 132:  	inline void Gotoxy(int x, int y)
 133:  	{
 134:  		TransmitCommand(0x80 | (y ? 0x40 : 0) | x);
 135:  		Delay_ms(5);
 136:  	}
 137:  
 138:  
 139:  	inline bool UploadZeichen(uint8_t Zeichen, uint8_t* pBits)
 140:  	{
 141:  		int i;
 142:  		TransmitCommand(0x40 | (Zeichen << 3));
 143:  		Delay_ms(5);
 144:  		for (i = 0; i< 8; ++i)
 145:  		{
 146:  			TransmitData(*(pBits++));
 147:  			Delay_ms(5);
 148:  		}
 149:  		TransmitCommand(0x80);
 150:  		Delay_ms(5);
 151:  		return true;
 152:  	}
 153:  
 154:  	inline void CursorOn()
 155:  	{
 156:  		TransmitCommand(0x0c | 3); // Display ein / Cursor an / Blinken
 157:  		Delay_us(50);
 158:  	}
 159:  
 160:  	inline void CursorOff()
 161:  	{
 162:  		TransmitCommand(0x0c); // Display ein / Cursor aus / kein Blinken
 163:  		Delay_us(50);
 164:  	}
 165:  
 166:  /*
 167:  	inline void Clear()
 168:  	{
 169:  		int i;
 170:  		LCD_gotoxy(0,0);
 171:  		delay5ms();
 172:  		for(i=0; i<16; ++i)
 173:  		{
 174:  			TransmitData(' ');
 175:  			delay5ms();
 176:  		}
 177:  		Gotoxy(0,1);
 178:  		delay5ms();
 179:  		for(i=0; i<16; ++i)
 180:  		{
 181:  			TransmitData(' ');
 182:  			delay5ms();
 183:  		}
 184:  	}
 185:  */
 186:  	bool TransmitStringXY(uint8_t x, uint8_t y, const uint8_t* s);
 187:  	bool TransmitInteger(int8_t n);
 188:  	bool TransmitInteger(int16_t n);
 189:  	bool TransmitInteger(int32_t n);
 190:  };
 191:  
 192:  #endif // #ifndef __AVRFK_HMC16223_H_INCLUDED__