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

📄 7219.c

📁 芯片
💻 C
📖 第 1 页 / 共 3 页
字号:

/*------------------------------------------------------------------------------
;          Title:	VS7219 Function Test/Demo Board
;      Programer:	Wang Hezuo(王合作)
;        Version: 	1.0
;   Last updated: 	2005.11.19
;         Target: 	--------
;      Processor: 	AT89C51(Generic 8031 series),at 24M(30P)
;        Display: 	LCM1602
; Support E-mail: 	wanghz@vslun.com
;			wanghezuo@hotmail.com
;    DESCRIPTION:
;			This Application Support to Test VS7219
;			And Demo & Can Measure Pin Current.
------------------------------------------------------------------------------*/

//#pragma src							// 产生汇编文件
#include <reg51.h>
#include <absacc.h>
#include <string.h>
#include <intrins.h>


// =★=★=★=★=★=★= 变量类型标识的宏定义,大家都喜欢这么做 =★=★=★=★=★=★=
#define uchar   	unsigned char
#define uint    	unsigned int

#define SomeNOP(); 	_nop_();_nop_();_nop_();_nop_(); 	//SomeNOP()使电路有一个稳定的过程


//uchar idata
#define cA      0x41
#define cB      0x42
#define cC      0x43
#define cD      0x44
#define cE      0x45
#define cF      0x46
#define cG      0x47
#define cH      0x48
#define cI      0x49
#define cJ      0x4a
#define cK      0x4b
#define cL      0x4c
#define cM      0x4d
#define cN      0x4e
#define cO      0x4f
#define cP      0x50
#define cQ      0x51
#define cR      0x52
#define cS      0x53
#define cT      0x54
#define cU      0x55
#define cV      0x56
#define cW      0x57
#define cX      0x58
#define cY      0x59
#define cZ      0x5a

#define ca      0x61
#define cb      0x62
#define cc      0x63
#define cd      0x64
#define ce      0x65
#define cf      0x66
#define cg      0x67
#define ch      0x68
#define ci      0x69
#define cj      0x6a
#define ck      0x6b
#define cl      0x6c
#define cm      0x6d
#define cn      0x6e
#define co      0x6f
#define cp      0x70
#define cq      0x71
#define cr      0x72
#define cs      0x73
#define ct      0x74
#define cu      0x75
#define cv      0x76
#define cw      0x77
#define cx      0x78
#define cy      0x79
#define cz      0x7a


#define c0      0x30
#define c1      0x31
#define c2      0x32
#define c3      0x33
#define c4      0x34
#define c5      0x35
#define c6      0x36
#define c7      0x37
#define c8      0x38
#define c9      0x39


char code exampl01[] = "When 7219 Ready ";
char code exampl02[] = "   Press NEW Key";
char code exampl03[] = "New 7219 Status:";
char code exampl04[] = "See Indicate LED";
char code exampl05[] = "VS7219 Status:  ";
char code exampl06[] = "  Display Normal"; // 测试状态
char code exampl07[] = "    Display Test";
char code exampl08[] = "          Decode"; // 译码/不译码
char code exampl09[] = "       NO Decode";
char code exampl10[] = "        ShutDown"; // 关断/启动
char code exampl11[] = "          WakeUp";
char code exampl12[] = "VS7219 Display  "; // 演示显示,同时选择是译码/不译码时的显示


char code exampl13[] = " ";

char code exampl14[] = "OK?";


// LCD1602 Pin Defined(引脚定义Can change this part at different board.)
/******************************************************************************/
#define Busy 		0x80 				// LCD sfr Busy=0x80;
#define DataPort 	P0 				// LCD数据端口
sbit RS_LCD       	= P1^0;
sbit RW_LCD       	= P1^1;
sbit E_LCD     		= P1^2;


// VS7219 Pin Defined(引脚定义Can change this part at different board.)
/******************************************************************************/
sbit VS7219_LOAD_TestIC	= P1^6; 			// VS7219  Load-Data Input: rising edge  pin 12
sbit VS7219_LOAD	= P1^4; 			// VS7219  Load-Data Input: rising edge  pin 12
sbit VS7219_DIN		= P1^5; 			// VS7219  Serial-Data Input: rising edge  pin 1
sbit VS7219_CLK		= P1^3; 			// VS7219  Serial-Clock Input: maximum 10MHz  pin 13

// VS7219 common part
#define  HIGH 		1
#define  LOW 		0
#define  TRUE      	1
#define  FALSE      	0
#define  ZERO     	0
#define  MSB 		0x80
#define  LSB 		0x01

