Нужна помощь по связке LCD5110 + MSP430 Launchpad
- Войдите на сайт для отправки комментариев
Чт, 29/10/2015 - 07:30
Всем привет! Недавно попал в руки Launchpad MSP430 на 2553 контроллере. Удалось к нему подключить экрачик 5110, текст на него вывести удалось, но статичную картинку вывести никак не получается. Как это можно реализовать ? Использовалась Energia
Сам код:
#include "msp430g2553.h"
#include "LCD_5110.h"
LCD_5110 myScreen =
LCD_5110(
P2_4, // Chip Select * #3 on sparkfun breakout SCE
P2_3, // Serial Clock * #7 on sparkfun breakout SCLK
P2_2, // Serial Data * #6 on sparkfun breakout DN(MOSI)
P2_1, // Data/Command * #5 on sparkfun breakout D/C
P2_0, // Reset * #4 on sparkfun breakout RST
P2_5, // Backlight #8 on sparkfun breakout LED
PUSH2 // Push Button 2
);
// Add setup code
void setup() {
myScreen.begin();
myScreen.setFont(1);
myScreen.text(1, 1, "MSP430");
myScreen.setFont(0);
myScreen.text(0, 5, "1234567890abcd");
}
void loop() {
}
Используемая библиотека
Файл LCD_5110.cpp
#include "LCD_5110.h" const uint8_t _commandLCD = 0x00; const uint8_t _dataLCD = 0x01; uint8_t _pinReset; uint8_t _pinSerialData; uint8_t _pinBacklight; uint8_t _pinChipSelect; uint8_t _pinDataCommand; uint8_t _pinSerialClock; uint8_t _pinPushButton; LCD_5110::LCD_5110() { LCD_5110(P2_2, // Chip Select P2_4, // Serial Clock P2_0, // Serial Data P2_3, // Data/Command P1_0, // Reset P2_1, // Backlight PUSH2); // Push Button 2 } LCD_5110::LCD_5110(uint8_t pinChipSelect, uint8_t pinSerialClock, uint8_t pinSerialData, uint8_t pinDataCommand, uint8_t pinReset, uint8_t pinBacklight, uint8_t pinPushButton) { _pinChipSelect = pinChipSelect; _pinSerialClock = pinSerialClock; _pinSerialData = pinSerialData; _pinDataCommand = pinDataCommand; _pinReset = pinReset; _pinBacklight = pinBacklight; _pinPushButton = pinPushButton; } void LCD_5110::write(uint8_t dataCommand, uint8_t c) { digitalWrite(_pinDataCommand, dataCommand); digitalWrite(_pinChipSelect, LOW); shiftOut(_pinSerialData, _pinSerialClock, MSBFIRST, c); digitalWrite(_pinChipSelect, HIGH); } void LCD_5110::setXY(uint8_t x, uint8_t y) { write(_commandLCD, 0x40 | y); write(_commandLCD, 0x80 | x); } void LCD_5110::begin() { pinMode(_pinChipSelect, OUTPUT); pinMode(_pinReset, OUTPUT); pinMode(_pinDataCommand, OUTPUT); pinMode(_pinSerialData, OUTPUT); pinMode(_pinSerialClock, OUTPUT); pinMode(_pinBacklight, OUTPUT); pinMode(_pinPushButton, INPUT_PULLUP); digitalWrite(_pinDataCommand, LOW); delay(30); digitalWrite(_pinReset, LOW); delay(100); // as per 8.1 Initialisation digitalWrite(_pinReset, HIGH); write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V — try other values write(_commandLCD, 0x12); // set Bias System 1:48 write(_commandLCD, 0x20); // chip is active, horizontal addressing, use basic instruction set write(_commandLCD, 0x09); // temperature control write(_commandLCD, 0x0c); // normal mode delay(10); clear(); _font = 0; setBacklight(false); } String LCD_5110::WhoAmI() { return "LCD Nokia 5110"; } void LCD_5110::clear() { setXY(0, 0); for (uint16_t i=0; i<6*84; i++) write(_dataLCD, 0x00); setXY(0, 0); } void LCD_5110::setBacklight(boolean b) { digitalWrite(_pinBacklight, b ? LOW : HIGH); } void LCD_5110::setFont(uint8_t font) { _font = font; } void LCD_5110::text(uint8_t x, uint8_t y, String s) { uint8_t i; uint8_t j; if (_font==0) { setXY(6*x, y); for (j=0; j<s.length(); j++) { for (i=0; i<5; i++) write(_dataLCD, Terminal6x8[s.charAt(j)-' '][i]); write(_dataLCD, 0x00); } } else if (_font==1) { setXY(6*x, y); for (j=0; j<s.length(); j++) { for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i]); write(_dataLCD, 0x00); } setXY(6*x, y+1); for (j=0; j<s.length(); j++) { for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i+1]); write(_dataLCD, 0x00); } } } boolean LCD_5110::getButton() { if (digitalRead(_pinPushButton)==LOW) { while (digitalRead(_pinPushButton)==LOW); // debounce return true; } else { return false; } }Файл LCD_5110.h
#if defined (__AVR_ATmega328P__) || defined(__AVR_ATmega2560__) // Arduino specific #include "WProgram.h" // #include "Arduino.h" for Arduino 1.0 #elif defined(__32MX320F128H__) || defined(__32MX795F512L__) // chipKIT specific #include "WProgram.h" #elif defined(__AVR_ATmega644P__) // Wiring specific #include "Wiring.h" #elif defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific #include "Energia.h" #elif defined(MCU_STM32F103RB) || defined(MCU_STM32F103ZE) || defined(MCU_STM32F103CB) || defined(MCU_STM32F103RE) // Maple specific #include "WProgram.h" #endif #ifndef LCD_5110_h #define LCD_5110_h #include "Terminal6.h" #include "Terminal12.h" class LCD_5110 { public: LCD_5110(); LCD_5110(uint8_t pinChipSelect, uint8_t pinSerialClock, uint8_t pinSerialData, uint8_t pinDataCommand, uint8_t pinReset, uint8_t pinBacklight, uint8_t pinPushButton); void begin(); String WhoAmI(); void clear(); void setBacklight(boolean b=true); void setFont(uint8_t font=0); uint8_t fontX(); uint8_t fontY(); void text(uint8_t x, uint8_t y, String s); boolean getButton(); private: void setXY(uint8_t x, uint8_t y); void write(uint8_t dataCommand, uint8_t c); uint8_t _font; }; #endifЭта библиотека не выводит картинок (по крайней мере, я не вижу в ней таких функций). Возьмите другую, такую где есть метод типа drawBitmap