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

📄 复件 ht1621.c

📁 VFD 显示驱动程序,可以直接应用.包括测试函数
💻 C
字号:

*/

#include <reg51.h>
#include <intrins.h>  //_nop_();
#include "type.h"
#include "gpio.h"
#include "ht1621.h"

extern GPIO volatile xdata *gGpio;
#define uchar unsigned char

#define BIAS   0X52
#define SYSEN  0X02
#define LCDON  0X06
#define LCDOFF 0X04
#define XTAL   0X30

//sbit HTCS  = P1^0;
//sbit HTWR  = P1^1;
//sbit HTDAT = P1^2;
#define  HTCS  0x04
#define  HTWR  0x02
#define  HTDAT 0x01

extern unsigned char Disp_Buffer[11];
const unsigned char Segment[17 ] ={0xaf,0xa0,0xcb,0xe9,
                                   0xe4, 0x6d,0x6f,0xa8,
								   0xef,0xed,0xee,0xef,
								   0x0f,0xaf,0x4f,0x4e};
/* Icon[0]-[AMCLOCK];Icon[1]-[PM];Icon[2]-[:];
 Icon[3]-[FLAT];Icon[4]-[USB];Icon[5]-[CARD];
 Icon[6]-[sleep];Icon[7]-[ROCK];Icon[8]-[classic];
 Icon[9]-[clock];Icon[10]-[(1)];Icon[11]-[pop];
 Icon[12]-[aux];Icon[13]-[ipod];Icon[14]-[(2)];Icon[15]-[radio];
 Icon[16]-[repeat];Icon[17]-[all];Icon[18]-[外筐];
 Icon[19]-[mhz];Icon[20]-[khz];Icon[21]-[st];
 Icon[22]-[copy];Icon[23]-[5];Icon[24]-[.];
 Icon[25]-[|];Icon[26]-[FM];Icon[27]-[amradio];
 Icon[28]-[||];Icon[29]-[play];*/
const unsigned int Icon[] = 
    { 0x0010,0x0110,0x0210,0x0401,0x0402,0x0404,
      0x0408,0x0410,0x0420,0x0440,0x0480,0x0501,
	  0x0502,0x0504,0x0508,0x0510,0x0520,0x0540,
	  0x0580,0x0601,0x0602,0x0604,0x0608,0x0610,
	  0x0710,0x0810,0x0910,0x0920,0x0940,0x0980};
                     
void SendBit(uchar dat, uchar cnt) //dat 的高CNT位写入HT1621,高位在前
{
	uchar i=0;
	for(i=0; i<cnt; i++)
	{
		if((dat&0x80)==0) 
		//	HTDAT = 0;
		   gGpio->PortB.rGPIO_OUT  &= (~HTDAT);
		else
		//	HTDAT = 1;
		   gGpio->PortB.rGPIO_OUT |= HTDAT;
        _nop_();_nop_();_nop_();_nop_();
		//HTWR = 0;
		  gGpio->PortB.rGPIO_OUT  &= (~HTWR);
		_nop_();_nop_();_nop_();_nop_();
	//	HTWR = 1;
	    gGpio->PortB.rGPIO_OUT |= HTWR;
        _nop_();_nop_();_nop_();_nop_();
		dat <<= 1;
	}
}
void SendDataBit(uchar dat, uchar cnt)  //dat的低CNT位写入HT1621,低位在前
{
	uchar i=0;
	for(i=0; i<cnt; i++)
	{
		if((dat&0x01)==0)
		//	HTDAT = 0;
		   gGpio->PortB.rGPIO_OUT  &= (~HTDAT);
		else 
		//	HTDAT = 1;
		   gGpio->PortB.rGPIO_OUT |= HTDAT;
        _nop_();_nop_();_nop_();_nop_();
		//HTWR = 0;
	   gGpio->PortB.rGPIO_OUT  &= (~HTWR);
		_nop_();_nop_();_nop_();_nop_();
	//	HTWR = 1;
	    gGpio->PortB.rGPIO_OUT |= HTWR;
        _nop_();_nop_();_nop_();_nop_();
		dat >>= 1;

	}
}
void SendCmd(uchar command)
{
//	HTCS = 0;
	gGpio->PortB.rGPIO_OUT  &= (~HTCS);
	SendBit(0x80, 4);
	SendBit(command, 8);
//	HTCS = 1;
	gGpio->PortB.rGPIO_OUT |= HTCS;
}
void Write_1621(uchar addr, uchar dat)
{
//	HTCS = 0;
	gGpio->PortB.rGPIO_OUT  &= (~HTCS);
	SendBit(0xA0, 3);
	SendBit(addr, 6);
	SendDataBit(dat, 4);
//	HTCS = 1;
    gGpio->PortB.rGPIO_OUT |= HTCS;
}
void WriteAll_1621(uchar addr, uchar *p, uchar cnt)
{
	uchar i=0;
	//HTCS = 0;
	gGpio->PortB.rGPIO_OUT  &= (~HTCS);
	SendBit(0xA0, 3);
	SendBit(addr, 6);
	for(i=0; i<cnt; i++,p++)
	{
		SendDataBit(*p, 8);	
	}
	//HTCS = 1;
    gGpio->PortB.rGPIO_OUT |= HTCS;
}

void Buf_Set_Digital( unsigned char Position,unsigned char Digital )
{
   
	if(Position<4)
    {
        Disp_Buffer[Position] &= 0x10;
        Disp_Buffer[Position] |= Segment[ Digital ];
    }   
	else
	{
       Disp_Buffer[13-Position] &= 0xf0;
       Disp_Buffer[13-Position] |= (Segment[ Digital ]&0x0f);
       Disp_Buffer[12-Position] &= 0x1f;
       Disp_Buffer[12-Position] |= (Segment[ Digital ]&0xf0);
	}
}  

void Buf_Set_Icon( unsigned int Icon )
{
    Disp_Buffer[ Icon>>8 ] |= ( unsigned char )Icon;
}


void Buf_Clear_Icon( unsigned int Icon )
{
    Disp_Buffer[ Icon>>8 ] &= (~( unsigned char )Icon);
}
void InitHT1621()
{
	gGpio->PortB.rGPIO_OE |= 0x0f; 
    gGpio->PortB.rGPIO_OUT |= 0x0f; 
	SendCmd(XTAL);
	SendCmd(BIAS);
	SendCmd(SYSEN);
	SendCmd(LCDON);
}
/*
void main()
{                                   //0,   1,    2 ,  3,   4 ,  5 ,  6 ,  7 , 8  ,  9,   a ,  b , c   ,d   , e,  f

	uchar i;

	HTCS  = 1;
	HTWR  = 1;
	HTDAT = 1;
  
    SendCmd(XTAL);
	SendCmd(BIAS);
	SendCmd(SYSEN);
	SendCmd(LCDON);
  
   
         for (i=0;i<30;i++)
        {
              Buf_Set_Digital(0,i);
    Buf_Set_Digital(1,i);
    Buf_Set_Digital(2,i);
    Buf_Set_Digital(3,i);
    Buf_Set_Digital(4,i);
    Buf_Set_Digital(5,i);
    Buf_Set_Digital(6,i);
            Buf_Set_Icon( Icon[i] );
            WriteAll_1621(0, Disp_Buffer, 10);
        }

       
       for (i=0;i<30;i++)
	   {
          Buf_Clear_Icon( Icon[i] );
          WriteAll_1621(0, Disp_Buffer, 10);
        }
		   
     SendCmd(LCDOFF);
	while(1)
	{
	_nop_();
	}
}
*/

⌨️ 快捷键说明

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