Driver library for ST7565 graphics LCD controller over SPI interface.
Dependents: ST7565SPI_Test OpPanel_Offline OpPanel_Offline_cmake_gcc_arm_NUCLEO_F303RENew
ST7565SPI.cpp
- Committer:
- kayekss
- Date:
- 2015-03-01
- Revision:
- 0:253db5137942
- Child:
- 1:2150513a5b18
File content as of revision 0:253db5137942:
// ==================================================== Mar 02 2015, kayeks == // ST7565SPI.cpp // =========================================================================== // Driver library for ST7565 graphics LCD controller over SPI interface. #include "ST7565SPI.h" /** Constructor of class ST7565SPI. */ ST7565SPI::ST7565SPI(PinName mosiPin, PinName sckPin, PinName csPin, PinName rsPin, PinName rstPin, int frequency) : rs(rsPin), rst(rstPin), spi(mosiPin, NC, sckPin), cs(csPin) { // Initialize SPI spi.format(8, 0); spi.frequency(frequency); // Initialize pins rs = 0; rst = 1; cs = 1; reset(); } /** Destructor of class ST7565SPI. */ ST7565SPI::~ST7565SPI() { } /** Hits hardware reset pin of the LCD module. */ void ST7565SPI::reset() { wait_ms(10); rst = 0; wait_ms(10); rst = 1; } /** Clear entire display by writing zero. */ void ST7565SPI::clear() { for (uint8_t j = 7; j <= 7; j--) { setPage(j); setColumn(0); for (uint8_t i = 0; i < 132; i++) { data(0x00); } } } /** Initialize controller. */ void ST7565SPI::init(uint8_t v0, uint8_t contrast, bias_t bias) { command(INTERNAL_RESET); wait_ms(5); command(DISPLAY_ON); command(PCTRL_BOOSTER_ON | PCTRL_REGULATOR_ON | PCTRL_VFOLLOWER_ON); command(V0_INTERNAL_R_0 + (v0 & 0x07)); command(ELECTRONIC_VOL_MODE); if (contrast == 0) { contrast = 1; } command(ELECTRONIC_VOL_1 - 1 + (contrast & 0x3f)); switch (bias) { case Bias1_7: command(BIAS_1_7); break; case Bias1_9: command(BIAS_1_9); } command(COMMON_ASCENDING); command(SEGMENT_ASCENDING); command(ENTIRE_DISPLAY_OFF); command(INVERT_DISPLAY_OFF); command(COMMON_OFFSET); clear(); } void ST7565SPI::setPage(uint8_t page) { if (page < 16) { command(0xb0 | page); } } void ST7565SPI::setColumn(uint8_t column) { command(0x10 | (column >> 4)); command(column & 0x0f); } void ST7565SPI::command(uint8_t c) { rs = 0; cs = 0; spi.write(c); cs = 1; } void ST7565SPI::data(uint8_t d) { rs = 1; cs = 0; spi.write(d); cs = 1; }