xianshi.c

来自「基于51单片机的320×240lcd显示器测试程序」· C语言 代码 · 共 234 行

C
234
字号
#include <reg52.h>
#include <stdio.h>
#include <math.h>
#include <absacc.h>
#include <string.h>
#define Uchar unsigned char 
#define Uint unsigned int
/* 直接访问方式地址定义,根据用户平台接口修改 */
#define  wcadd1 XBYTE[0x0100]  /* 写指令代码地址 */
#define  wdadd1 XBYTE[0x0000]  /* 写参数及显示数据地址 */
#define  rdadd1 XBYTE[0x0100]  /* 读参数及显示数据地址 */
#define  rbadd1 XBYTE[0x0000]  /* 读忙状态地址 */
/* 程序参数定义,根据用户选择的LCM型号修改 */
#define  para     0x28  ;
#define CsrDirD		0x4f;
#define	CsrW		0x46;
#define	mWrite		0x42;

/*-------------------320240的SYSTEM SET 参数-------------------------------*/
unsigned char SYSTAB[8]={0x30,0x87,0x07,0x27,0x42,0xf0,0x30,0x00};//p1-p8
unsigned char SCRTAB[10]={0x00,0x00,0xf0,0x00,0x40,0xf0,0x00,0x80,0x00,0x00};//p1-pp10

typedef struct typFNT_GB16				// 汉字字模数据结构
{
	signed char Index[2];
	char Msk[32];
};

struct typFNT_GB16 code Cdotlib[]={

	   "测",0x40,0x02,0x27,0xC2,0x24,0x42,0x84,0x52,		//0
		0x45,0x52,0x55,0x52,0x15,0x52,0x25,0x52,
		0x25,0x52,0x25,0x52,0xC5,0x52,0x41,0x02,
      		0x42,0x82,0x42,0x42,0x44,0x4A,0x48,0x04,

	   "试",0x00,0x20,0x40,0x28,0x20,0x24,0x30,0x24,		//1
		0x27,0xFE,0x00,0x20,0xE0,0x20,0x27,0xE0,
		0x21,0x20,0x21,0x10,0x21,0x10,0x21,0x0A,
        	0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00,

	   "文",0x02,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,		//2
		0x10,0x10,0x08,0x10,0x08,0x20,0x04,0x20,
		0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,
		0x04,0x60,0x08,0x10,0x30,0x0E,0xC0,0x04,

	   "本",0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x08,		//3
		0x7F,0xFC,0x05,0x40,0x05,0x40,0x05,0x40,
		0x09,0x20,0x09,0x20,0x11,0x10,0x2F,0xEE,
		0xC1,0x04,0x01,0x00,0x01,0x00,0x01,0x00,

	   "方",0x04,0x00,0x03,0x00,0x01,0x00,0x00,0x04,		//4
		0xFF,0xFE,0x04,0x00,0x04,0x10,0x07,0xF8,
		0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x10,
		0x08,0x10,0x10,0x10,0x20,0xA0,0x40,0x40,

	   "式",0x00,0x80,0x00,0xA0,0x00,0x90,0x00,0x84,		//5
		0xFF,0xFE,0x00,0x80,0x00,0x80,0x3E,0x80,
		0x08,0x80,0x08,0x40,0x08,0x40,0x09,0x20,
		0x0E,0x22,0x70,0x12,0x20,0x0A,0x00,0x04,

	   "图",0x00,0x04,0x7F,0xFE,0x44,0x04,0x47,0xE4,		//6
		0x4C,0x44,0x52,0x84,0x41,0x04,0x42,0x84,
		0x46,0x44,0x49,0x3C,0x70,0x94,0x46,0x04,
		0x41,0x04,0x40,0x84,0x7F,0xFC,0x40,0x04,
 
