/************************************************************************************************** z-stack代码,SPI总线写数据 **************************************************************************************************/ void HalLcd_HW_Write(uint8 data) { #ifdef CC2530DK_V1 //do nothiing #else //保存原来MISO引脚的设置,方向和功能选择 uint8 dir = P1DIR; uint8 sel = P1SEL; /* 0为input 1为output 这里要设为输出,控制lcd的A0(命令或数据选择) */ P1DIR |=BV(7); /* 0为GPIO,1为外设, 这里用到的是MISO引脚的GPIO功能, 因此相应引脚设为0? */ P1SEL &=~(BV(7)); #endif LCD_SPI_BEGIN(); LCD_DO_WRITE(); LCD_SPI_TX(data); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); #ifdef CC2530DK_V1 //do nothiing #else P1DIR =dir; P1SEL =sel; #endif }
/******************************************************************** * 函数名称:HalLcd_HW_SetBackLight * 功 能:设置背光亮度等级 * 入口参数:Deg 亮度等级0~127 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_SetBackLight(unsigned char Deg) { LCD_SPI_BEGIN(); FUNCTION_SET(0x8A); //传送指令0x8A FUNCTION_SET(Deg); //背光设置亮度值 LCD_SPI_END(); }
/************************************************************************************************** z-stack代码,SPI总线写命令 **************************************************************************************************/ void HalLcd_HW_Control(uint8 cmd) { #ifdef CC2530DK_V1 //do nothiing #else //保存原来MISO引脚的设置 uint8 dir = P1DIR; uint8 sel = P1SEL; P1DIR |=BV(7); /* 0为GPIO,1为外设, 这里用到的是MISO引脚的GPIO功能, 因此相应引脚设为0? */ P1SEL &=~(BV(7)); #endif LCD_SPI_BEGIN(); LCD_DO_CONTROL(); LCD_SPI_TX(cmd); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); #ifdef CC2530DK_V1 //do nothiing #else P1DIR =dir; P1SEL =sel; #endif }
/********************************************************************* * 函数名称:HalLcd_HW_Clear * 功 能:LCD硬件清屏 * 入口参数:无 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_Clear(void) { //清屏操作 LCD_SPI_BEGIN(); //SS置低电平 FUNCTION_SET(0x80); //送指令0x80 LCD_SPI_END(); //完成操作置SS高电平 }
/********************************************************************* * 函数名称:HalLcd_HW_Control * 功 能:LCD硬件写入控制 * 入口参数:cmd 写入的命令或者数据 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_Control(unsigned char cmd) { LCD_SPI_BEGIN(); LCD_SPI_TX(cmd); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/************************************************************************************************** * @fn HalLcd_HW_Write * * @brief Write 1 byte to the LCD * * @param uint8 data - data to be written to the LCD * * @return None **************************************************************************************************/ void HalLcd_HW_Write(uint8 data) { LCD_SPI_BEGIN(); LCD_DO_WRITE(); LCD_SPI_TX(data); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/************************************************************************************************** * @fn HalLcd_HW_Control * * @brief Write 1 command to the LCD * * @param uint8 cmd - command to be written to the LCD * * @return None **************************************************************************************************/ void HalLcd_HW_Control(uint8 cmd) { LCD_SPI_BEGIN(); LCD_DO_CONTROL(); LCD_SPI_TX(cmd); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/*********************************************************************************** * @fn lcdWrite * * @brief Write character to display * * @param uint8 data - character to display * * @return none */ static void lcdWrite(uint8 data) { LCD_SPI_BEGIN(); LCD_DO_WRITE(); LCD_SPI_TX(data); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/*********************************************************************************** * @fn lcdControl * * @brief Send command to display * * @param uint8 command * * @return none */ static void lcdControl(uint8 command) { LCD_SPI_BEGIN(); LCD_DO_CONTROL(); LCD_SPI_TX(command); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/*********************************************************************************** * @fn lcdWrite * * @brief Write character to display * * @param uint8 ch - character to display * * @return none */ static void lcdWrite(uint8 ch) { P1_2 = 0; //LCD_SPI_BEGIN(); LCD_DO_WRITE(); LCD_SPI_TX(ch); LCD_SPI_WAIT_RXRDY(); LCD_SPI_END(); }
/********************************************************************* * 函数名称:HalLcd_HW_Write * 功 能:在x y 地址上写入数据 * 入口参数:x x地址 * y y地址 * a 写入的数据 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_Write(unsigned char x,unsigned char y,unsigned char a) { LCD_SPI_BEGIN(); //SS置低电平 FUNCTION_SET(0x07); //传送指令0x07 FUNCTION_SET(x); //要显示字符的左上角的X轴位置 FUNCTION_SET(y); //要显示字符的左上角的Y轴位置 FUNCTION_SET(a); //要显示字符ASCII字符的ASCII码值 LCD_SPI_END(); //完成操作置SS高电平 }
/*********************************************************************************** * @fn lcdWriteMany * * @brief Write text to display * * @param char *pData - text buffer * uint16 count - number of bytes * * @return none */ static void lcdWriteMany(const char *pData, uint16 count) { LCD_SPI_BEGIN(); LCD_DO_WRITE(); while (count--) { LCD_SPI_TX(*(pData++)); LCD_SPI_WAIT_RXRDY(); } LCD_SPI_END(); }
/********************************************************************* * 函数名称:HalLcd_HW_FontMode * 功 能:设置字符显示覆盖模式 * 入口参数:Cover 字符覆盖模式设置,0或1 * Color 覆盖模式为1时字符显示时的背景覆盖色 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_FontMode(unsigned char Cover,unsigned char Color) { unsigned char ucTemp=0; ucTemp = (Cover<<4)|Color; LCD_SPI_BEGIN(); //SS置低电平 FUNCTION_SET(0x89); //传送指令0x89 FUNCTION_SET(ucTemp); //发送设置值 LCD_SPI_END(); //完成操作置SS高电平 }
/********************************************************************* * 函数名称:HalLcd_HW_FontCharSet * 功 能:ASCII字符字体设置 * 入口参数:Font_NUM 字体选择,以驱动所带的字库为准 * Color 文本颜色,仅作用于ASCII字库 * 出口参数:无 * 返 回 值:无 ********************************************************************/ void HalLcd_HW_FontCharSet(unsigned char Font_NUM,unsigned char Color) { unsigned char ucTemp = 0; ucTemp = (Font_NUM<<4)|Color; LCD_SPI_BEGIN(); //SS置低电平 FUNCTION_SET(0x81); //传送指令0x81 FUNCTION_SET(ucTemp); //选择6X10的ASCII字体,字符色为黑色 LCD_SPI_END(); //完成操作置SS高电平 }
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 /* 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_Wait(20);// 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); }