📄 vfd.c
字号:
/******************************************************************
** 文件名: VFD.C
** Copyright (c) 昊元科技技术开发部
** 创建人: 马 亮
** 日 期: 2005/03/29
** 修改人:
** 日 期:
** 描 述: VFD模块的驱动函数,
驱动芯片为 UPD16311
引脚连线见原理图
** 版 本:
******************************************************************/
#include "include.h"
// PIN 定义
//commands
#define DMSC 0x00 //00 display mode setting command
#define DSC 0x40 //01 data setting command
#define ASC 0xc0 //11 address setting command
#define DCC 0x80 //10 display control command
//set data write and read modes
#define WDTDM 0x00 //00 write data to diaplay memory
#define WDTLED 0x01 //01 write data to LED
#define RKD 0x02 //10 read key data
#define RSD 0x03 //11 read SW data
//uchar VfdRamBuff[48];
//真值表
#define DIG1 1
#define DIG2 2
#define DIG3 3
#define DIG4 4
#define DIG5 5
#define DIG6 6
#define DIG7 7
#define DIG8 8
#define DIG9 9
#define DIG10 10
#define DIG11 11
#define DIG12 12
#define M_E 13
/***********************************************************
* com1 ___a___
* | | |
* |f | b
* | |
* |___g___|
* | |
* |e | c
* | | 。 DP
* |___d___| , com2
*
***********************************************************/
// P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
// com1 a b f g c e d DP com2
//------------------------------------
// 0. ABCDEF 1110 1110 0xee |
// 1. BC 0010 0100 0x24 |
// 2. ABDEG 1101 0110 0xd6 |
// 3. ABCDG 1011 0110 0xb6 |
// 4. BCFG 0011 1100 0x3c |
// 5. ACDFG 1011 1010 0xba |
// 6. ACDEFG 1111 1010 0xfa |
// 7. ABC 0010 0110 0x26 |
// 8. ABCDEFG 1111 1110 0xfe |
// 9. ABCDFG 1011 1110 0xbe |
//------------------------------------
uchar Digit[]={0xee,0x24,0xd6,0xb6,0x3c,0xba,0xfa,0x26,0xfe,0xbe};
#define VFD_DOT 10
#define VFD_NULL 11
/*******************************************
* 外部函数,来自 lcd_ctrol.c
********************************************/
//extern void SetupPortB(uint add,uchar dat);
void ClrVFD();
/***************************************************
* 函数: Wrt_VFD_1byte(uchar ubyte)
* 输入: uchar ubyte -- 输入16311的数据或命令
* 输出: void
* 功能: 送一个数据或命令给UPD16311
* 必须严格按DATABOOK上的时序控制 VFD_STB、VFD_CLK、VFD_DAT
***************************************************/
void Wrt_VFD_1byte(uchar ubyte)
{
uchar i;
i=8;
do
{
SetupPortB(VFD_CLK,0);
if(ubyte&0x01)
SetupPortB(VFD_DAT,1);
else
SetupPortB(VFD_DAT,0);
ubyte>>=1;
_nop_();
SetupPortB(VFD_CLK,1);
i--;
}while(i!=0);
}
/********************************************
* 函数: Disp_VFD_On()
* 输入: void
* 输出: void
* 功能: 开VFD显示
* 开VFD显示,设置脉宽: 0x8f
b7 b6 b5 b4 b3 b2 b1 b0
1 0 |___| | |___|___|
| | |_________ set dimming quanlity
Don't care | 000: set pluse with to 1/16
| 001: set pluse with to 2/16
| 010: set pluse with to 4/16
| 011: set pluse with to 10/16
| 100: set pluse with to 11/16
| 101: set pluse with to 12/16
| 110: set pluse with to 13/16
| 111: set pluse with to 14/16
|
|_______________ turn on/off diaplay
0 : display off
1 : display on
********************************************/
void Disp_VFD_On()
{
SetupPortB(VFD_STB,0); //数据在STB为低时送入
Wrt_VFD_1byte(DCC|0x08|0x07);//开VFD显示
SetupPortB(VFD_STB,1);
}
/********************************************
* 函数: Disp_VFD_Off()
* 输入: void
* 输出: void
* 功能: 关VFD显示
********************************************/
void Disp_VFD_Off()
{
SetupPortB(VFD_STB,0); //数据在STB为低时送入
Wrt_VFD_1byte(DCC|0x00|0x07);//关VFD显示
SetupPortB(VFD_STB,1);
}
/********************************************
* 函数: Init_VFD()
* 输入: void
* 输出: void
* 功能: 对VFD模块进行初始化
* 设置显示模式: 0x0e (13 digits--15 segments)
********************************************/
void Init_VFD(void)
{
uchar EAStatus;
EAStatus = EA;
EA=0;
SetupPortB(VFD_CLK,1);
SetupPortB(VFD_DAT,1);
SetupPortB(VFD_STB,1);
Disp_VFD_Off();
SetupPortB(VFD_STB,0); //数据在STB为低时送入
Wrt_VFD_1byte(DMSC|0x0c); //设置显示模式 (13 digits--15 segments)
SetupPortB(VFD_STB,1);
ClrVFD();
EA = EAStatus;
}
/******************************************************************
* 函数: _Set_VDF_Addr(uchar _data)
* 输入: uchar _data --- VFD RAM 地址值
* 输出: void
* 功能: 设置传入数据在 VFD RAM 中的地址
******************************************************************/
void _Set_VDF_Addr(uchar _data)
{
_data = _data&0x3f; //数据保护
Wrt_VFD_1byte(ASC|_data);//设置地址
}
/******************************************************************
* 函数: _display_VFD(uchar DispAddr, uchar _data)
* 输入: uchar DispAddr --- VFD RAM 地址
* uchar _data --- VFD RAM 数据
* 输出: void
* 功能: 把显示数据送入VFD RAM 中
******************************************************************/
void _display_VFD(uchar DispAddr, uchar _data)
{
uchar _addr;
_addr = DispAddr;
SetupPortB(VFD_STB,0); //数据在STB为低时送入
Wrt_VFD_1byte(0x44);//设置成写数据 display momery 模式 0x44
SetupPortB(VFD_STB,1);
SetupPortB(VFD_STB,0); //数据在STB为低时送入
_Set_VDF_Addr(_addr);//设置 display momery 地址
Wrt_VFD_1byte(_data);//把数据写进 display momery
SetupPortB(VFD_STB,1);
Disp_VFD_On();
}
/******************************************************************
* 函数: ClrVFD()
* 输入: void
* 输出: void
* 功能: 清空VFD显示数据
******************************************************************/
void ClrVFD()
{
uchar i;
for(i=0; i<48; i++)
_display_VFD(i,0);
}
/******************************************************************
* 函数: DisplayVFD(uchar _index, uchar _num)
* 输入: uchar _index --- 地址序号(例如: _index = 0,对应右起第一个 '8' 字)
* uchar _num --- 要显示的数据 (例如: _num = 1时,显示1)
* 输出: void
* 功能: 在对应的段码管中,显示相应的值
******************************************************************/
void DisplayVFD(uchar _index, uchar _num)
{
uchar EAStatus;
EAStatus = EA;
EA = 0;
switch(_num)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
_display_VFD(_index*3,Digit[_num]);
_display_VFD(_index*3+1,0);
_display_VFD(_index*3+2,0);
break;
case VFD_DOT: //显示点
// _display_VFD(_index*3,0);
_display_VFD(_index*3+1,0x01);
// _display_VFD(_index*3+2,0);
break;
case VFD_NULL: //显示空白
_display_VFD(_index*3,0);
_display_VFD(_index*3+1,0);
_display_VFD(_index*3+2,0);
break;
default :
break;
}
EA = EAStatus;
}
void DispNumVfd(ulong ShowData)
{
uchar i,index;
uchar buf[8];
uchar showflg=0;
buf[7] = ShowData/10000000;
buf[6] = (ShowData%10000000/1000000);
buf[5] = (ShowData%1000000/100000);
buf[4] = (ShowData%100000/10000);
buf[3] = (ShowData%10000/1000);
buf[2] = (ShowData%1000/100);
buf[1] = (ShowData%100/10);
buf[0] = (ShowData%10);
for(i=8;i>0;i--)
{
index = i-1;
if(buf[index]||index<=2)
showflg = 1;
if(showflg)
DisplayVFD(index,buf[index]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -