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

📄 upd16311.c

📁 M3355的源代码
💻 C
字号:
/*====================================================================
 *
 *  Copyright (C) 1997 Acer Labs, Inc.  All Rights Reserved.
 *                  
 *  File:   uPD16311.c 
 *                                           
 *  Contents: uPD16311 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 20
	#define VFD_GRID_NUM 8
#elif VFD_DISP_MODE == 0x01
    #define VFD_SEG_NUM 16
    #define VFD_GRID_NUM 5
#elif VFD_DISP_MODE == 0x08
	#define VFD_SEG_NUM 19
	#define VFD_GRID_NUM 9
#elif VFD_DISP_MODE == 0x09
	#define VFD_SEG_NUM 18
	#define VFD_GRID_NUM 10
#elif VFD_DISP_MODE == 0x0a
	#define VFD_SEG_NUM 24
	#define VFD_GRID_NUM 6
//	#define VFD_SEG_NUM 17
//	#define VFD_GRID_NUM 11
#elif VFD_DISP_MODE == 0x0b
	#define VFD_SEG_NUM 16
	#define VFD_GRID_NUM 12
#elif VFD_DISP_MODE == 0x0c
	#define VFD_SEG_NUM 15
	#define VFD_GRID_NUM 13
#elif VFD_DISP_MODE == 0x0d
	#define VFD_SEG_NUM 14
	#define VFD_GRID_NUM 14
#elif VFD_DISP_MODE == 0x0e
	#define VFD_SEG_NUM 13
	#define VFD_GRID_NUM 15
#elif VFD_DISP_MODE == 0x0f
	#define VFD_SEG_NUM 12
	#define VFD_GRID_NUM 16
#endif


/*----------------------------------------------------------------------
 * Function_Name: VfdHold
 *
 * Description:	Hold Vfd Chip, pull VFD Strobe low
 *
 * Arguments:
 *
 * Return Value: void
 *----------------------------------------------------------------------*/
static void VfdHold()
{
    int i;
    /*WaitSem(SCI_semid);*/
    dis_dsp();



    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 */
    //alert(" ======= VfdHold return =======\n\r\0");
    for (i=0;i<5;i++)
    {}


    /***************************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);*/
    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
 *----------------------------------------------------------------------*/
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 */
#if(_MODEL != CYP405)  //add for vfdbright
    VfdCommand( (BYTE)(0x88 | DIMMING_RATE) );
#endif
}

/*----------------------------------------------------------------------
 * Function_Name: VfdDisplayOff
 *
 * Description:	Turn Off the VFD Screen
 *
 * Arguments:
 *
 * Return Value: void
 *----------------------------------------------------------------------*/
void VfdDisplayOff()
{
    /* Command 4: control display-dimming quantily */
#if(_MODEL != CYP405)  //add for vfdbright
    VfdCommand( (BYTE)(0x80 | DIMMING_RATE) );
#endif
}
#if(_MODEL == CYP405 || _MODEL == CYP325U)
void VfdDisplayOff2()
{
    /* Command 4: control display-dimming quantily */
    //add for vfdbright
    VfdCommand( (BYTE)(0x88) );

}
#endif
/*----------------------------------------------------------------------
 * 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*3;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 dwRet;
    VfdHold();
    /* Command 2: set data */
    SciSetByte(0x43); /* Get SW Command */
    SciDelay(2);/* wait 2 us, need wait 1 us */
    dwRet=SciGetByte();
    VfdRelease();
    return dwRet;
}

/*----------------------------------------------------------------------
 * Function_Name: VfdSetLed
 *
 * Description:	Set value of 5 LEDs
 *
 * Arguments:
 *     BYTE bLEDs - 5 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));
    SciSetByte(BYTE2(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/*if 0*/

/*----------------------------------------------------------------------
 * Function_Name: VfdInit
 *
 * Description:	Initialize the Vfd Chip
 *
 * Arguments:
 *
 * Return Value: void
 *----------------------------------------------------------------------*/
void VfdInit()
{

    /* /STB for VFD, this chip is low active!! */
    /************************M3325C_PLATFORM******************************/
    /*************************M3351_PLATFORM******************************/
    SET_GPIO_W(SCI_VFD);
    SET_GPIO_HI(SCI_VFD);


    /***************************M6303_PLATFORM*****************************/
    /**********************************************************************/

    VfdCommand(VFD_DISP_MODE); /* Set # of Grid/Segment  */
#if (_TA==3)

    VfdSetLed(0xfd);/* Turn on Green LED */ // only mk bowei 2002/10/28
#elif (_MODEL == CYP405)

    VfdSetLed(0xff); /* turn off all LED */
#else

    VfdSetLed(0x00);/* turn off all LED */
#endif

    VfdCls();
}

/*----------------------------------------------------------------------
 * 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));
        SciSetByte(BYTE2(*dwBuff));
    }
    VfdRelease();
}

/*----------------------------------------------------------------------
 * 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 = 0;

    VfdHold();
    /* Command 2: set data */
    SciSetByte(0x42); /* Get Key Command */
    SciDelay(2);/* wait 2 us, need wait 1 us */
    /* key-map of 32 keys. (This chip should have 48 keys at most!) */

    BYTE0(dwRet)=SciGetByte();
    BYTE1(dwRet)=SciGetByte();
    BYTE2(dwRet)=SciGetByte();
    BYTE3(dwRet)=SciGetByte();

    VfdRelease();
    return dwRet;
}

⌨️ 快捷键说明

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