	   "形",0x00,0x80,0x7F,0xC4,0x11,0x0C,0x11,0x10,		//7
	 	0x11,0x20,0x11,0x44,0x11,0x0C,0xFF,0xD0,
		0x11,0x20,0x11,0x42,0x11,0x06,0x11,0x08,
		0x21,0x10,0x21,0x20,0x41,0x40,0x01,0x00,
 };
 Uchar code  Cdot24lib[]={
		0x00,0x04,0x00,0x00,0x07,0x00,0x00,0x06,		// 晓
		0x00,0x23,0x06,0x18,0x3F,0x87,0xFC,0x33,
		0x7E,0x00,0x33,0x06,0x20,0x33,0x03,0x78,
		0x33,0x03,0xE0,0x33,0x03,0x84,0x3F,0x0E,
		0xC4,0x33,0x70,0x7C,0x33,0x00,0x0E,0x33,
		0x00,0x00,0x33,0x7F,0xF8,0x33,0x0C,0xC0,
		0x33,0x0C,0xC0,0x3F,0x0C,0xC4,0x33,0x18,
		0xC4,0x32,0x18,0xC4,0x20,0x30,0xC6,0x00,
		0x60,0xFE,0x01,0x80,0x7C,0x06,0x00,0x00,

		0x00,0x20,0x00,0x00,0x38,0x00,0x00,0x30,		// 奇
		0x00,0x00,0x30,0x30,0x1F,0xFF,0xF8,0x00,
		0x60,0x00,0x00,0xDC,0x00,0x01,0x87,0xC0,
		0x06,0x00,0xE0,0x08,0x00,0x4C,0x7F,0xFF,
		0xFE,0x00,0x00,0x60,0x08,0x18,0x60,0x0F,
		0xFC,0x60,0x0C,0x18,0x60,0x0C,0x18,0x60,
		0x0C,0x18,0x60,0x0C,0x18,0x60,0x0F,0xF8,
		0x60,0x0C,0x10,0x60,0x08,0x00,0x60,0x00,
		0x0F,0xE0,0x00,0x01,0xC0,0x00,0x00,0x80,

		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 工
		0x18,0x3F,0xFF,0xFC,0x00,0x18,0x00,0x00,
		0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,
		0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,
		0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,
		0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,
		0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,
		0x00,0x00,0x18,0x0C,0x7F,0xFF,0xFE,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

		0x02,0x08,0x00,0x03,0x8E,0x00,0x03,0x0C,		// 作
		0x00,0x03,0x0C,0x00,0x07,0x18,0x0C,0x06,
		0x1F,0xFE,0x06,0x36,0x00,0x0F,0x26,0x00,
		0x0E,0x66,0x00,0x1E,0x46,0x00,0x36,0x86,
		0x18,0x26,0x07,0xFC,0x46,0x06,0x00,0x86,
		0x06,0x00,0x06,0x06,0x00,0x06,0x06,0x0C,
		0x06,0x07,0xFE,0x06,0x06,0x00,0x06,0x06,
		0x00,0x06,0x06,0x00,0x06,0x06,0x00,0x06,
		0x06,0x00,0x06,0x06,0x00,0x04,0x04,0x00,

		0x00,0x30,0x00,0x00,0x18,0x00,0x10,0x10,		// 室
		0x0C,0x1F,0xFF,0xFE,0x30,0x00,0x0C,0x30,
		0x00,0x10,0x60,0x00,0xC0,0x07,0xFF,0xE0,
		0x00,0x60,0x00,0x00,0xC2,0x00,0x01,0x81,
		0x80,0x02,0x00,0x60,0x0F,0xFF,0xF0,0x07,
		0x10,0x30,0x00,0x1C,0x10,0x00,0x18,0x00,
		0x00,0x18,0x60,0x0F,0xFF,0xF0,0x00,0x18,
		0x00,0x00,0x18,0x00,0x00,0x18,0x0C,0x7F,
		0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00
};

INT_1()
   {
     unsigned char i;
     wcadd1=0x40;   /* SYSTEM SET代码 */
     for(i=0;i<8;i++)
        {
          wdadd1=SYSTAB[i];  /* 写入参数 */
        }
      wcadd1=0x44;   /* SCROLL代码 */
      for(i=0;i<10;i++)
        {
          wdadd1=SCRTAB[i];   /* 写入参数 */
        }
      wcadd1=0x5a;   /* HDOT SCR 代码 */
      wdadd1=0x00;   /* 设置参数P1 */
      wcadd1=0x5b;   /* OVLAY 代码 */
      wdadd1=0x00;   /* 设置参数:显示一,三区为文本属性 */
      wcadd1=0x59;   /* 显示状态设置 */
      wdadd1=0x54;   /* 设置参数:显示一~四区开显示 */
  }	  
 CLEAR()
  {
    unsigned int i,j;
    wcadd1=0x4c;   /* CSRDIR 代码 */
    wcadd1=0x46;   /* CSRW 代码 */
    wdadd1=0x00;   /* 设置参数光标指针低8位 */
    wdadd1=0x00;   /* 设置参数光标指针高8位 */
    wcadd1=0x42;   /* MWRITE 代码 */
    for(j=0;j<2195;j++)
      {
        for(i=0;i<30;i++)
          {
            wdadd1=0x00;   /* 写入数据 */
          }
      }
  }
/*********************/
/*    清屏函数     */
/*********************/

/*图形方式显示*/
void PutCdotInGraph( Uint Ox,  Uint Oy, Uchar Cnumber, Uchar DotWidth )    //16	or24
{ 
Uint tempPtr,Optr;
Uchar tempCount1,tempCount2,nByte; 		
	Optr =Oy* para+Ox;
	nByte = DotWidth/8;		//2or3
	wcadd1= CsrDirD ;// 自动右移。	0x4f
	tempPtr = (Uint)Cnumber * DotWidth*nByte;
	for (tempCount1=0;tempCount1<nByte;tempCount1++) {

		wcadd1= CsrW ;			// 光标定位指令  0x46
		wdadd1 =Optr%256 ;		// 设置光标地址CSR
		wdadd1 = Optr /256 ;
	    wcadd1= mWrite ;						// ram写指令0x42
		
		switch(DotWidth){

			case 16:	for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
						wdadd1 = Cdotlib[Cnumber].Msk[tempCount2*2+tempCount1] ;		// 写入数据
						}
						break;
			case 24:	for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
						wdadd1 =Cdot24lib[tempPtr] ;		// 写入数据
						tempPtr += nByte;
						}
						break;
		}
		tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
		Optr++;
	}
}
delayms(unsigned char t)
{
unsigned char i;
for(i=0;i<100;i++)
for(;t!=0;t--);
}

 void main()
   {
   Uchar i,j;
   Uint s;
  	 delayms(1000);
     INT_1();   
	 CLEAR();  	 
	 while(1)	
	  {	
	  for(i=0;i<2;i++)
	  {wcadd1= CsrDirD ;
	  s=0x40*para+0x40  ;	  
	  wdadd1=s%256;
	  wdadd1=s/256;
	   wcadd1= mWrite ;
	   for(j=16*i;j<16*(i+1);j++)
	   	   { wdadd1= Cdotlib[0].Msk[j]	 ;
		   	   }
			   s++;	
			   }   
	/*PutCdotInGraph( 28, 30, 6, 16 );	// 调汉字写入子程序,0=设置汉字代码
	PutCdotInGraph( 30, 30, 7, 16 );	// 调汉字写入子程序,1=设置汉字代码
	PutCdotInGraph(	32, 30, 4, 16 );	// 调汉字写入子程序
	PutCdotInGraph( 34, 30, 5, 16 );	// 调汉字写入子程序
	PutCdotInGraph( 36, 30, 0, 16 );	// 调汉字写入子程序,0=设置汉字代码
	PutCdotInGraph( 38, 30, 1, 16 );	// 调汉字写入子程序,1=设置汉字代码
	*/
	delayms(100);
}

  }

⌨️ 快捷键说明

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