?? zlg7289.c
字號:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: Zlg7289.c
** Last modified Date: 2008/07/29
** Last Version: V1.10
** Description: 數碼管顯示與鍵盤管理芯片ZLG7289的驅動程序
**
**--------------------------------------------------------------------------------------------------------
** Created By: 廖茂剛
** Created date: 2008/01/03
** Version: V1.00
** Descriptions:
**
**--------------------------------------------------------------------------------------------------------
** Modified by: 周小明
** Modified date: 2008/07/29
** Version: V1.10
** Description:
**
*********************************************************************************************************/
#include "LCD_KEY.h"
// 延時N個微秒
void __delayNuS (int32 iTime)
{
iTime = SysCtlClockGet() * iTime / 2000000; // 根據系統時鐘速率確定延時
while (--iTime != 0);
}
// 向SPI 總線寫入1 個字節的數據。
void __zlg7289SPIWrite (int8 cDat)
{
int8 cT = 8;
GPIOPinTypeOut( LCD_KEY_PORT , LCD_KEY_DIO); // 設置DIO端口為輸出模式
do
{ // 循環寫一個字節的數據
if((cDat & 0x80) == 0x80)
{
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_DIO, 0xff);
}
else
{
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_DIO, 0x00);
}
cDat <<= 1;
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CLK, 0xff);
__delayNuS(5);
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CLK, 0x00);
__delayNuS(5);
} while (--cT != 0);
}
// 從SPI 總線讀取1 個字節的數據
int8 __zlg7289SPIRead (void)
{
int8 cDat = 0;
int8 cT = 8;
GPIOPinTypeIn( LCD_KEY_PORT, LCD_KEY_DIO); // 設置DIO端口為輸出模式
do
{ // 循環讀一個字節的數據
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CLK, 0xff);
__delayNuS(5);
cDat <<= 1;
if (GPIOPinRead( LCD_KEY_PORT , LCD_KEY_DIO))
{
cDat++;
}
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CLK, 0x00);
__delayNuS(5);
} while (--cT != 0);
return (cDat);
}
// 執行ZLG7289 純指令。
void zlg7289Cmd (int8 cCmd)
{
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0x00);
__delayNuS(25);
__zlg7289SPIWrite(cCmd);
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0xff);
__delayNuS(5);
}
// 執行ZLG7289 帶數據指令。
void zlg7289CmdDat (uint8 cCmd, int8 cDat)
{
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0x00);
__delayNuS(25);
__zlg7289SPIWrite(cCmd);
__delayNuS(15);
__zlg7289SPIWrite(cDat);
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0xff);
__delayNuS(5);
}
// 下載數據。
// ucMod=0: 下載數據且按方式0 譯碼
// ucMod=1: 下載數據且按方式1 譯碼
// ucMod=2: 下載數據但不譯碼
// cX: 數碼管編號(橫坐標),取值0~7
// cDp=0: 小數點不亮
// cDp=1: 小數點亮
// cDat: 要顯示的數據
void zlg7289Download (uint8 ucMod, int8 cX, int8 cDp, int8 cDat)
{
uint8 ucModDat[3] = {0x80,0xC8,0x90};
uint8 ucD1;
uint8 ucD2;
if (ucMod > 2)
{
ucMod = 2;
}
ucD1 = ucModDat[ucMod];
cX &= 0x07;
ucD1 |= cX;
ucD2 = cDat & 0x7F;
if (cDp == 1)
{
ucD2 |= 0x80;
}
zlg7289CmdDat(ucD1, ucD2);
}
// 執行ZLG7289 鍵盤命令。
// 返回讀到的按鍵值:0~63。如果返回0xFF 則表示沒有鍵按下
int8 zlg7289Key (void)
{
int8 cKey;
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0x00);
__delayNuS(25);
__zlg7289SPIWrite(0x15);
__delayNuS(15);
cKey = __zlg7289SPIRead();
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS, 0xff);
__delayNuS(5);
return (cKey);
}
// ZLG7289 初始化
void zlg7289Init (void)
{
SysCtlPeripheralEnable( LCD_KEY_PERIPH ); // 使能GPIO B口外設
GPIOPinTypeOut( LCD_KEY_PORT , LCD_KEY_CS |LCD_KEY_CLK |LCD_KEY_DIO);
// 設置I/O口為輸出模式
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_DIO, 0xff);
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CLK, 0x00);
GPIOPinWrite( LCD_KEY_PORT , LCD_KEY_CS , 0xff);
zlg7289Reset(); // 復位ZLG7289
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -