mcufriend 2.4 TFT LCD Shield Lib
Dependents: Nucleo_LCD_mcufriend_test
Fork of 24_TFT_STMNUCLEO by
mcufriend 2.4" TFT LCD Shield
Import program
00001 #include "mbed.h" 00002 #include "ili9328.h" 00003 00004 // prepare the data bus for writing commands and pixel data 00005 BusOut dataBus( D8, D9, D2, D3, D4, D5, D6, D7 ); // 8 pins 00006 // create the lcd instance 00007 ILI9328_LCD lcd( A3, A4, A2,A1, &dataBus, NC, A0); // control pins and data bus 00008 //ILI9328_LCD( CS, RESET, RS, WR, BusOut* DATA_PORT, PinName BL = NC, RD ); 00009 00010 int main() 00011 { 00012 int ii,height,width; 00013 00014 height = lcd.GetHeight(); 00015 width = lcd.GetWidth(); 00016 // initialize display - place it in standard portrait mode and set background to black and 00017 // foreground to white color. 00018 lcd.Initialize(); 00019 00020 // print something on the screen 00021 lcd.Print( "Hello, World!", CENTER, 50); // align text to center horizontally and use starndard colors 00022 00023 wait(2); 00024 00025 lcd.ClearScreen(); 00026 00027 for(ii=0;ii<width;ii++) 00028 { 00029 lcd.DrawLine(0, 0, height, ii,COLOR_GREEN); 00030 ii = ii+10; 00031 } 00032 wait(2); 00033 00034 lcd.DrawCircle(height/4, width/4, 20, COLOR_GREEN); 00035 wait(2); 00036 00037 lcd.FillCircle(height/2, width/2, 50, COLOR_GREEN); 00038 wait(2); 00039 00040 lcd.FillTriangle(height/4, width/4,(height/4)+20, (width/4)+40,(height/4)-20, (width/4)+40, COLOR_RED); 00041 00042 while ( 1 ) { } 00043 }
HW information about the mcufriend LCD Shield
Diff: lcd_base.h
- Revision:
- 22:4c169297f374
- Parent:
- 21:e5c1e8ffada1
- Child:
- 30:ede1a0a32e04
--- a/lcd_base.h Sat Jan 26 02:55:46 2013 +0000 +++ b/lcd_base.h Sat Jan 26 04:36:46 2013 +0000 @@ -158,6 +158,34 @@ */ typedef struct Bitmap_struct bitmap_t; +/** \struct BacklightPwmCtrl_enum + * \brief Type of backlight control for the LCD. + * + * When the selected type is \c Constant, the pin is simply on or off - there is no gradation in the intensity of the display. + * In this case any free pin can be used to control the backlight. On the other hand, when PWM is used to control brightness, + * take care to use only PWM-able mbed pins (p21, p22, p23, p24, p25, and p26), any other pins won't work. It is assumed that + * you know what you are doing, so no check is done to prevent using a non-PWM pin as assigned control pin, when either \c Direct + * or \c Indirect option is used. + * + * \version 0.1 + * \remark When choosing PWM to control the backlight, you have the option to choose the pin to either source (\c Direct) or sink + * (\c Indirect) the current for LCD brightness control. Be aware that the mbed pins can source (and probably sink when + * configured as inputs) only 4 mA @+3V3 VDD. So if you are intending to use a bigger LCD, whith more LEDs in its backlight + * implementation, you probably want to interface it through a small signal transistor or a small MOSFET, in order to be able + * to handle a higher current without damaging your mbed. + * \remark As of version 0.1 (2013-01-25) the Indirect method of PWM has not been implemented yet. + */ +enum BacklightPwmCtrl_enum +{ + Constant, /**< When the pin is a simple on/off switch. */ + Direct, /**< Control the brightness with PWM, as the control pin is sourcing the current to drive the backlight LEDs. */ + Indirect, /**< Control the brightness with PWM, as the control pin is sinking the current which drives the backlight LEDs. */ +}; +/** \typedef backlight_t + * \brief Convenience shortcut for the backlight control type. + */ +typedef BacklightPwmCtrl_enum backlight_t; + /** Base class for LCD implementations. * @@ -202,7 +230,7 @@ * \remarks This function is controller-specific and needs to be * implemented separately for each available display. */ - virtual void Sleep( void ) = 0; + virtual void Sleep( void ); /** Wakes up the display from sleep mode. * @@ -212,7 +240,7 @@ * \remarks This function is controller-specific and needs to be * implemented separately for each available display. */ - virtual void WakeUp( void ) = 0; + virtual void WakeUp( void ); /** Set the foreground color for painting. * @@ -271,6 +299,11 @@ */ virtual void FillScreen( int color = -1 ); + /** Sets the backlight intensity in percent as a float value in the range [0.0,1.0]. + * \param level The backligh intensity in percent, where 0.0 is off and 1.0 is full brightness. + */ + virtual void SetBacklightLevel( float level ); + /** Clears the screen. * * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color. @@ -408,8 +441,11 @@ * \param CS Pin connected to the CS input of the display. * \param RS Pin connected to the RS input of the display. * \param RESET Pin connected to the RESET input of the display. + * \param BL Pin connected to the circuit controlling the LCD's backlight. + * \param blType The type of backlight to be used. + * \param defaultBacklight The standard backlight intensity (if using PWM control), expressed in percent as float value from 0.0 to 1.0 */ - LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET ); + LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight ); /** Activates the display for command/data transfer. * @@ -539,6 +575,10 @@ colordepth_t _colorDepth; unsigned int _foreground, _background; const font_t* _font; + DigitalOut* _lcd_pin_bl; + PwmOut* _bl_pwm; + backlight_t _bl_type; + float _bl_pwm_default, _bl_pwm_current; }; #ifdef __cplusplus