Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCD_X_Serial.c Source File

LCD_X_Serial.c

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH                         *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2018  SEGGER Microcontroller GmbH                *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.48 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : LCD_X_SERIAL_1.c
00041 Purpose     : Port routines
00042 ----------------------------------------------------------------------
00043 */
00044 
00045 #ifndef LCD_DELAY
00046   #define LCD_DELAY(x)
00047 #endif
00048 
00049 #ifndef LCD_SET_CS
00050   #define LCD_SET_CS()
00051   #define LCD_CLR_CS()
00052 #endif
00053 
00054 /*********************************************************************
00055 *
00056 *           Hardware configuration
00057 *
00058 **********************************************************************
00059 
00060   Needs to be adapted to your target hardware.
00061 */
00062 
00063 /* Configuration example:
00064 
00065 #define LCD_CLR_A0()      P7 &= ~(1<<1)
00066 #define LCD_SET_A0()      P7 |=  (1<<1) 
00067 #define LCD_CLR_RESET()   P7 &= ~(1<<2)
00068 #define LCD_SET_RESET()   P7 |=  (1<<2) 
00069 #define LCD_CLR_CLK()     P7 &= ~(1<<3)
00070 #define LCD_SET_CLK()     P7 |=  (1<<3) 
00071 #define LCD_CLR_DATA()    P7 &= ~(1<<4)
00072 #define LCD_SET_DATA()    P7 |=  (1<<4) 
00073 #define LCD_SET_DIR_OUT() P7D = 0xff
00074 #define LCD_CLR_CS()      P7 &= ~(1<<0)      // Optional
00075 #define LCD_SET_CS()      P7 |=  (1<<0)      // Optional
00076 #define LCD_CLR_CS1()     P7 &= ~(1<<5)      // Optional (only for mult. controllers)
00077 #define LCD_SET_CS1()     P7 |=  (1<<5)      // Optional (only for mult. controllers)
00078 #define LCD_DELAY(ms)     GUI_Delay(ms)      // Optional
00079 
00080 */
00081 
00082 /*********************************************************************
00083 *
00084 *           Initialisation
00085 *
00086 **********************************************************************
00087   This routine should be called from your application program
00088   to set port pins to their initial values
00089 */
00090 
00091 void LCD_X_Init(void) {
00092   LCD_CLR_RESET();
00093   LCD_SET_DIR_OUT();
00094   LCD_SET_CS();
00095   #ifdef LCD_SET_CS1
00096     LCD_SET_CS1();
00097   #endif
00098   LCD_SET_A0();
00099   LCD_SET_RESET();
00100   LCD_SET_CLK();
00101   LCD_SET_DATA();
00102   LCD_DELAY(20);
00103   LCD_SET_RESET();
00104   LCD_DELAY(20);
00105 }
00106 
00107 /*********************************************************************
00108 *
00109 *           Send1 routine
00110 *
00111 **********************************************************************
00112 
00113   Usually, there is no need to modify this routine.
00114   It should be sufficient ot modify the low-level macros above or
00115   in a configuration file.
00116 */
00117 
00118 /* Write 1 byte, MSB first */
00119 static void Send1(unsigned char Data) {
00120   if ((Data >> 7) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00121   if ((Data >> 6) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00122   if ((Data >> 5) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00123   if ((Data >> 4) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00124   if ((Data >> 3) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00125   if ((Data >> 2) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00126   if ((Data >> 1) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00127   if ((Data >> 0) & 1) LCD_SET_DATA(); else LCD_CLR_DATA(); LCD_CLR_CLK(); LCD_SET_CLK();
00128 }
00129 
00130 /*********************************************************************
00131 *
00132 *           Read1 routine
00133 *
00134 **********************************************************************
00135 */
00136 
00137 /* Read 1 byte, MSB first */
00138 static unsigned char Read1(void) {
00139   unsigned char Data = 0;
00140   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 7);
00141   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 6);
00142   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 5);
00143   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 4);
00144   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 3);
00145   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 2);
00146   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 1);
00147   LCD_CLR_CLK(); LCD_SET_CLK(); if (LCD_SDO()) Data |= (1 << 0);
00148   return Data;
00149 }
00150 
00151 /*********************************************************************
00152 *
00153 *           Controller 0
00154 *
00155 **********************************************************************
00156 
00157 */
00158 
00159 /* Write to controller, with A0 = 1 */
00160 void LCD_X_Write01(unsigned char Data) {
00161   LCD_CLR_CS();
00162   LCD_SET_A0();
00163   Send1(Data);
00164   LCD_SET_CS();
00165 }
00166 
00167 /* Write multiple bytes to controller, with A0 = 1 */
00168 void LCD_X_WriteM01(unsigned char * pData, int NumBytes) {
00169   LCD_CLR_CS();
00170   LCD_SET_A0();
00171   for (; NumBytes; NumBytes--) {
00172     Send1(*pData++);
00173   }
00174   LCD_SET_CS();
00175 }
00176 
00177 /* Write to controller, with A0 = 0 */
00178 void LCD_X_Write00(unsigned char Cmd) {
00179   LCD_CLR_CS();
00180   LCD_CLR_A0();
00181   Send1(Cmd);
00182   LCD_SET_CS();
00183 }
00184 
00185 /* Read from controller, with A0 = 1 */
00186 unsigned char LCD_X_Read01(void) {
00187   unsigned char Data;
00188   LCD_CLR_CS();
00189   LCD_CLR_A0();
00190   Data = Read1();
00191   LCD_SET_CS();
00192   return Data;
00193 }
00194 
00195 /*********************************************************************
00196 *
00197 *           Controller 1 (optional)
00198 *
00199 **********************************************************************
00200 
00201 */
00202 
00203 #ifdef LCD_SET_CS1
00204 /* Write to controller, with A0 = 1 */
00205 void LCD_X_Write11(unsigned char Data) {
00206   LCD_CLR_CS1();
00207   LCD_SET_A0();
00208   Send1(Data);
00209   LCD_SET_CS1();
00210 }
00211 
00212 /* Write multiple bytes to controller, with A0 = 1 */
00213 void LCD_X_WriteM11(unsigned unsigned char * pData, int NumBytes) {
00214   LCD_CLR_CS1();
00215   LCD_SET_A0();
00216   for (; NumBytes; NumBytes--) {
00217     Send1(*pData++);
00218   }
00219   LCD_SET_CS1();
00220 }
00221 
00222 /* Write to controller, with A0 = 0 */
00223 void LCD_X_Write10(unsigned char Cmd) {
00224   LCD_CLR_CS1();
00225   LCD_CLR_A0();
00226   Send1(Cmd);
00227   LCD_SET_CS1();
00228 }
00229 #endif
00230