| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

drv_lcd_interface.c
1 //======================================================================================================================
2 // Copyright(c) 2018 Microchip Technology Inc. and its subsidiaries.
3 // Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with
4 // Microchip products. It is your responsibility to comply with third party license terms applicable to your use of
5 // third-party software (including open source software) that may accompany Microchip software.
6 // THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO
7 // THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR
8 // PURPOSE.
9 // IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE,
10 // COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED
11 // OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY
12 // ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE
13 // PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
14 //======================================================================================================================
15
16 //======================================================================================================================
17 // @file drv_lcd_interface.c
18 // @brief driver for the spi-interface to access the LCD controller
19 //======================================================================================================================
20
21 #include <stdint.h>
22 #include "common/delay.h"
23 #include "config/hal.h"
24
25
26 // PRIVATE FUNCTION CALL PROTOTYPES
27 void drv_LcdInterface_SpiSend(uint8_t data);
28
29 /*********************************************************************************
30 * @ingroup lib-driver-layer-lcd-interface-properties-private
31 * @{
32 * @brief Initial interface pin state conditions
33 **********************************************************************************/
34
35 #define LCD_CS_nSELECTED LCD_CS_SetHigh
36 #define LCD_CS_SELECTED LCD_CS_SetLow
37
38 #define LCD_RS_COMMAND LCD_RS_SetLow
39 #define LCD_RS_DATA LCD_RS_SetHigh
40 // end of group lib-driver-layer-lcd-interface-properties-private
42
43 /*********************************************************************************
44 * @ingroup lib-driver-layer-lcd-interface-functions-public
45 * @fn void drv_LcdInterface_Initialize(void)
46 * @brief Initializes the LCD interface driver
47 * @details
48 * This function needs to be called once at startup before calling
49 * any other function of the LCD device driver
50 **********************************************************************************/
51
52 void drv_LcdInterface_Initialize(void)
53 {
54 LCD_RST_SetHigh();
55 LCD_CS_nSELECTED();
56 LCD_SCL_SetLow();
57 LCD_SDI_SetLow();
58 LCD_RS_SetLow();
59
60 LCD_RST_SetDigitalOutput();
61 LCD_CS_SetDigitalOutput();
62 LCD_SCL_SetDigitalOutput();
63 LCD_SDI_SetDigitalOutput();
64 LCD_RS_SetDigitalOutput();
65 }
66
67 /*********************************************************************************
68 * @ingroup lib-driver-layer-lcd-interface-functions-public
69 * @fn void drv_LcdInterface_Reset(void)
70 * @brief Resets the LCD controller
71 * @details
72 * This function needs to be called once after system startup to reset
73 * the LCD controller and get into a defined state.
74 **********************************************************************************/
75
76 void drv_LcdInterface_Reset(void)
77 {
78 LCD_RST_SetLow();
79 __delay_ms(1);
80 LCD_RST_SetHigh();
81 }
82
83 /*********************************************************************************
84 * @ingroup lib-driver-layer-lcd-interface-functions-public
85 * @fn void drv_LcdInterface_SendCmd(uint8_t data)
86 * @brief Sends a command to the LCD controller
87 * @details
88 * This function sends a one byte long command via the initialized SPI interface
89 * to the LCD controller.
90 **********************************************************************************/
91
92 void drv_LcdInterface_SendCmd(uint8_t cmd)
93 {
94 LCD_CS_SELECTED();
95 LCD_RS_COMMAND();
96 drv_LcdInterface_SpiSend(cmd);
97 }
98
99 /*********************************************************************************
100 * @ingroup lib-driver-layer-lcd-interface-functions-public
101 * @fn void drv_LcdInterface_SendCmd(uint8_t data)
102 * @brief Sends one character to the display controller to be displayed on the LCD screen
103 * @details
104 * This function sends a single character via the initialized SPI interface
105 * to the LCD controller to be displayed on the LCD screen
106 **********************************************************************************/
107
108 extern void drv_LcdInterface_SendChar(const char c)
109 {
110 LCD_CS_SELECTED();
111 LCD_RS_DATA();
112 drv_LcdInterface_SpiSend(c);
113 }
114
115 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 // PRIVATE FUNCTIONS
117 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119 /*********************************************************************************
120 * @ingroup lib-driver-layer-lcd-interface-functions-private
121 * @fn void drv_LcdInterface_SpiSend(uint8_t data)
122 * @brief Sends data through the SPI interface to the LCD controller
123 * @details
124 * This function sends one byte via the initialized SPI interface to the
125 * LCD controller.
126 **********************************************************************************/
127
128 void drv_LcdInterface_SpiSend(uint8_t data)
129 {
130 uint8_t mask;
131
132 for(mask = 0x80; mask != 0; mask >>= 1)
133 {
134 LCD_SCL_SetLow();
135 Nop();
136 __delay_us(1);
137 if(data & mask)
138 LCD_SDI_SetHigh();
139 else
140 LCD_SDI_SetLow();
141 LCD_SCL_SetHigh();
142 Nop();
143 __delay_us(1);
144 }
145 LCD_CS_nSELECTED();
146 __delay_us(1);
147 }
148
149
150
151 // end of file