// VS7219 part
#define  NoOp 		0x00
#define  Digit0 	0x01
#define  Digit1 	0x02
#define  Digit2 	0x03
#define  Digit3 	0x04
#define  Digit4 	0x05
#define  Digit5 	0x06
#define  Digit6 	0x07
#define  Digit7 	0x08
#define  DECODE_MODE    0x09
#define  INTENSITY      0x0A
#define  SCAN_LIMIT     0x0B
#define  SHUTDOWN       0x0C
#define  DISPLAY_TEST   0x0F

        bit B_DISPLAY_TEST; 						// 测试标志位
        bit B_SHUTDOWN; 						// 关断标志位
        bit B_DECODE_MODE; 						// 译码/不译码标志位
        unsigned char FLAG_INTENSITY; 					// 亮度标志
        unsigned char FLAG_SCAN_LIMIT; 					// 位数标志
        unsigned char FLAG_LED; 					// LED标志

// VS7219 演示时显示的数据
unsigned char code Num_Decode[] =  {   // 译码显示的数据
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0c,0x0b,0x0d,0x0e,0x0f};
//0    1    2    3    4    5    6    7    8    9    -    H    E    L    P    空

unsigned char code Num_NoDecode[] = {  // 不译码显示的数据
0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,
//0    1    2    3    4    5    6    7    8    9
0x40,0x01,0x08,0x49,0x1f,0x4e,0x3d,0x4f,0x47,0x5f,
//-(上)-(中)_(下)三   b    C    d    E    F    G
0x17,0x37,0x0e,0x63,0x1d,0x7e,0x67,0x73,0x00};
// h   H    L  o(上)o(下)O(大)  P    q    空


//{0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x00,0x79,0x4f,0x01,0x47,0x4f,0x4f,0x0e,0x08,0x5f,0x1d,0x1d,0x3d,0x40,0x37,0x4f,0x0e,0x67,0x00};
// 0    1    2    3    4    5    6    7    8    9    空   3    E    -    F    E    E    L    _    G    o    o    d    -    H    E    L    P    空


// 键盘用的(全局变量)
unsigned char key;
sbit KeyBoard_GND 	= P3^0;




// =★=★=★=★=★=★=★=★=★= LCD1602显示驱动程序 =★=★=★=★=★=★=★=★=★=

/*=============================================================================
            LCD1602字符液晶屏显示驱动程序

连接线图:   LCM-------51     LCM-------51     LCM------------51
            DB0-----P0.0     DB4-----P0.4     RS_LCD-------P2.0
            DB1-----P0.1     DB5-----P0.5     RW_LCD-------P2.1
            DB2-----P0.2     DB6-----P0.6     E_LCD--------P2.7
            DB3-----P0.3     DB7-----P0.7     VLCD接1K2电阻到GND

[注]:AT89C51的晶振频率为12MHz
==============================================================================*/

void Delay5ms(void);
void Delay10ms(void );
void Delay100ms(void);
void Delay200ms(void);
void Delay400ms(void);
void ePutstr(unsigned char x, unsigned char y, unsigned char code *ptr);
void Display( unsigned char dd );
void Disp_XY( char posx,char posy);
void DispOneChar(unsigned char x, unsigned char y, unsigned char Wdata);
void Initial_LCD1602( void );
void LcdWriteCommand( unsigned char CMD, unsigned char AttribC );
void LcdWriteData( char dataW );
void WaitForEnable( void );
void LcdClear(void );
void LCD1602_LOGO(void );


// =★=★=★=★=★=★=★=★=★=★= 短延时 5ms =★=★=★=★=★=★=★=★=★=★=
void Delay5ms(void)
{
    	unsigned int i = 5552;

    	while(i--);
}


// =★=★=★=★=★=★=★=★=★=★= 短延时 10ms =★=★=★=★=★=★=★=★=★=★=
void Delay10ms(void )
{
     	unsigned char i;

     	for(i = 200;i>0;i--) { ;}
}


// =★=★=★=★=★=★=★=★=★=★= 长延时 100ms =★=★=★=★=★=★=★=★=★=★=
void Delay100ms(void)
{
    	unsigned char i = 3;
    	unsigned int  j;

    	while(i--)
    	{
        	j=3634;
        	while(j--);
    	};
}



// =★=★=★=★=★=★=★=★=★=★= 长延时 200ms =★=★=★=★=★=★=★=★=★=★=
void Delay200ms(void)
{
    	unsigned char i = 5;
    	unsigned int  j;

    	while(i--)
    	{
        	j=3634;
        	while(j--);
    	};
}


