/**************************************************************************************************
 * @fn      HalLcdWriteData to the LCD
 *
 * @brief   Write a data to the LCD
 *
 * @param  data-the data to be wrote
 *
 *
 * @return  None
 **************************************************************************************************/
void HalLcd_HW_WriteData(uint8 data)
{
    uint8 i = 0;
    LCD_CS = 0; // to select the LCD
    HalLcd_HW_WaitUs(1);
    LCD_RS = 1;// write data
    HalLcd_HW_WaitUs(1);
    for(i = 0; i < 8; i++)
    {
        LCD_CLK = 0;
        asm("nop");// a delay for waiting the peripheral
        // HalLcd_HW_WaitUs(1);
        if(data & 0x80)
        {
            LCD_DI = 1;
        }
        else
        {
            LCD_DI = 0;
        }
        asm("nop");// a delay to set the data
        asm("nop");
        //HalLcd_HW_WaitUs(1);
        data = data << 1;
        LCD_CLK = 1;
        // HalLcd_HW_WaitUs(1);
        asm("nop");// a delay to hold the data
        asm("nop");
    }
    LCD_CS = 1;//
    //
}
예제 #2
0
파일: hal_lcd.c 프로젝트: billy-wang/IOT
/**************************************************************************************************
 * @fn      HalLcd_HW_Init
 *
 * @brief   Initilize HW LCD Driver.
 *
 * @param   None
 *
 * @return  None
 **************************************************************************************************/
void HalLcd_HW_Init(void)
{
  /* Initialize LCD IO lines */
  halLcd_ConfigIO();

  /* Initialize SPI */
  halLcd_ConfigSPI();

  /* Perform reset */
  LCD_ACTIVATE_RESET();
  HalLcd_HW_WaitUs(15000); // 15 ms
  LCD_RELEASE_RESET();
  HalLcd_HW_WaitUs(15); // 15 us

  /* Perform the initialization sequence */
  FUNCTION_SET(CGRAM | COM_FORWARD | THREE_LINE);

  /* Set contrast */
  HalLcd_HW_SetContrast(15);

  /* Set power */
  SET_POWER_SAVE_MODE(OSC_OFF | POWER_SAVE_ON);
  SET_POWER_CTRL(VOLTAGE_DIVIDER_ON | CONVERTER_AND_REG_ON);
  SET_BIAS_CTRL(BIAS_1_5);
  HalLcd_HW_WaitUs(21000);// 21 ms

  /* Clear the display */
  HalLcd_HW_Clear();
  HalLcd_HW_ClearAllSpecChars();
  SET_DISPLAY_CTRL(DISPLAY_CTRL_ON | DISPLAY_CTRL_BLINK_OFF | DISPLAY_CTRL_CURSOR_OFF);
}
/**************************************************************************************************
 * @fn      HalLcdWriteCommand to the LCD
 *
 * @brief   Write a command to the LCD
 *
 * @param  cmd-the command to be wrote
 *
 *
 * @return  None
 **************************************************************************************************/
void HalLcd_HW_WriteCommand(uint8 cmd)
{
    uint8 i = 0;
    LCD_CS = 0; // to select the LCD
    HalLcd_HW_WaitUs(1);
    LCD_RS = 0;// write the command
    HalLcd_HW_WaitUs(1);
    for(i = 0; i < 8; i++)
    {
        LCD_CLK = 0;
        asm("nop");// a delay for waiting the peripheral
        // HalLcd_HW_WaitUs(2);
        if(cmd & 0x80)
        {
            LCD_DI = 1;
        }
        else
        {
            LCD_DI = 0;
        }
        //asm("nop");// a delay to set the data
        // asm("nop");
        // HalLcd_HW_WaitUs(2);
        cmd = cmd << 1;
        LCD_CLK = 1;
        asm("nop");// a delay to hold the data
        asm("nop");
        HalLcd_HW_WaitUs(1);
    }
    LCD_CS = 1;

}
예제 #4
0
/*
作用    设置LCD 文本显示的其实行和列
参数1   line,范围:0~7,即能够显示的行为1~8行,也就是lcd手册里提到的page
参数2   col,范围:0~127,即lcd的总列数,显示的起始位置可以设置到每一列
*/
void set_ddram_line_col(uint8 line,uint8 col)
{

  uint8 page,coll,coll_l,coll_h;
  page = line;
  coll = col;
  coll_h = coll>>4;
  coll_l = coll&0x0f;
  HalLcd_HW_Control(0xB0+page);
  HalLcd_HW_WaitUs(15); // 15 us
  HalLcd_HW_Control(0x10+coll_h);
  HalLcd_HW_WaitUs(15); // 15 us
  HalLcd_HW_Control(0x00+coll_l);
  HalLcd_HW_WaitUs(15); // 15 us
}
예제 #5
0
/*********************************************************************
 * 函数名称:HalLcd_HW_Init
 * 功    能:LCD硬件初始化
 * 入口参数:无
 * 出口参数:无
 * 返 回 值:无
 ********************************************************************/
