📄 bu2872.c
字号:
/*====================================================================
*
* Copyright (C) 1997 Acer Labs, Inc. All Rights Reserved.
*
* File: BU2872.c
*
* Contents: BU2872 VFD chip control
*
* History:
* Date By Reason
* =========== ========= ======
* 19-May-1999 Charlemage for timing/ack process
* 23-Aug-2001 Dick Ma Porting to M3325
********************************************************************/
#include <gpio.h>
#include <sci.h>
#include <platform.h>
/*** define the display setting ***/
#if VFD_DISP_MODE == 0x00
#define VFD_SEG_NUM 16
#define VFD_GRID_NUM 4
#elif VFD_DISP_MODE == 0x01
#define VFD_SEG_NUM 16
#define VFD_GRID_NUM 5
#elif VFD_DISP_MODE == 0x02
#define VFD_SEG_NUM 16
#define VFD_GRID_NUM 6
#elif VFD_DISP_MODE == 0x03
#define VFD_SEG_NUM 15
#define VFD_GRID_NUM 7
#elif VFD_DISP_MODE == 0x04
#define VFD_SEG_NUM 14
#define VFD_GRID_NUM 8
#elif VFD_DISP_MODE == 0x05
#define VFD_SEG_NUM 13
#define VFD_GRID_NUM 9
#elif VFD_DISP_MODE == 0x06
#define VFD_SEG_NUM 12
#define VFD_GRID_NUM 10
#elif VFD_DISP_MODE == 0x07
#define VFD_SEG_NUM 11
#define VFD_GRID_NUM 11
#endif
/*----------------------------------------------------------------------
* Function_Name: VfdHold
*
* Description: Hold Vfd Chip, pull VFD Strobe hi
*
* Arguments:
* DWORD* dwBuff - DisplayBuffer to set
* Return Value: void
*----------------------------------------------------------------------*/
void VfdHold()
{
/*WaitSem(SCI_semid);*/
dis_dsp();
SET_GPIO_W(SCI_MD | SCI_MC | SCI_VFD);/* SCI_MD write mode */
SET_GPIO_HI(SCI_MD | SCI_MC | SCI_VFD);/* pull SCI_MD high */
}
/*----------------------------------------------------------------------
* Function_Name: VfdRelease
*
* Description: Release Vfd Chip, pull VFD Strobe low
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdRelease()
{
SciDelay(20);/* Delay >13.3us */
SET_GPIO_W(SCI_MD | SCI_MC | SCI_VFD);/* SCI_MD write mode */
SET_GPIO_HI(SCI_MD | SCI_MC );/* pull SCI_MC,SCI_MD high */
SET_GPIO_LOW(SCI_VFD);/* pull SCI_MD low */
/*SigSem(SCI_semid);*/
ena_dsp();
dly_tsk(1);/* wait for task dispatch */
}
/*----------------------------------------------------------------------
* Function_Name: VfdCommand
*
* Description: Send command to VFD controller
*
* Arguments:
* BYTE bCMD : VFD command
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdCommand(BYTE cmd)
{
VfdHold();
SciSetByteMF(cmd);
VfdRelease();
}
/*----------------------------------------------------------------------
* Function_Name: VfdDisplayOn
*
* Description: Turn On the VFD Screen
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdDisplayOn()
{
/* Command: control display-dimming quantily */
VfdCommand((BYTE)((DIMMING_RATE << 4) | VFD_DISP_MODE) | 0x08);
}
/*----------------------------------------------------------------------
* Function_Name: VfdDisplayOff
*
* Description: Turn Off the VFD Screen
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdDisplayOff()
{
/* Command: control display-dimming quantily */
VfdCommand((BYTE)((DIMMING_RATE << 4) | VFD_DISP_MODE));
}
/*----------------------------------------------------------------------
* Function_Name: VfdCls
*
* Description: Initialize the Vfd RAMs that we can use them latter.
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdCls()
{
int i;
VfdDisplayOff();
for(i=1;i<=VFD_GRID_NUM;i++)/* Clear VFD RAMs */
{
VfdSetGrid(i,0x00000000);
}
VfdDisplayOn();
}
/*----------------------------------------------------------------------
* Function_Name: VfdGetSw
*
* Description:
*
* Arguments:
*
* Return Value:
* BYTE - Lower 4 bits are the status of the 4 SW.
* bit0: SW1 ~ bit3: SW4
*----------------------------------------------------------------------*/
BYTE VfdGetSw()
{
BYTE bRet;
VfdHold();
/* Command : set SW input mode */
SciSetByteMF(0xb0);
SciDelay(80);
bRet=SciGetByteMF();
VfdRelease();
return (bRet&0x0f);
}
/*----------------------------------------------------------------------
* Function_Name: VfdSetLed
*
* Description: Set value of 4 LEDs
*
* Arguments:
* BYTE bLEDs - 4 LED status , 1 as light.
* Lower 4 bits are the status of the 4 LED.
* bit0: LED1 ~ bit3: LED4
* Return Value: void
*----------------------------------------------------------------------*/
void VfdSetLed(BYTE bLEDs)
{
/* Command : set LED mode, Lower 4 bits are the status of the 4 LED. */
VfdCommand((bLEDs&0x0f)|0x90);
}
/*----------------------------------------------------------------------
* Function_Name: VfdSetGrid
*
* Description: Set one grid of VFD display Data
*
* Arguments:
* BYTE bGrid: grid offset (from 1 to 11)
* DWORD dwData: DATA to display RAM, (ignore higher 2 bytes)
* Return Value: void
*----------------------------------------------------------------------*/
void VfdSetGrid(BYTE bGrid,DWORD dwData)
{
VfdHold();
/* Command : set write display data to RAM mode */
SciSetByteMF(bGrid|0x80);
SciDelay(80);/* Delay >40us */
SciSetByteMF(BYTE1(dwData));
SciDelay(80);/* Delay >40us */
SciSetByteMF(BYTE0(dwData));
VfdRelease();
}
#if 0
/*----------------------------------------------------------------------
* Function_Name: VfdSelfTest
*
* Description: Customer use this function to build the panel header.
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdSelfTest()
{
int i;
BYTE b, bGrid;
DWORD dw;
DWORD LightTable[VFD_GRID_NUM+1];
DWORD BlinkTable[VFD_GRID_NUM+1];
#if 1
/******************************/
/* Light VFD */
/******************************/
PRINTF("\nLight VFD\n");
for (bGrid = 1; bGrid <= VFD_GRID_NUM; bGrid++)
{
LightTable[bGrid] = 0xffffffff;
BlinkTable[bGrid] = 0x00000000;
}
/* Light ALL */
VfdUpdate(LightTable);
dly_tsk(300);
/* Blink 3 times */
for(i=0;i<3;i++)
{
VfdUpdate(BlinkTable);
dly_tsk(100);
VfdUpdate(LightTable);
dly_tsk(200);
}
/* Off one bit each time */
for (bGrid = 1; bGrid <= VFD_GRID_NUM; bGrid ++)
{
for (b = 0; b < VFD_SEG_NUM; b++)
{
LightTable[bGrid] &= ~(0x00000001 << b);/* turn off one element */
VfdSetGrid(bGrid, LightTable[bGrid]);
dly_tsk(100);
LightTable[bGrid] = 0xffffffff;
}
VfdSetGrid(bGrid, LightTable[bGrid]);
}
/* Light ALL */
VfdUpdate(LightTable);
dly_tsk(300);
#endif
#if 1
/******************************/
/* Light LED */
/******************************/
PRINTF("\nLight LED\n");
/* Light ALL LED */
VfdSetLed(0xff);
/* Light one LED */
dly_tsk(300);
for(b=0;b<5;b++)
{
VfdSetLed(0x01 << b);
dly_tsk(200);
}
/* Light ALL LED */
VfdSetLed(0xff);
#endif
#if 1
/******************************/
/* Check Key and SW input */
/******************************/
PRINTF("\nCheck Key and SW input\n");
while(1)
{
// b = VfdGetSw();
// if(b)
// {
// PRINTF("\nFind SW input! %x\n", b);
// }
dw = VfdGetKeys();
if(dw)
{
PRINTF("\nFind Key input! %x\n", dw);
}
}
#endif
}
#endif
/*----------------------------------------------------------------------
* Function_Name: VfdInit
*
* Description: Initialize the Vfd Chip
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdInit()
{
/* Disable STB, this chip is high active!! */
SET_GPIO_W(SCI_VFD);
SET_GPIO_LOW(SCI_VFD);
VfdSetLed(0x00);
VfdCls();
}
/*----------------------------------------------------------------------
* Function_Name: VfdUpdate
*
* Description: Update whole VFD screen
*
* Arguments:
* DWORD* dwBuff - DisplayBuffer to set
* Return Value: void
*----------------------------------------------------------------------*/
void VfdUpdate(DWORD *dwBuff)
{
int i;
for(i=1,dwBuff++;i<=VFD_GRID_NUM;i++,dwBuff++)
{
VfdSetGrid(i,*dwBuff);
}
}
/*----------------------------------------------------------------------
* Function_Name: VfdGetKeys
*
* Description:
*
* Arguments:
*
* Return Value:
* DWORD - key-map of 32 keys. (This chip should have 48 keys at most!)
*----------------------------------------------------------------------*/
DWORD VfdGetKeys()
{
DWORD dwRet;
VfdHold();
/* Command : set Keys input mode */
SciSetByteMF(0xa0);
SciDelay(80);/* Delay >40us */
BYTE3(dwRet)=SciGetByteMF();
SciDelay(80);/* Delay >40us */
BYTE2(dwRet)=SciGetByteMF();
SciDelay(80);/* Delay >40us */
BYTE1(dwRet)=SciGetByteMF();
BYTE0(dwRet)=0;
VfdRelease();
return dwRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -