|
| 1 | +/* --COPYRIGHT--,BSD |
| 2 | + * Copyright (c) 2014, Texas Instruments Incorporated |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of Texas Instruments Incorporated nor the names of |
| 17 | + * its contributors may be used to endorse or promote products derived |
| 18 | + * from this software without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 22 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 27 | + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 28 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 29 | + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 30 | + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + * --/COPYRIGHT--*/ |
| 32 | +/******************************************************************************* |
| 33 | + * |
| 34 | + * hal_LCD.c |
| 35 | + * |
| 36 | + * Hardware abstraction layer for the FH-1138P Segmented LCD |
| 37 | + * |
| 38 | + * September 2014 |
| 39 | + * E. Chen |
| 40 | + * |
| 41 | + ******************************************************************************/ |
| 42 | + |
| 43 | +#include "hal_LCD.h" |
| 44 | +#include "string.h" |
| 45 | +#include <driverlib.h> |
| 46 | + |
| 47 | +// LCD memory map for numeric digits |
| 48 | +const char digit[10][2] = |
| 49 | +{ |
| 50 | + {0xFC, 0x28}, /* "0" LCD segments a+b+c+d+e+f+k+q */ |
| 51 | + {0x60, 0x20}, /* "1" */ |
| 52 | + {0xDB, 0x00}, /* "2" */ |
| 53 | + {0xF3, 0x00}, /* "3" */ |
| 54 | + {0x67, 0x00}, /* "4" */ |
| 55 | + {0xB7, 0x00}, /* "5" */ |
| 56 | + {0xBF, 0x00}, /* "6" */ |
| 57 | + {0xE4, 0x00}, /* "7" */ |
| 58 | + {0xFF, 0x00}, /* "8" */ |
| 59 | + {0xF7, 0x00} /* "9" */ |
| 60 | +}; |
| 61 | + |
| 62 | +// LCD memory map for uppercase letters |
| 63 | +const char alphabetBig[26][2] = |
| 64 | +{ |
| 65 | + {0xEF, 0x00}, /* "A" LCD segments a+b+c+e+f+g+m */ |
| 66 | + {0xF1, 0x50}, /* "B" */ |
| 67 | + {0x9C, 0x00}, /* "C" */ |
| 68 | + {0xF0, 0x50}, /* "D" */ |
| 69 | + {0x9F, 0x00}, /* "E" */ |
| 70 | + {0x8F, 0x00}, /* "F" */ |
| 71 | + {0xBD, 0x00}, /* "G" */ |
| 72 | + {0x6F, 0x00}, /* "H" */ |
| 73 | + {0x90, 0x50}, /* "I" */ |
| 74 | + {0x78, 0x00}, /* "J" */ |
| 75 | + {0x0E, 0x22}, /* "K" */ |
| 76 | + {0x1C, 0x00}, /* "L" */ |
| 77 | + {0x6C, 0xA0}, /* "M" */ |
| 78 | + {0x6C, 0x82}, /* "N" */ |
| 79 | + {0xFC, 0x00}, /* "O" */ |
| 80 | + {0xCF, 0x00}, /* "P" */ |
| 81 | + {0xFC, 0x02}, /* "Q" */ |
| 82 | + {0xCF, 0x02}, /* "R" */ |
| 83 | + {0xB7, 0x00}, /* "S" */ |
| 84 | + {0x80, 0x50}, /* "T" */ |
| 85 | + {0x7C, 0x00}, /* "U" */ |
| 86 | + {0x0C, 0x28}, /* "V" */ |
| 87 | + {0x6C, 0x0A}, /* "W" */ |
| 88 | + {0x00, 0xAA}, /* "X" */ |
| 89 | + {0x00, 0xB0}, /* "Y" */ |
| 90 | + {0x90, 0x28} /* "Z" */ |
| 91 | +}; |
| 92 | + |
| 93 | +void Init_LCD() |
| 94 | +{ |
| 95 | + // L0~L26 & L36~L39 pins selected |
| 96 | + LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_SEGMENT_LINE_26); |
| 97 | + LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_36, LCD_E_SEGMENT_LINE_39); |
| 98 | + |
| 99 | + LCD_E_initParam initParams = LCD_E_INIT_PARAM; |
| 100 | + initParams.clockDivider = LCD_E_CLOCKDIVIDER_3; |
| 101 | + initParams.muxRate = LCD_E_4_MUX; |
| 102 | + initParams.segments = LCD_E_SEGMENTS_ENABLED; |
| 103 | + |
| 104 | + // Init LCD as 4-mux mode |
| 105 | + LCD_E_init(LCD_E_BASE, &initParams); |
| 106 | + |
| 107 | + // LCD Operation - Mode 3, internal 3.02v, charge pump 256Hz |
| 108 | + LCD_E_setVLCDSource(LCD_E_BASE, LCD_E_INTERNAL_REFERENCE_VOLTAGE, LCD_E_EXTERNAL_SUPPLY_VOLTAGE); |
| 109 | + LCD_E_setVLCDVoltage(LCD_E_BASE, LCD_E_REFERENCE_VOLTAGE_2_96V); |
| 110 | + |
| 111 | + LCD_E_enableChargePump(LCD_E_BASE); |
| 112 | + LCD_E_setChargePumpFreq(LCD_E_BASE, LCD_E_CHARGEPUMP_FREQ_16); |
| 113 | + |
| 114 | + // Clear LCD memory |
| 115 | + LCD_E_clearAllMemory(LCD_E_BASE); |
| 116 | + |
| 117 | + // Configure COMs and SEGs |
| 118 | + // L0 = COM0, L1 = COM1, L2 = COM2, L3 = COM3 |
| 119 | + LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_MEMORY_COM0); |
| 120 | + LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_1, LCD_E_MEMORY_COM1); |
| 121 | + LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_2, LCD_E_MEMORY_COM2); |
| 122 | + LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_3, LCD_E_MEMORY_COM3); |
| 123 | + |
| 124 | + // Select to display main LCD memory |
| 125 | + LCD_E_selectDisplayMemory(LCD_E_BASE, LCD_E_DISPLAYSOURCE_MEMORY); |
| 126 | + |
| 127 | + // Turn on LCD |
| 128 | + LCD_E_on(LCD_E_BASE); |
| 129 | +} |
| 130 | + |
| 131 | +/* |
| 132 | + * Scrolls input string across LCD screen from left to right |
| 133 | + */ |
| 134 | +void displayScrollText(char *msg) |
| 135 | +{ |
| 136 | + int length = strlen(msg); |
| 137 | + int i; |
| 138 | + int s = 5; |
| 139 | + char buffer[6] = " "; |
| 140 | + for (i=0; i<length+7; i++) |
| 141 | + { |
| 142 | + int t; |
| 143 | + for (t=0; t<6; t++) |
| 144 | + buffer[t] = ' '; |
| 145 | + int j; |
| 146 | + for (j=0; j<length; j++) |
| 147 | + { |
| 148 | + if (((s+j) >= 0) && ((s+j) < 6)) |
| 149 | + buffer[s+j] = msg[j]; |
| 150 | + } |
| 151 | + s--; |
| 152 | + |
| 153 | + showChar(buffer[0], pos1); |
| 154 | + showChar(buffer[1], pos2); |
| 155 | + showChar(buffer[2], pos3); |
| 156 | + showChar(buffer[3], pos4); |
| 157 | + showChar(buffer[4], pos5); |
| 158 | + showChar(buffer[5], pos6); |
| 159 | + |
| 160 | + __delay_cycles(200000); |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +/* |
| 165 | + * Displays input character at given LCD digit/position |
| 166 | + * Only spaces, numeric digits, and uppercase letters are accepted characters |
| 167 | + */ |
| 168 | +void showChar(char c, int position) |
| 169 | +{ |
| 170 | + if (c == ' ') |
| 171 | + { |
| 172 | + // Display space |
| 173 | + LCDMEMW[position/2] = 0; |
| 174 | + } |
| 175 | + else if (c >= '0' && c <= '9') |
| 176 | + { |
| 177 | + // Display digit |
| 178 | + LCDMEMW[position/2] = digit[c-48][0] | (digit[c-48][1] << 8); |
| 179 | + } |
| 180 | + else if (c >= 'A' && c <= 'Z') |
| 181 | + { |
| 182 | + // Display alphabet |
| 183 | + LCDMEMW[position/2] = alphabetBig[c-65][0] | (alphabetBig[c-65][1] << 8); |
| 184 | + } |
| 185 | + else |
| 186 | + { |
| 187 | + // Turn all segments on if character is not a space, digit, or uppercase letter |
| 188 | + LCDMEMW[position/2] = 0xFFFF; |
| 189 | + } |
| 190 | +} |
| 191 | + |
| 192 | +/* |
| 193 | + * Clears memories to all 6 digits on the LCD |
| 194 | + */ |
| 195 | +void clearLCD() |
| 196 | +{ |
| 197 | + LCDMEMW[pos1/2] = 0; |
| 198 | + LCDMEMW[pos2/2] = 0; |
| 199 | + LCDMEMW[pos3/2] = 0; |
| 200 | + LCDMEMW[pos4/2] = 0; |
| 201 | + LCDMEMW[pos5/2] = 0; |
| 202 | + LCDMEMW[pos6/2] = 0; |
| 203 | + LCDMEM[12] = LCDMEM[13] = 0; |
| 204 | +} |
0 commit comments