📄 upd16312.c
字号:
/*====================================================================
*
* Copyright (C) 1997 Acer Labs, Inc. All Rights Reserved.
*
* File: uPD16312.c
*
* Contents: uPD16312 VFD chip control
*
* History:
* Date By Reason
* =========== ========= ======
* 19-May-1999 Charlemage for timing/ack process
* 23-Aug-2001 Dick Ma Porting to M3325
* 28-Dec-2002 Dick Ma Porting to VDTR6312
********************************************************************/
#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
#elif VFD_DISP_MODE == 0x0a
#define VFD_SEG_NUM 24
#define VFD_GRID_NUM 6
#endif
/*----------------------------------------------------------------------
* Function_Name: VfdHold
*
* Description: Hold Vfd Chip, pull VFD Strobe low
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
static void VfdHold()
{
/*WaitSem(SCI_semid);*/
#ifdef DISDSPDISINT
dis_dsp();
#else
DisInt();
#endif
/************************M3325C_PLATFORM******************************/
/*************************M3351_PLATFORM******************************/
SET_GPIO_W(SCI_MD | SCI_MC | SCI_VFD);/* SCI_MD,SCI_MC,SCI_VFD write mode */
SET_GPIO_HI(SCI_MD | SCI_MC);/* pull SCI_MD,SCI_MC high */
SET_GPIO_LOW(SCI_VFD);/* pull SCI_VFD low */
/***************************M6303_PLATFORM*****************************/
/**********************************************************************/
}
/*----------------------------------------------------------------------
* Function_Name: VfdRelease
*
* Description: Release Vfd Chip, pull VFD Strobe high
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
static void VfdRelease()
{
SciDelay(2);/* wait 2 us, need wait 1 us */
/************************M3325C_PLATFORM******************************/
/*************************M3351_PLATFORM******************************/
SET_GPIO_W(SCI_MD | SCI_MC | SCI_VFD);/* SCI_MD,SCI_MC,SCI_VFD write mode */
SET_GPIO_HI(SCI_MD | SCI_MC | SCI_VFD);/* pull SCI_MD,SCI_MC,SCI_VFD high */
/***************************M6303_PLATFORM*****************************/
/**********************************************************************/
/*SigSem(SCI_semid);*/
#ifdef DISDSPDISINT
ena_dsp();
#else
EnInt();
#endif
dly_tsk(1);/* wait for task dispatch */
}
/*----------------------------------------------------------------------
* Function_Name: VfdCommand
*
* Description: Send command to VFD controller
*
* Arguments:
* BYTE bCMD : VFD command
*
* Return Value: void
*----------------------------------------------------------------------*/
static void VfdCommand(BYTE bCMD)
{
VfdHold();
SciSetByte(bCMD);
VfdRelease();
}
/*----------------------------------------------------------------------
* Function_Name: VfdDisplayOn
*
* Description: Turn On the VFD Screen
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdDisplayOn()
{
/* Command 4: control display-dimming quantily */
VfdCommand( (BYTE)(0x88 | DIMMING_RATE) );
}
/*----------------------------------------------------------------------
* Function_Name: VfdDisplayOff
*
* Description: Turn Off the VFD Screen
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdDisplayOff()
{
/* Command 4: control display-dimming quantily */
VfdCommand( (BYTE)(0x80 | DIMMING_RATE) );
}
/*----------------------------------------------------------------------
* Function_Name: VfdCls
*
* Description: Initialize the Vfd RAMs that we can use them latter.
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
static void VfdCls()
{
int i;
VfdDisplayOff();
/* Command 2: set data */
VfdCommand(0x40); /* Write to display memory, increments mode */
VfdHold();
/* Command 3: set address */
SciSetByte(0xC0); /* Set Address to 0 */
for(i=VFD_GRID_NUM*2;i>0;i--) /* Clear VFD RAMs */
{
SciSetByte(0x00);
}
VfdRelease();
VfdDisplayOn();
}
/*----------------------------------------------------------------------
* Function_Name: VfdGetSw
*
* Description:
*
* Arguments:
*
* Return Value:
* BYTE - Lower 4 bits are the status of the 4 SW.
*----------------------------------------------------------------------*/
BYTE VfdGetSw()
{
BYTE bRet;
VfdHold();
/* Command 2: set data */
SciSetByte(0x43); /* Get SW Command */
SciDelay(2);/* wait 2 us, need wait 1 us */
bRet = SciGetByte();
VfdRelease();
return bRet;
}
/*----------------------------------------------------------------------
* Function_Name: VfdSetLed
*
* Description: Set value of 5 LEDs
*
* Arguments:
* BYTE bLEDs - 4 LED status , 1 as light.
* Return Value: void
*----------------------------------------------------------------------*/
void VfdSetLed(BYTE bLEDs)
{
VfdHold();
SciSetByte(0x41); /* Write to LEDs command */
SciSetByte(~bLEDs);
VfdRelease();
}
/*----------------------------------------------------------------------
* Function_Name: VfdSetGrid
*
* Description: Set one grid of VFD display Data
*
* Arguments:
* BYTE bGrid: grid offset
* DWORD dwData: DATA to display RAM, (ignore higher 1 byte)
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdSetGrid(BYTE bGrid, DWORD dwData)
{
BYTE bAddr= (bGrid-1)*3;
/* Command 3: set address */
VfdCommand(0xC0 | bAddr); /* Set Address to Grid */
VfdHold();
SciSetByte(0x40); /* Write to display memory, inc mode */
SciSetByte(BYTE0(dwData));
SciSetByte(BYTE1(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 */
/******************************/
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(50);
VfdUpdate(LightTable);
dly_tsk(100);
}
/* 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(50);
LightTable[bGrid] = 0xffffffff;
}
VfdSetGrid(bGrid, LightTable[bGrid]);
}
/* Light ALL */
VfdUpdate(LightTable);
dly_tsk(300);
#endif
#if 1
/******************************/
/* Light LED */
/******************************/
/* Light ALL LED */
VfdSetLed(0xff);
/* Light one LED */
dly_tsk(300);
for(b=0;b<5;b++)
{
VfdSetLed(0x01 << b);
dly_tsk(50);
}
/* Light ALL LED */
VfdSetLed(0xff);
#endif
#if 1
/******************************/
/* Check Key and SW input */
/******************************/
while(1)
{
b = VfdGetSw();
if(b)
{
PRINTF("\nFind SW input! %x\n", b);
}
dw = VfdGetKeys();
if(dw)
{
PRINTF("\nFind Key input! %x\n", b);
}
}
#endif
}
#endif
/*----------------------------------------------------------------------
* Function_Name: VfdInit
*
* Description: Initialize the Vfd Chip
*
* Arguments:
*
* Return Value: void
*----------------------------------------------------------------------*/
void VfdInit()
{
/* /STB for VFD, this chip is low active!! */
SET_GPIO_W(SCI_VFD);
SET_GPIO_HI(SCI_VFD);
VfdCommand(VFD_DISP_MODE); /* Set # of Grid/Segment */
VfdCls();
VfdSetLed(0xff); /* turn off all LED */
}
/*----------------------------------------------------------------------
* Function_Name: VfdUpdate
*
* Description: Update whole VFD screen
*
* Arguments:
* DWORD* dwBuff - Display Buffer to set
* Return Value: void
*----------------------------------------------------------------------*/
void VfdUpdate(DWORD *dwBuff)
{
int i;
/* Command 2: set data */
VfdCommand(0x40); /* Write to display memory, increments mode */
VfdHold();
/* Command 3: set address */
SciSetByte(0xC0); /* Set Address to 0 */
for(i=0,dwBuff++;i<VFD_GRID_NUM;i++,dwBuff++)
{
SciSetByte(BYTE0(*dwBuff));
SciSetByte(BYTE1(*dwBuff));
}
VfdRelease();
}
/*----------------------------------------------------------------------
* Function_Name: VfdGetKeys
*
* Description:
*
* Arguments:
*
* Return Value:
* DWORD - key-map of 24 keys. (This chip should have only 24 keys at most!)
*----------------------------------------------------------------------*/
DWORD VfdGetKeys()
{
DWORD dwRet;
VfdHold();
/* Command 2: set data */
SciSetByte(0x42); /* Get Key Command */
SciDelay(2);/* wait 2 us, need wait 1 us */
BYTE0(dwRet)=SciGetByte();
BYTE1(dwRet)=SciGetByte();
BYTE2(dwRet)=SciGetByte();
BYTE3(dwRet)=0x00;
VfdRelease();
return dwRet;
}
/*----------------------------------------------------------------------
* Function_Name: VfdInitStandbyKey
*
* Description:
*
* Arguments:
* BYTE - bSystemCode (IR System code)
* BYTE - bStandbyKey (IR Standby key code)
*
* Return Value:
* void
*----------------------------------------------------------------------*/
void VfdInitStandbyKey(BYTE bSystemCode, BYTE bStandbyCode)
{
VfdHold();
SciSetByte(0x60); /* Write IR System code command */
SciDelay(2); /* wait 2 us, need wait 1 us */
SciSetByte(bSystemCode);
SciDelay(2); /* wait 2 us, need wait 1 us */
SciSetByte(0x61); /* Write IR Standby code command */
SciDelay(2); /* wait 2 us, need wait 1 us */
SciSetByte(bStandbyCode);
VfdRelease();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -