Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: PCF8576_GH08172_test
PCF8576.cpp
00001 /* Copyright (c) 2016 ARM Ltd., MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 * 00018 */ 00019 #include "PCF8576.h" 00020 00021 PCF8576::PCF8576(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) 00022 { 00023 initialize(); 00024 } 00025 00026 PCF8576::PCF8576(I2C &i2c_obj, int addr) : m_i2c(i2c_obj), m_addr(addr) 00027 { 00028 initialize(); 00029 } 00030 00031 PCF8576::~PCF8576() 00032 { 00033 } 00034 00035 void PCF8576::initialize() 00036 { 00037 m_i2c.frequency(200000); 00038 00039 for(uint32_t i = 0; i < 14; i++) { 00040 m_lcd_buf[i] = 0; 00041 } 00042 00043 m_C5_mask = m_C6_mask = 0; 00044 00045 m_lcd_buf[0] = PCF8576_CMD_MODE_SET 00046 | (0x0 << 0) // 1:4 multiplex 00047 | (0 << 2) // LCD 1/3 bias 00048 | (1 << 3) // enable display 00049 | (1 << 7); // another command to follow 00050 00051 m_lcd_buf[1] = PCF8576_CMD_BINK 00052 | (0x0 << 0) // blinking off 00053 | (0 << 2) // blink mode normal 00054 | (0 << 7); // last command 00055 00056 m_i2c.write(PCF8576_DEFAULT_SLAVE_ADDRESS, m_lcd_buf, 14); 00057 00058 } 00059 00060 void PCF8576::icon(uint32_t count) 00061 { 00062 if (count & 0x08) { 00063 m_C5_mask |= 0x01; 00064 m_lcd_buf[11] |= 0x01; 00065 } else { 00066 m_C5_mask &= ~0x01; 00067 m_lcd_buf[11] &= ~0x01; 00068 } 00069 00070 if (count & 0x04) { 00071 m_C5_mask |= 0x02; 00072 m_lcd_buf[11] |= 0x02; 00073 } else { 00074 m_C5_mask &= ~0x02; 00075 m_lcd_buf[11] &= ~0x02; 00076 } 00077 00078 if (count & 0x02) { 00079 m_C6_mask |= 0x01; 00080 m_lcd_buf[13] |= 0x01; 00081 } else { 00082 m_C6_mask &= ~0x01; 00083 m_lcd_buf[13] &= ~0x01; 00084 } 00085 00086 if (count & 0x01) { 00087 m_C6_mask |= 0x02; 00088 m_lcd_buf[13] |= 0x02; 00089 } else { 00090 m_C6_mask &= ~0x02; 00091 m_lcd_buf[13] &= ~0x02; 00092 } 00093 m_i2c.write(PCF8576_DEFAULT_SLAVE_ADDRESS, m_lcd_buf, 14); 00094 00095 } 00096 00097 00098 void PCF8576::print(char *str) 00099 { 00100 uint32_t len = strlen(str); 00101 if (len == 0) 00102 return; 00103 if (len > 6) 00104 len = 6; 00105 00106 m_lcd_buf[0] = PCF8576_CMD_DEVICE_SEL | (1 << 7); 00107 m_lcd_buf[1] = PCF8576_CMD_LOAD_DATA; 00108 00109 for(uint32_t i = 0; i < len; i++) { 00110 m_lcd_buf[(i*2) + 2] = (char)(FontMatrix[(*str - ' ')] & 0xFF); 00111 m_lcd_buf[(i*2) + 3] = (char)(FontMatrix[(*str - ' ')] >> 8); 00112 str++; 00113 } 00114 00115 m_lcd_buf[11] |= m_C5_mask; 00116 m_lcd_buf[13] |= m_C6_mask; 00117 00118 m_i2c.write(PCF8576_DEFAULT_SLAVE_ADDRESS, m_lcd_buf, 2 + (len*2)); 00119 }
Generated on Wed Jul 13 2022 02:09:56 by
1.7.2
NXP PCF8576 Universal LCD driver