// =★=★=★=★=★=★=★=★=★=★= 长延时 400ms =★=★=★=★=★=★=★=★=★=★=
void Delay400ms(void)
{
    	unsigned char i = 5;
    	unsigned int  j;

    	while(i--)
    	{
        	j=7269;
        	while(j--);
    	};
}


/*==============================================================================
从指定位置显示字符串
x:0-15  y:0-1
==============================================================================*/
void ePutstr(unsigned char x, unsigned char y, unsigned char code *ptr)
{
	unsigned char i,l=0;

	while (ptr[l] > 31) {l++;};
    	for (i=0;i<l;i++)
    	{
        	DispOneChar(x++,y,ptr[i]);
        	if ( x == 16 )
        	{
            		x  = 0;
            		y ^= 1;
        	}
    	}
}


/*==============================================================================
演示一行连续字符串,配合上位程序演示移动字串
==============================================================================*/
void Display( unsigned char dd )
{
    	unsigned char i;

    	for (i=0;i<16;i++)
    	//for (i=15;i<0;i--)
    	{
        	DispOneChar(i,1,dd++);
                Delay200ms();
        	dd &= 0x7f;
        	if (dd<32) dd=32;
    	}
}


/*==============================================================================
显示光标定位  (x 0-15 ; y 0-1)
==============================================================================*/
void Disp_XY( char posx,char posy)
{
    	unsigned char temp;

    	temp = posx & 0xf;
    	posy &= 0x1;
    	if ( posy )temp |= 0x40;
    	temp |= 0x80;
    	LcdWriteCommand(temp,0);
}


/*==============================================================================
按指定位置显示数出一个字符
==============================================================================*/
void DispOneChar(unsigned char x, unsigned char y, unsigned char Wdata)
{
        Disp_XY( x, y );                                 // 定位显示地址
        LcdWriteData( Wdata );                           // 写字符
}


/*==============================================================================
初始化程序, 必须按照产品资料介绍的初始化过程进行
==============================================================================*/
void Initial_LCD1602( void )
{
        Delay5ms();Delay5ms();Delay5ms();               // 延时15ms
        LcdWriteCommand( 0x38, 0);                      // 显示模式设置(不检测忙信号)
        Delay5ms();                                     // 延时5ms
        LcdWriteCommand( 0x38, 0);                      // 共三次
        Delay5ms();
        LcdWriteCommand( 0x38, 0);
        //Delay5ms();

        LcdWriteCommand( 0x38, 1);                      // 显示模式设置(以后均检测忙信号)
        LcdWriteCommand( 0x08, 1);                      // 显示关闭
        LcdWriteCommand( 0x01, 1);                      // 显示清屏
        LcdWriteCommand( 0x06, 1);                      // 显示光标移动设置
        LcdWriteCommand( 0x0c, 1);                      // 显示开及光标设置
}


/*==============================================================================
写控制字符子程序: E=1 RS_LCD=0 RW_LCD=0                    写指令
==============================================================================*/
void LcdWriteCommand( unsigned char CMD, unsigned char AttribC )
{

        if (AttribC) WaitForEnable();                   // 检测忙信号?
        RS_LCD = 0;  RW_LCD = 0; _nop_();_nop_();
        DataPort = CMD; _nop_();_nop_();
        // 送控制字子程序

        E_LCD = 1; _nop_();_nop_(); E_LCD = 0;            // 操作允许脉冲信号
}


/*==============================================================================
当前位置写字符子程序: E =1 RS_LCD=1 RW_LCD=0               写数据
==============================================================================*/
void LcdWriteData( char dataW )
{

    	WaitForEnable();                            	// 检测忙信号

    	RS_LCD = 1; RW_LCD = 0; _nop_();_nop_();
    	DataPort = dataW; _nop_();_nop_();
    	E_LCD = 1; _nop_();_nop_(); E_LCD = 0;        	// 操作允许脉冲信号

}


/*==============================================================================
正常读写操作之前必须检测LCD控制器状态:    E=1 RS_LCD=0 RW_LCD=1
DB7:  0  LCD控制器空闲; 1  LCD控制器忙
==============================================================================*/
void WaitForEnable( void )
{
    	DataPort = 0xff;
    	RS_LCD =0; RW_LCD = 1; _nop_();
    	E_LCD = 1; _nop_();_nop_();
    	while( DataPort & Busy );
    	E_LCD = 0;
}


/*==============================================================================
显示屏清屏
==============================================================================*/
void LcdClear(void )
{
    	LcdWriteCommand(0x01,1);
}

⌨️ 快捷键说明

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