void HalLcd_HW_Init(void)
{
  halLcd_ConfigIO(); // 初始化LCD IO口
  halLcd_ConfigSPI();// 初始化 SPI 口

  /* 复位LCD */
  LCD_ACTIVATE_RESET();
  HalLcd_HW_WaitUs(8000);
  LCD_RELEASE_RESET();
  HalLcd_HW_WaitUs(30000); 
  HalLcd_HW_WaitUs(30000); 

  HalLcd_HW_SetBackLight(0); // 设置背光强度
  HalLcd_HW_Clear();         // 清屏
  HalLcd_HW_SetBackLight(100);
	
  HalLcd_HW_FontCharSet(0,1);// 字体设置
  HalLcd_HW_FontMode(1,0);
}
void HalLcdInit(void)
{
#if (HAL_LCD == TRUE)
    /*config the I/O---------------by Zimuge*/
    P1SEL &= ~(BV(3) + BV(5) + BV(6) + BV(7));
    P1DIR |= (BV(3) + BV(5) + BV(6) + BV(7));
    P2SEL &= ~BV(0);
    P2DIR |= BV(0);
    LEDD = 0; //open the backlight
    HalLcd_HW_WriteCommand(0xE2);// software rest
    HalLcd_HW_WaitUs(2);

    HalLcd_HW_WriteCommand(0x2C);// open the boost circuit
    HalLcd_HW_WaitUs(2);
    HalLcd_HW_WriteCommand(0x2E);// open the voltage management circuit
    HalLcd_HW_WaitUs(2);
    HalLcd_HW_WriteCommand(0x2F);// open the voltage follower
    HalLcd_HW_WaitUs(2);

    HalLcd_HW_WriteCommand(0x24);// select the contrast roughly
    HalLcd_HW_WriteCommand(0x81);// select the contrast smoothly
    HalLcd_HW_WriteCommand(0x12);
    HalLcd_HW_WriteCommand(0xA2);// select the bias voltage radio 1/9

    HalLcd_HW_WriteCommand(0xC8);// scan the LCD from top to bottom

    HalLcd_HW_WriteCommand(0xA0);// the address will automatically increase one by one

    HalLcd_HW_WriteCommand(0x40);// select the begining of the column to display the char

    HalLcd_HW_WriteCommand(0xAF);// open the lcd

    // HalLcd_HW_WriteCommand(0xA5);
    HalLcd_HW_Clear();
    LoadBackground();

#endif
}
예제 #7
0
/**************************************************************************************************
初始化,已根据lcd12864手册更改
 **************************************************************************************************/
void HalLcd_HW_Init(void)
{
  /* Initialize LCD IO lines */
  halLcd_ConfigIO();

  /* Initialize SPI */
  halLcd_ConfigSPI();

	HalLcd_HW_Control(0xe2);	//软复位
	HalLcd_HW_WaitUs(15000); // 15 us
	HalLcd_HW_Control(0x2c);	//升压步聚1
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0x2e);	//升压步聚2
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0x2f);	//升压步聚3
	HalLcd_HW_WaitUs(150); // 15 us
	HalLcd_HW_Control(0x23);	//粗调对比度,可设置范围0x20~0x27
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0x81);	//微调对比度
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0x28);	//0x1a,微调对比度的值,可设置范围0x00~0x3f
	HalLcd_HW_WaitUs(15); // 15 us
	
	HalLcd_HW_Control(0xa2);	// 1/9偏压比(bias)
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0xa0);	//行扫描顺序:从上到下
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0xc8);	//列扫描顺序:从左到右
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0x40);	//起始行:第一行开始
	HalLcd_HW_WaitUs(15); // 15 us
	HalLcd_HW_Control(0xaf);	//打开显示
	HalLcd_HW_WaitUs(15); // 15 us
    HalLcd_HW_Control(0xa4);	
	HalLcd_HW_WaitUs(15); // 15 us
        
	HalLcd_HW_Clear();
        //display_string_5x7(1,1,"abcdefghijklmnopqrstuvwxyz");
        //display_string_5x7(8,1,"uvwxyz0123456789");
        //while(1);


}