📄 lcd.c
字号:
LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
ID3 = GPIO_ReadInputData( GPIOx_D_LCD );
LCD_DataLinesConfig( Output );
}
/*******************************************************************************
*
* LCD_DrawChar
*
*******************************************************************************/
/**
* Draw a character on the LCD screen.
*
* @param[in] x The line where to display the character shape.
* @param[in] y The column start address.
* @param[in] width The number of columns (dots) in a character width.
* @param[in] bmp The character (monochrome) bitmap. A pointer of the dot matrix data.
* @param[in] textColor The character color.
* @param[in] bGndColor The character background color.
* @param[in] charMagniCoeff The character magnifying coefficient.
*
* @warning The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8* bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff )
{
int i;
int j;
int k1;
int k2;
// Select the area for LCD output.
LCD_SetRect_For_Cmd( x, y, 7 * charMagniCoeff, 14 * charMagniCoeff );
// Select LCD output mode.
LCD_SendLCDCmd( ST7637_RAMWR );
for( i = 0; i < 7; i++ )
{
for( k1 = 0; k1 < charMagniCoeff; k1++ )
{
for( j = 0x80; j; j >>= 1 ) // 8
{
for( k2 = 0; k2 < charMagniCoeff; k2++ )
{
LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) );
LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) );
}
}
for( j = 0x80; j > 2; j >>= 1 ) // 8
{
for( k2 = 0; k2 < charMagniCoeff; k2++ )
{
LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) );
LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) );
}
}
}
}
}
/*******************************************************************************
*
* LCD_DisplayRotate
*
*******************************************************************************/
/**
* Configure the LCD controller for a given orientation.
*
* @param[in] H12 The new screen orientation.
*
**/
/******************************************************************************/
static void LCD_DisplayRotate( Rotate_H12_V_Match_TypeDef H12 )
{
// Memory Access Control 0x36
LCD_SendLCDCmd( ST7637_MADCTR );
switch( H12 )
{
case V3 :
LCD_SendLCDData( V3_MADCTRVAL );
break;
case V6 :
LCD_SendLCDData( V6_MADCTRVAL );
break;
case V9 :
LCD_SendLCDData( V9_MADCTRVAL );
break;
case V12 :
default :
LCD_SendLCDData( V12_MADCTRVAL );
break;
}
}
/*******************************************************************************
*
* LCD_7637_Controller
*
*******************************************************************************/
/**
* Initialization of the controller registers.
*
* @note See ST7637.PDF for more information.
*
**/
/******************************************************************************/
static void LCD_7637_Controller( void )
{
extern void starting_delay ( long unsigned );
/** Apply hardware reset **/
LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */
starting_delay( 0x500 );
LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
starting_delay( 0x500 );
//default mode is output
LCD_DataLinesConfig( Output );
LCD_CheckLCDStatus();
LCD_SendLCDCmd( ST7637_SWRESET );
//-----------disable autoread + Manual read once ----------------------------
LCD_SendLCDCmd( ST7637_AUTOLOADSET ); // Auto Load Set 0xD7
LCD_SendLCDData( 0xBF ); // Auto Load Disable
LCD_SendLCDCmd( ST7637_EPCTIN ); // EE Read/write mode 0xE0
LCD_SendLCDData( 0x00 ); // Set read mode
LCD_SendLCDCmd( ST7637_EPMRD ); // Read active 0xE3
LCD_SendLCDCmd( ST7637_EPCTOUT ); // Cancel control 0xE1
//---------------------------------- Sleep OUT ------------------------------
LCD_SendLCDCmd( ST7637_DISPOFF ); // display off 0x28
LCD_SendLCDCmd( ST7637_SLPOUT ); // Sleep Out 0x11
//--------------------------------Vop setting--------------------------------
LCD_SendLCDCmd( ST7637_VOPSET ); // Set Vop by initial Module 0xC0
LCD_SendLCDData( 0xFB ); // Vop = 13.64
LCD_SendLCDData( 0x00 ); // base on Module
//----------------------------Set Register-----------------------------------
LCD_SendLCDCmd( ST7637_BIASSEL ); // Bias select 0xC3
LCD_SendLCDData( 0x00 ); // 1/12 Bias, base on Module
LCD_SendLCDCmd( ST7637_BSTBMPXSEL ); // Setting Booster times 0xC4
LCD_SendLCDData( 0x05 ); // Booster X 8
LCD_SendLCDCmd( ST7637_BSTEFFSEL ); // Booster eff 0xC5
LCD_SendLCDData( 0x11 ); // BE = 0x01 (Level 2)
LCD_SendLCDCmd( ST7637_VGSORCSEL ); // Vg with booster x2 control 0xcb
LCD_SendLCDData( 0x01 ); // Vg from Vdd2
LCD_SendLCDCmd( ST7637_ID1SET ); // ID1 = 00 0xcc
LCD_SendLCDData( 0x00 ); //
LCD_SendLCDCmd( ST7637_ID3SET ); // ID3 = 00 0xce
LCD_SendLCDData( 0x00 ); //
LCD_SendLCDCmd( 0xB7 ); // Glass direction
LCD_SendLCDData( 0xC0 ); //
LCD_SendLCDCmd( ST7637_ANASET ); // Analog circuit setting 0xd0
LCD_SendLCDData( 0x1D ); //
LCD_SendLCDCmd( 0xB4 ); // PTL mode set
LCD_SendLCDData( 0x18 ); // power normal mode
LCD_SendLCDCmd( ST7637_INVOFF ); // Display Inversion OFF 0x20
LCD_SendLCDCmd( 0x2A ); // column range
LCD_SendLCDData( 0x04 ); //
LCD_SendLCDData( 0x83 ); //
LCD_SendLCDCmd( 0x2B ); // raw range
LCD_SendLCDData( 0x04 ); //
LCD_SendLCDData( 0x83 ); //
LCD_SendLCDCmd( ST7637_COLMOD ); // Color mode = 65k 0x3A
LCD_SendLCDData( 0x05 ); //
LCD_SendLCDCmd( ST7637_MADCTR ); // Memory Access Control 0x36
LCD_SendLCDData( V9_MADCTRVAL );
LCD_SendLCDCmd( ST7637_DUTYSET ); // Duty = 132 duty 0xb0
LCD_SendLCDData( 0x7F );
LCD_SendLCDCmd( 0x29 ); // Display ON
LCD_SendLCDCmd( 0xF9 ); // Gamma
LCD_SendLCDData( 0x00 ); //
LCD_SendLCDData( 0x03 ); //
LCD_SendLCDData( 0x05 ); //
LCD_SendLCDData( 0x07 ); //
LCD_SendLCDData( 0x09 ); //
LCD_SendLCDData( 0x0B ); //
LCD_SendLCDData( 0x0D ); //
LCD_SendLCDData( 0x0F ); //
LCD_SendLCDData( 0x11 ); //
LCD_SendLCDData( 0x13 ); //
LCD_SendLCDData( 0x15 ); //
LCD_SendLCDData( 0x17 ); //
LCD_SendLCDData( 0x19 ); //
LCD_SendLCDData( 0x1B ); //
LCD_SendLCDData( 0x1D ); //
LCD_SendLCDData( 0x1F ); //
}
/*******************************************************************************
*
* LCD_BackLightConfig
*
*******************************************************************************/
/**
* Setting of the PWM that drives the backlight intensity.
*
**/
/******************************************************************************/
static void LCD_BackLightConfig( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOB clock */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
/* GPIOB Configuration:TIM4 2 in Output */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOB, &GPIO_InitStructure );
/* TIM4 Configuration -----------------------------------------------------*/
/* TIM4CLK = 12 MHz, Prescaler = 0x0 */
/* Enable TIM4 clock */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE );
TIM_DeInit( TIM4 );
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
TIM_OCStructInit( &TIM_OCInitStructure );
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM4, &TIM_TimeBaseStructure );
/* Output Compare Toggle Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_Channel = TIM_Channel_2;
TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
TIM_OCInit( TIM4, &TIM_OCInitStructure );
TIM_OC4PreloadConfig( TIM4, TIM_OCPreload_Disable );
TIM_ARRPreloadConfig( TIM4, ENABLE );
/* Enable TIM4 IT */
TIM_ITConfig( TIM4, TIM_IT_CC2, ENABLE );
// Go !!!
TIM_Cmd( TIM4, ENABLE );
}
/*******************************************************************************
*
* LCD_BackLightChange
*
*******************************************************************************/
/**
* Modify the PWM rate.
*
**/
/******************************************************************************/
static void LCD_BackLightChange( void )
{
/* Output Compare Toggle Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
TIM_OCInit( TIM4, &TIM_OCInitStructure );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -