⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_lcd.c

📁 Zigbee2007.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
#endif
}

/**************************************************************************************************
 * @fn      HalLcdWriteStringValue
 *
 * @brief   Write a string followed by a value to the LCD
 *
 * @param   title  - Title that will be displayed before the value
 *          value  - value
 *          format - redix
 *          line   - line number
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteStringValue( char *title, uint16 value, uint8 format, uint8 line )
{
#if (HAL_LCD == TRUE)
  uint8 tmpLen;
  uint8 buf[LCD_MAX_BUF];
  uint32 err;

  tmpLen = (uint8)osal_strlen( (char*)title );
  osal_memcpy( buf, title, tmpLen );
  buf[tmpLen] = ' ';
  err = (uint32)(value);
  _ltoa( err, &buf[tmpLen+1], format );
  HalLcdWriteString( (char*)buf, line );		
#endif
}

/**************************************************************************************************
 * @fn      HalLcdWriteStringValue
 *
 * @brief   Write a string followed by a value to the LCD
 *
 * @param   title   - Title that will be displayed before the value
 *          value1  - value #1
 *          format1 - redix of value #1
 *          value2  - value #2
 *          format2 - redix of value #2
 *          line    - line number
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteStringValueValue( char *title, uint16 value1, uint8 format1,
                                  uint16 value2, byte format2, uint8 line )
{

#if (HAL_LCD == TRUE)

  uint8 tmpLen;
  uint8 buf[LCD_MAX_BUF];
  uint32 err;

  tmpLen = (uint8)osal_strlen( (char*)title );
  if ( tmpLen )
  {
    osal_memcpy( buf, title, tmpLen );
    buf[tmpLen++] = ' ';
  }

  err = (uint32)(value1);
  _ltoa( err, &buf[tmpLen], format1 );
  tmpLen = (uint8)osal_strlen( (char*)buf );

  buf[tmpLen++] = ',';
  buf[tmpLen++] = ' ';
  err = (uint32)(value2);
  _ltoa( err, &buf[tmpLen], format2 );

  HalLcdWriteString( (char *)buf, line );		

#endif
}

/**************************************************************************************************
 * @fn      HalLcdDisplayPercentBar
 *
 * @brief   Display percentage bar on the LCD
 *
 * @param   title   -
 *          value   -
 *
 * @return  None
 **************************************************************************************************/
void HalLcdDisplayPercentBar( char *title, uint8 value )
{
#if (HAL_LCD == TRUE)

  uint8 percent;
  uint8 leftOver;
  uint8 buf[17];
  uint32 err;
  uint8 x;

  /* Write the title: */
  HalLcdWriteString( title, HAL_LCD_LINE_1 );

  if ( value > 100 )
    value = 100;

  /* convert to blocks */
  percent = (byte)(value / 10);
  leftOver = (byte)(value % 10);

  /* Make window */
  osal_memcpy( buf, "[          ]  ", 15 );

  for ( x = 0; x < percent; x ++ )
  {
    buf[1+x] = '>';
  }

  if ( leftOver >= 5 )
    buf[1+x] = '+';

  err = (uint32)value;
  _ltoa( err, (uint8*)&buf[13], 10 );

  HalLcdWriteString( (char*)buf, HAL_LCD_LINE_2 );

#endif

}

/**************************************************************************************************
 *                                    HARDWARE LCD
 **************************************************************************************************/

/**************************************************************************************************
 * @fn      HalLcd_HW_Init
 *
 * @brief   Initilize HW LCD Driver.
 *
 * @param   None
 *
 * @return  None
 **************************************************************************************************/
#if (HAL_LCD == TRUE)

void HalLcd_HW_Init(void)
{
  /* Initialize SPI */
  UCB0CTL1 |= UCSWRST;
  UCB0CTL0 |= UCMST | UCSYNC | UCCKPH | UCMSB;   /* MSB, Master mode, Sync mode, Data capture on the first UCLK edge */
  UCB0CTL1 |= UCSSEL1;                           /* SMCLK */
  UCB0BR0  = 4;
  UCB0BR1  = 0;
  LCD_SPI_INIT_PORTS();
  LCD_SPI_END();
  UCB0CTL1 &= ~UCSWRST;

  /* Init I/O */
  LCD_CTRL_INIT_PORTS();

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

  Lcdwritecom(0xAE);
  Lcdwritecom(0xAD);	//dc-dc off
  Lcdwritecom(0x8a);
  HalLcd_HW_Wait(15); // 15 ms
  Lcdwritecom(0x00);
  Lcdwritecom(0x10);
  Lcdwritecom(0x40);
  Lcdwritecom(0x81);
  Lcdwritecom(ContrastValue);
  Lcdwritecom(0xA0);
  Lcdwritecom(0xA4);
  Lcdwritecom(0xA6);
  Lcdwritecom(0xA8);
  Lcdwritecom(0x3f);
  Lcdwritecom(0xD3);
  Lcdwritecom(0x00);
  Lcdwritecom(0xD5);
  Lcdwritecom(0x20);
  Lcdwritecom(0xD8);
  Lcdwritecom(0x00);
  Lcdwritecom(0xDA);
  Lcdwritecom(0x12);
  Lcdwritecom(0xDB);
  Lcdwritecom(0x00);
  Lcdwritecom(0xD9);
  Lcdwritecom(0x22);
  Lcdwritecom(0xc8);
  Lcdwritecom(0xAF);
  ClearScreen();
}

