PCD8544 Driver for an LCD with an PCD8544 controller (e.g. Nokia 3310, 3390)
pcd8544_drv.hpp@1:9948e71af151, 2011-01-02 (annotated)
- Committer:
- carlosftm
- Date:
- Sun Jan 02 11:56:06 2011 +0000
- Revision:
- 1:9948e71af151
- Parent:
- 0:358e68b0535a
Library with Text support only (14x6 characters)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
carlosftm | 0:358e68b0535a | 1 | /** |
carlosftm | 0:358e68b0535a | 2 | * @file pcd8544_drv.hpp |
carlosftm | 0:358e68b0535a | 3 | * PCD8544 Driver for an LCD with an PCD8544 controller. |
carlosftm | 0:358e68b0535a | 4 | * Note: Text mode supported only. |
carlosftm | 0:358e68b0535a | 5 | * |
carlosftm | 0:358e68b0535a | 6 | * Created on: 12/31/2010 at 19:48 |
carlosftm | 0:358e68b0535a | 7 | * @author: CarlosFTM |
carlosftm | 0:358e68b0535a | 8 | */ |
carlosftm | 1:9948e71af151 | 9 | #ifndef __PCD8544_DRV_HPP__ |
carlosftm | 1:9948e71af151 | 10 | #define __PCD8544_DRV_HPP__ |
carlosftm | 0:358e68b0535a | 11 | |
carlosftm | 0:358e68b0535a | 12 | #include "mbed.h" |
carlosftm | 0:358e68b0535a | 13 | #include "ascii_table.hpp" |
carlosftm | 0:358e68b0535a | 14 | |
carlosftm | 0:358e68b0535a | 15 | /* Number of pixels on the LCD */ |
carlosftm | 0:358e68b0535a | 16 | #define MAX_PIX_X (84) |
carlosftm | 0:358e68b0535a | 17 | #define MAX_PIX_Y (48) |
carlosftm | 0:358e68b0535a | 18 | |
carlosftm | 0:358e68b0535a | 19 | /* Size of a caracter displayed on the LCD */ |
carlosftm | 0:358e68b0535a | 20 | #define CHAR_PIX_X (6) |
carlosftm | 0:358e68b0535a | 21 | #define CHAR_PIX_Y (8) |
carlosftm | 0:358e68b0535a | 22 | |
carlosftm | 0:358e68b0535a | 23 | /* Maximum number of character displayed on the LCD*/ |
carlosftm | 0:358e68b0535a | 24 | #define MAX_CHAR_X (MAX_PIX_X / CHAR_PIX_X) |
carlosftm | 0:358e68b0535a | 25 | #define MAX_CHAR_Y (MAX_PIX_Y / CHAR_PIX_Y) |
carlosftm | 0:358e68b0535a | 26 | |
carlosftm | 0:358e68b0535a | 27 | /* Timming constants*/ |
carlosftm | 0:358e68b0535a | 28 | #define TICK (1) // Clock pulse width in useg |
carlosftm | 0:358e68b0535a | 29 | #define RESET_TICKS (8) // number of ticks for reset |
carlosftm | 0:358e68b0535a | 30 | |
carlosftm | 0:358e68b0535a | 31 | /* Digital output assignament*/ |
carlosftm | 0:358e68b0535a | 32 | #define pin_sclk (p21) |
carlosftm | 0:358e68b0535a | 33 | #define pin_mosi (p22) |
carlosftm | 0:358e68b0535a | 34 | #define pin_dc (p23) |
carlosftm | 0:358e68b0535a | 35 | #define pin_sce (p24) |
carlosftm | 0:358e68b0535a | 36 | #define pin_reset (p25) |
carlosftm | 0:358e68b0535a | 37 | |
carlosftm | 0:358e68b0535a | 38 | /* Digital output logicla level*/ |
carlosftm | 0:358e68b0535a | 39 | #define HIGH (1) |
carlosftm | 0:358e68b0535a | 40 | #define LOW (0) |
carlosftm | 0:358e68b0535a | 41 | |
carlosftm | 0:358e68b0535a | 42 | /* Display control command */ |
carlosftm | 0:358e68b0535a | 43 | #define DISPLAY_BLANK (0x08) |
carlosftm | 0:358e68b0535a | 44 | #define NORMAL_MODE (0x0C) |
carlosftm | 0:358e68b0535a | 45 | #define ALL_SEG_ON (0x09) |
carlosftm | 0:358e68b0535a | 46 | #define INVERSE_MODE (0x0D) |
carlosftm | 0:358e68b0535a | 47 | |
carlosftm | 0:358e68b0535a | 48 | #define SET_ADDRES_X (0x80) |
carlosftm | 0:358e68b0535a | 49 | #define SET_ADDRES_Y (0x40) |
carlosftm | 0:358e68b0535a | 50 | |
carlosftm | 0:358e68b0535a | 51 | |
carlosftm | 0:358e68b0535a | 52 | /** Creates an interface to the PCD8544 LCD controller |
carlosftm | 0:358e68b0535a | 53 | * |
carlosftm | 0:358e68b0535a | 54 | */ |
carlosftm | 0:358e68b0535a | 55 | class pcd8544 |
carlosftm | 0:358e68b0535a | 56 | { |
carlosftm | 0:358e68b0535a | 57 | private: |
carlosftm | 0:358e68b0535a | 58 | DigitalOut _sclk; |
carlosftm | 0:358e68b0535a | 59 | DigitalOut _mosi; |
carlosftm | 0:358e68b0535a | 60 | DigitalOut _dc; |
carlosftm | 0:358e68b0535a | 61 | DigitalOut _sce; |
carlosftm | 0:358e68b0535a | 62 | DigitalOut _reset; |
carlosftm | 0:358e68b0535a | 63 | /** Sends a raw byte to the LCD controller |
carlosftm | 0:358e68b0535a | 64 | * |
carlosftm | 0:358e68b0535a | 65 | * @param byte to send, boolean to indicate if it is a coomand (Command = TRUE / Data = FALSE). |
carlosftm | 0:358e68b0535a | 66 | */ |
carlosftm | 0:358e68b0535a | 67 | void sendByte(char byte, bool command); |
carlosftm | 0:358e68b0535a | 68 | |
carlosftm | 0:358e68b0535a | 69 | /** Generates a clock tick |
carlosftm | 0:358e68b0535a | 70 | * |
carlosftm | 0:358e68b0535a | 71 | * @param pulse width in useg |
carlosftm | 0:358e68b0535a | 72 | */ |
carlosftm | 0:358e68b0535a | 73 | inline void clockTick(unsigned short useg); |
carlosftm | 0:358e68b0535a | 74 | |
carlosftm | 0:358e68b0535a | 75 | public: |
carlosftm | 0:358e68b0535a | 76 | |
carlosftm | 0:358e68b0535a | 77 | /** Creates an interface to the LCD |
carlosftm | 0:358e68b0535a | 78 | * |
carlosftm | 0:358e68b0535a | 79 | * @param PinName for SCLK |
carlosftm | 0:358e68b0535a | 80 | * @param PinName for MOSI |
carlosftm | 0:358e68b0535a | 81 | * @param PinName for DC |
carlosftm | 0:358e68b0535a | 82 | * @param PinName for SCE |
carlosftm | 0:358e68b0535a | 83 | * @param PinName for RESET |
carlosftm | 0:358e68b0535a | 84 | */ |
carlosftm | 0:358e68b0535a | 85 | pcd8544(PinName pin_sclk, PinName pin_mosi, PinName pin_dc, PinName pin_sce, PinName pin_reset); |
carlosftm | 0:358e68b0535a | 86 | |
carlosftm | 0:358e68b0535a | 87 | /** Writes data into the LCD controller |
carlosftm | 0:358e68b0535a | 88 | * |
carlosftm | 0:358e68b0535a | 89 | * @param data to be transmited in byte |
carlosftm | 0:358e68b0535a | 90 | */ |
carlosftm | 0:358e68b0535a | 91 | void writeData(char data); |
carlosftm | 0:358e68b0535a | 92 | |
carlosftm | 0:358e68b0535a | 93 | /** Writes a command into the LCD controller |
carlosftm | 0:358e68b0535a | 94 | * |
carlosftm | 0:358e68b0535a | 95 | * @param command in byte |
carlosftm | 0:358e68b0535a | 96 | */ |
carlosftm | 0:358e68b0535a | 97 | void writeCmd(char cmd); |
carlosftm | 0:358e68b0535a | 98 | |
carlosftm | 0:358e68b0535a | 99 | /** Writes a character into the LCD controller |
carlosftm | 0:358e68b0535a | 100 | * |
carlosftm | 0:358e68b0535a | 101 | * @param Character to be written in byte |
carlosftm | 0:358e68b0535a | 102 | */ |
carlosftm | 0:358e68b0535a | 103 | void writeChar(char character); |
carlosftm | 0:358e68b0535a | 104 | |
carlosftm | 0:358e68b0535a | 105 | /** Writes a string into LCD |
carlosftm | 0:358e68b0535a | 106 | * |
carlosftm | 0:358e68b0535a | 107 | * @param pointer to a character string |
carlosftm | 0:358e68b0535a | 108 | */ |
carlosftm | 0:358e68b0535a | 109 | void writeString(char* character); |
carlosftm | 0:358e68b0535a | 110 | |
carlosftm | 0:358e68b0535a | 111 | /** Reset the LCD |
carlosftm | 0:358e68b0535a | 112 | * |
carlosftm | 0:358e68b0535a | 113 | * @param none |
carlosftm | 0:358e68b0535a | 114 | */ |
carlosftm | 0:358e68b0535a | 115 | void resetLCD(void); |
carlosftm | 0:358e68b0535a | 116 | |
carlosftm | 0:358e68b0535a | 117 | /** Initialize the LCD |
carlosftm | 0:358e68b0535a | 118 | * |
carlosftm | 0:358e68b0535a | 119 | * @param none |
carlosftm | 0:358e68b0535a | 120 | */ |
carlosftm | 0:358e68b0535a | 121 | void initLCD(void); |
carlosftm | 0:358e68b0535a | 122 | |
carlosftm | 0:358e68b0535a | 123 | /** Clear the LCD screen |
carlosftm | 0:358e68b0535a | 124 | * |
carlosftm | 0:358e68b0535a | 125 | * @param none |
carlosftm | 0:358e68b0535a | 126 | */ |
carlosftm | 0:358e68b0535a | 127 | void clearLCD(void); |
carlosftm | 0:358e68b0535a | 128 | |
carlosftm | 0:358e68b0535a | 129 | /** Set the cursor to a specific position |
carlosftm | 0:358e68b0535a | 130 | * |
carlosftm | 0:358e68b0535a | 131 | * @param X and Y position in characters |
carlosftm | 0:358e68b0535a | 132 | */ |
carlosftm | 0:358e68b0535a | 133 | void setCursorXY(char x, char y); |
carlosftm | 1:9948e71af151 | 134 | }; |
carlosftm | 1:9948e71af151 | 135 | #endif |