This is a low level driver for the ST7565R LCD controller.
It provides basic functions for initializing and writing to the LCD controller. In addition to hardware control and use of the LCD controller internal functions .
Before writing data to the display call st7565r_init() which will set up the physical interface and the LCD. A file named conf_st7565r.h is needed to define which interface to use. For more information see the Interface selection section. In addition one also need to define the pins ST7565R_A0_PIN, ST7565R_CS_PIN and ST7565R_RESET_PIN and the display ST7565R_CLOCK_SPEED.
- Warning
- This driver is not reentrant and can not be used in interrupt\ service routines without extra care.
As a safety feature one also need to set the max and min contrast levels that the st7565r_set_contrast using the defines ST7565R_DISPLAY_CONTRAST_MAX and ST7565R_DISPLAY_CONTRAST_MIN to protect the display from too high voltage, please see the st7565r_set_contrast function for more details.
An example conf_st7565r.h file could look like
#define ST7565R_USART_SPI_INTERFACE
#define ST7565R_USART_SPI &USARTD0
#define ST7565R_CLOCK_SPEED 1000000
#define ST7565R_DISPLAY_CONTRAST_MAX 40
#define ST7565R_DISPLAY_CONTRAST_MIN 30
#define ST7565R_A0_PIN NHD_C12832A1Z_REGISTER_SELECT
#define ST7565R_CS_PIN NHD_C12832A1Z_CSN
#define ST7565R_RESET_PIN NHD_C12832A1Z_RESETN
Dependencies
This driver depends on the following modules:
|
The LCD controller support both serial and parallel mode, that means there is a number of possible ways of interfacing the controller using different AVR peripherals.
The different interfaces can be selected using different defines. This driver supports the serial communication mode using an USART in Master SPI mode by defining ST7565R_USART_SPI_INTERFACE, and a normal SPI in Master Mode by defining ST7565R_SPI_INTERFACE.
- Note
- The current driver only support serial mode.
|
#define | ST7565R_USART_SPI_INTERFACE |
| Select the a USART SPI interface. More...
|
|
#define | ST7565R_SPI_INTERFACE |
| Select the normal SPI peripheral interface. More...
|
|
#define ST7565R_CMD_ADC_NORMAL 0xA0 |
#define ST7565R_CMD_ADC_REVERSE 0xA1 |
#define ST7565R_CMD_BOOSTER_RATIO_2X_3X_4X 0x00 |
#define ST7565R_CMD_BOOSTER_RATIO_5X 0x01 |
#define ST7565R_CMD_BOOSTER_RATIO_6X 0x03 |
#define ST7565R_CMD_BOOSTER_RATIO_SET 0xF8 |
#define ST7565R_CMD_COLUMN_ADDRESS_SET_LSB |
( |
|
column | ) |
(0x00 | (column)) |
#define ST7565R_CMD_COLUMN_ADDRESS_SET_MSB |
( |
|
column | ) |
(0x10 | (column)) |
#define ST7565R_CMD_DISPLAY_ALL_POINTS_OFF 0xA4 |
#define ST7565R_CMD_DISPLAY_ALL_POINTS_ON 0xA5 |
#define ST7565R_CMD_DISPLAY_NORMAL 0xA6 |
#define ST7565R_CMD_DISPLAY_OFF 0xAE |
#define ST7565R_CMD_DISPLAY_ON 0xAF |
#define ST7565R_CMD_DISPLAY_REVERSE 0xA7 |
#define ST7565R_CMD_ELECTRONIC_VOLUME |
( |
|
volume | ) |
(0x3F & (~volume)) |
#define ST7565R_CMD_ELECTRONIC_VOLUME_MODE_SET 0x81 |
#define ST7565R_CMD_END 0xEE |
#define ST7565R_CMD_LCD_BIAS_1_DIV_5_DUTY33 0xA1 |
#define ST7565R_CMD_LCD_BIAS_1_DIV_6_DUTY33 0xA2 |
#define ST7565R_CMD_NOP 0xE3 |
#define ST7565R_CMD_NORMAL_MODE 0xAD |
#define ST7565R_CMD_NORMAL_SCAN_DIRECTION 0xC0 |
#define ST7565R_CMD_PAGE_ADDRESS_SET |
( |
|
page | ) |
(0xB0 | (page)) |
#define ST7565R_CMD_POWER_CTRL_ALL_ON 0x2F |
#define ST7565R_CMD_READ_MODIFY_WRITE 0xE0 |
#define ST7565R_CMD_RESET 0xE2 |
#define ST7565R_CMD_REVERSE_SCAN_DIRECTION 0xC8 |
#define ST7565R_CMD_SLEEP_MODE 0xAC |
#define ST7565R_CMD_START_LINE_SET |
( |
|
line | ) |
(0x40 | (line)) |
#define ST7565R_CMD_STATUS_READ 0x00 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_0 0x20 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_1 0x21 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_2 0x22 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_3 0x23 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_4 0x24 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_5 0x25 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_6 0x26 |
#define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_7 0x27 |
#define ST7565R_SERIAL_INTERFACE |
#define ST7565R_SPI_INTERFACE |
Select the normal SPI peripheral interface.
#define ST7565R_USART_SPI_INTERFACE |
Select the a USART SPI interface.
static void st7565r_display_invert_disable |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_display_invert_enable |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_display_off |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_display_on |
( |
void |
| ) |
|
|
inlinestatic |
static uint8_t st7565r_get_status |
( |
void |
| ) |
|
|
inlinestatic |
Read status from the controller.
- Note
- The controller does not support read in serial mode.
- Return values
-
8 | bit status read from the controller |
static void st7565r_hard_reset |
( |
void |
| ) |
|
|
inlinestatic |
void st7565r_init |
( |
void |
| ) |
|
Initialize the LCD controller.
Call this function to initialize the hardware interface and the LCD controller. When initialization is done the display is turned on and ready to receive data.
References ioport_set_pin_low(), ST7565R_CMD_ADC_NORMAL, ST7565R_CMD_BOOSTER_RATIO_2X_3X_4X, ST7565R_CMD_BOOSTER_RATIO_SET, ST7565R_CMD_LCD_BIAS_1_DIV_6_DUTY33, ST7565R_CMD_POWER_CTRL_ALL_ON, ST7565R_CMD_REVERSE_SCAN_DIRECTION, ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_1, st7565r_display_invert_disable(), st7565r_display_on(), st7565r_hard_reset(), st7565r_interface_init(), st7565r_set_contrast(), and st7565r_write_command().
Referenced by gfx_mono_st7565r_init().
static uint8_t st7565r_read_data |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_set_all_pixels |
( |
bool |
pixels_on | ) |
|
|
inlinestatic |
static void st7565r_set_column_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static uint8_t st7565r_set_contrast |
( |
uint8_t |
contrast | ) |
|
|
inlinestatic |
Set the LCD contrast level.
- Warning
- This will set the voltage for the LCD, settings this value too high may result in damage to the LCD. Hence the limit for these settings must be defined in the conf_st7565r.h file.
Contrast values outside the max and min values will be clipped to the defined ST7565R_DISPLAY_CONTRAST_MAX and ST7565R_DISPLAY_CONTRAST_MIN.
- Parameters
-
contrast | a number between 0 and 63 where the max values is given by the LCD. |
- Return values
-
contrast | the contrast value written to the LCD controller |
References ST7565R_CMD_ELECTRONIC_VOLUME, ST7565R_CMD_ELECTRONIC_VOLUME_MODE_SET, and st7565r_write_command().
Referenced by st7565r_init().
static void st7565r_set_display_start_line_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static void st7565r_set_page_address |
( |
uint8_t |
address | ) |
|
|
inlinestatic |
static void st7565r_sleep_disable |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_sleep_enable |
( |
void |
| ) |
|
|
inlinestatic |
static void st7565r_soft_reset |
( |
void |
| ) |
|
|
inlinestatic |
Perform a soft reset of the LCD controller.
This functions will reset the LCD controller by sending the reset command.
- Note
- this functions should not be confused with the st7565r_hard_reset() function, this command will not control the RST pin.
References ST7565R_CMD_RESET, and st7565r_write_command().
static void st7565r_write_command |
( |
uint8_t |
command | ) |
|
|
inlinestatic |
Writes a command to the display controller.
This functions pull pin A0 low before writing to the controller. Different data write function is called based on the selected interface.
- Parameters
-
command | the command to write |
References usart_spi_device::id, spi_device::id, ioport_set_pin_low(), spi_deselect_device(), spi_select_device(), spi_write_single(), usart_spi_deselect_device(), usart_spi_select_device(), and usart_spi_transmit().
Referenced by st7565r_display_invert_disable(), st7565r_display_invert_enable(), st7565r_display_off(), st7565r_display_on(), st7565r_init(), st7565r_set_all_pixels(), st7565r_set_column_address(), st7565r_set_contrast(), st7565r_set_display_start_line_address(), st7565r_set_page_address(), st7565r_sleep_disable(), st7565r_sleep_enable(), and st7565r_soft_reset().
static void st7565r_write_data |
( |
uint8_t |
data | ) |
|
|
inlinestatic |
Write data to the display controller.
This functions sets the pin A0 before writing to the controller. Different data write function is called based on the selected interface.
- Parameters
-
References usart_spi_device::id, spi_device::id, ioport_set_pin_high(), ioport_set_pin_low(), spi_deselect_device(), spi_select_device(), spi_write_single(), usart_spi_deselect_device(), usart_spi_select_device(), and usart_spi_transmit().
Referenced by gfx_mono_st7565r_put_byte(), and gfx_mono_st7565r_put_page().