/**************************************************************************************************
 * @fn      void Lcdwritecom(uint8 cmd)
 *
 * @brief   Write 1 command to the LCD
 *
 * @param   uint8 cmd - command to be written to the LCD
 *
 * @return  None
 **************************************************************************************************/
void Lcdwritecom(uint8 cmd)
{
  LCD_SPI_BEGIN();
  LCD_DO_CONTROL();
  LCD_SPI_TX(cmd);
  LCD_SPI_WAIT_RXRDY();
  LCD_SPI_END();
}

/**************************************************************************************************
 * @fn      void Lcdwritedata(uint8 data)
 *
 * @brief   Write 1 byte to the LCD
 *
 * @param   uint8 data - data to be written to the LCD
 *
 * @return  None
 **************************************************************************************************/
void Lcdwritedata(uint8 data)
{
  LCD_SPI_BEGIN();
  LCD_DO_WRITE();
  LCD_SPI_TX(data);
  LCD_SPI_WAIT_RXRDY();
  LCD_SPI_END();
}

/*******************************************************************************
//函数名:void SetRamAddr (INT8U Page, INT8U Col)
//功能:lcd位置选择
//输入:Page-页,Col-列
//输出:无
********************************************************************************/
void SetRamAddr (uint8 Page, uint8 Col)
{
	Lcdwritecom(0xB0 + Page);
	Lcdwritecom(Col & 0x0f); //Set lower column address
	Lcdwritecom(0x10 | ((Col & 0xf0) >> 4)); //Set higher column address		//低位
}

/*******************************************************************************
//函数名:void SetContrast(INT8U Gain, INT8U Step)
//功能:lcd对比度设定
//输入:Page-页,Col-列
//输出:无
********************************************************************************/
void SetContrast(uint8 Gain, uint8 Step)
{
	Lcdwritecom(0x81);
	Lcdwritecom(Step);
}
/*******************************************************************************
//函数名:void InitDisplay(void)
//功能:lcd设定为正常显示状态
//输入:无
//输出:无
********************************************************************************/
void InitDisplay(void)
{
	Lcdwritecom(DisplayOff);			//关显示
	Lcdwritecom(SegRemapOn);    			//ks0713/ssd1815
	Lcdwritecom(ComRemapOn);    			//ssd1815
	SetContrast(iIntRegValue, iContCtrlRegValue); 	//设定缺省对比度
	Lcdwritecom(PwrCtrlReg | IntVolBstr | IntReg | OPampBuffer); //turn on booster, regulator & divider
	Lcdwritecom(DisplayOn);				//开显示
}


/*******************************************************************************
//函数名:void contrastctrl(INT8U start,stop)
//功能:lcd对比度调整
//输入:无
//输出:无
********************************************************************************/
void contrastctrl(uint8 start, uint8 stop)
{
	uint8 i;
	if (start < stop)
	{
		for (i=start; i<stop; i+=1)
		{
			SetContrast(iIntRegValue, i); //slowly turn on display
			fdelay(80);
		}
	}
	else
	{
		for (i=start; i>stop; i-=1)
		{
			SetContrast(iIntRegValue, i); //slowly turn off display
			fdelay(120);
		}
	}
}


/*******************************************************************************
//函数名:void ClearScreen(void)
//功能:清屏
//输入:无
//输出:无
********************************************************************************/
void ClearScreen(void)
{
	uint8 i , j;
	
	for (i = 0 ; i < PageNo ; i++)
	{
		SetRamAddr(i,0);
		for (j=0;j<ColNo; j++) Lcdwritedata(0x00);
	}
}
/*******************************************************************************
//函数名:void fdelay(unsigned int n)
//功能:廷时
//输入:时间
//输出:无
********************************************************************************/
void fdelay(unsigned int n) /* wait n seconds*/
{
	uint16 i;
	uint16 j;
	for (i=0;i<5;i++)
	for (j=0;j<n*2;j++) ;
}

/**************************************************************************************************
 * @fn      HalLcd_HW_WriteChar
 *
 * @brief   Write one char to the display
 *
 * @param   uint8 line - line number that the char will be displayed
 *          uint8 col - colum where the char will be displayed
 *
 * @return  None
 **************************************************************************************************/
void HalLcd_HW_WriteChar(uint8 line, uint8 col, char text)
{
	uint8 ii = 0;
	unsigned int index = 0 ;
	if (col < LCD_MAX_LINE_LENGTH)
	{
		index = (unsigned int)(text - 0x20);
		index = (unsigned int)index*6;
		SetRamAddr(line, col*6);
		for(ii=0;ii<6;ii++)
		{
			Lcdwritedata(FontSystem6x8[index]);		
			index += 1;
		}
	}
	else
	{
		return;
	}
}

/**************************************************************************************************
 * @fn          halLcdWriteLine
 *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -