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