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

📄 24064b.c

📁 51单片机液晶显示模块源程序
💻 C
字号:
/****	TEST PROGRAM FOR 24064*****/
#include <reg51.h>
#include <intrins.h>

typedef unsigned char uchar;
typedef unsigned int  uint;

sbit	cd  = P2^0;  	/*通道选择,=1为指令通道,=0为数据通道*/
sbit	ce  = P2^7;	  /*低电平有效,T6963C片选信号*/
sbit	fs  = P3^5;	  /*字体选择*/
sbit	rst = P2^3;	  /*复位信号,低电平有效*/
sbit	rd  = P3^7;	  /*读操作,低电平有效*/
sbit	wr  = P3^6;	  /*写操作,低电平有效*/
sbit  test2 = P3^2;
sbit  test3 = P3^3;
sbit  test4 = P3^4;
sbit	sta0 = P0^0;
sbit	sta1 = P0^1;
sbit	sta2 = P0^2;
sbit	sta3 = P0^3;
sbit	sta4 = P0^4;
sbit	sta5 = P0^5;
sbit	sta6 = P0^6;
sbit	sta7 = P0^7;

sfr  lcdbus=0x80;	/*数据总线,P0口,DB0-DB7*/
bit d1500ms_flag = 0;

uint data i;
uchar data time0_number;
uchar code han0[] = {0x80,0x81,0x82,0x83};
uchar code han1[] = {0x84,0x85,0x86,0x87};
uchar code han2[] = {0x88,0x89,0x8a,0x8b};
uchar code han3[] = {0x8c,0x8d,0x8e,0x8f};
uchar code han4[] = {0x90,0x91,0x92,0x93};
uchar code han5[] = {0x94,0x95,0x96,0x97};
uchar code han6[] = {0x98,0x99,0x9a,0x9b};
uchar code han7[] = {0x9c,0x9d,0x9e,0x9f};
uchar code han8[] = {0xa0,0xa1,0xa2,0xa3};
uchar code han9[] = {0xa4,0xa5,0xa6,0xa7};
uchar code han10[] = {0xa8,0xa9,0xaa,0xab};
uchar code han11[] = {0xac,0xad,0xae,0xaf};
uchar code han12[] = {0xb0,0xb1,0xb2,0xb3};
uchar code han13[] = {0xb4,0xb5,0xb6,0xb7};
uchar code han14[] = {0xb8,0xb9,0xba,0xbb};
uchar code han15[] = {0xbc,0xbd,0xbe,0xbf};
uchar code han16[] = {0xc0,0xc1,0xc2,0xc3};
uchar code han17[] = {0xc4,0xc5,0xc6,0xc7};
uchar code han18[] = {0xc8,0xc9,0xca,0xcb};
uchar code han19[] = {0xcc,0xcd,0xce,0xcf};
uchar code han20[] = {0xd0,0xd1,0xd2,0xd3};
uchar code han21[] = {0xd4,0xd5,0xd6,0xd7};

uchar code TAB[] = 
	{
/*80*/	0x00,0x00,0x00,0x00,0xfc,0x8d,0x69,0x3a,
	      0x00,0x00,0x80,0xc0,0x8c,0xf4,0x4c,0x58,
	      0x38,0x6c,0xc1,0x03,0x1e,0x00,0x00,0x00,
	      0xe0,0xb0,0x9c,0x0f,0x07,0x00,0x00,0x00,/*欢0*/
/*84*/	0x00,0x00,0x00,0x67,0x7e,0x04,0xf4,0x16,
	      0x00,0x00,0x00,0xc8,0x7c,0x6c,0x6c,0xe8,
	      0x17,0xff,0x83,0x00,0x00,0x00,0x00,0x00,
	      0x70,0x60,0xff,0x7f,0x0c,0x00,0x00,0x00,/*迎1*/
/*88*/	0x00,0x00,0x00,0x38,0xf7,0xf0,0x33,0x32,
	      0x00,0x00,0x60,0x60,0xfe,0x64,0xfc,0x6c,
	      0x33,0x33,0x30,0x31,0x3f,0x00,0x00,0x00,
	      0xfc,0xc0,0xf0,0x9f,0x07,0x02,0x00,0x00,/*使2*/
/*8c*/	0x00,0x00,0x08,0x0f,0x0c,0x0c,0x0f,0x0c,
	      0x00,0x00,0x02,0xff,0x63,0x63,0xff,0x63,
	      0x0f,0x18,0x18,0x38,0xf0,0x00,0x00,0x00,
	      0xff,0x63,0x63,0x63,0x63,0x43,0x00,0x00,/*用3*/
/*90*/	0x00,0x00,0x40,0xff,0xc7,0x44,0x5b,0x46,
	      0x00,0x00,0x00,0xfe,0x66,0xe6,0x86,0xe6,
	      0x7a,0x41,0x47,0x40,0x7f,0x00,0x00,0x00,
	      0x3e,0x86,0x86,0x06,0xfe,0x04,0x00,0x00,/*图4*/
/*94*/	0x00,0x00,0x00,0x7f,0x33,0x33,0xff,0xff,
	      0x00,0x00,0x00,0xc7,0x1c,0x00,0xc7,0xcc,
	      0x1b,0x1b,0x33,0xf3,0xc3,0x00,0x00,0x00,
	      0x30,0x01,0x07,0x1c,0xf8,0x00,0x00,0x00,/*形5*/
/*98*/	0x00,0x00,0x01,0x01,0x01,0x19,0x1f,0x18,
	      0x00,0x00,0x80,0xf0,0xfc,0x80,0xfc,0x0c,
	      0x1f,0x08,0x12,0x76,0xc4,0x00,0x00,0x00,
	      0xf8,0x08,0x4c,0x67,0x23,0x01,0x00,0x00,/*点6*/
/*9c*/	0x00,0x00,0x00,0xfd,0x67,0x68,0x79,0x6f,
	      0x00,0x00,0x60,0x60,0xff,0xe0,0xb0,0xfc,
	      0x6d,0x7b,0x67,0x60,0x60,0x40,0x00,0x00,
	      0xb0,0xfc,0xff,0x30,0x30,0x30,0x00,0x00,/*阵7*/
/*a0*/	0x00,0x10,0x30,0x70,0xb0,0x10,0x10,0x10,
	      0x00,0x00,0x18,0x24,0x46,0x42,0x02,0x06,
	      0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xf0,
	      0x06,0x0c,0x00,0x08,0x10,0x60,0x22,0x7e,/*12 8*/
/*a4*/	0x00,0x00,0x38,0x62,0x42,0x42,0x62,0x36,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,
	      0x18,0x1c,0x26,0x46,0x42,0x42,0x43,0x3e,
	      0x32,0x34,0x18,0x08,0x1c,0x24,0x26,0x47,/*8x 9*/
/*a8*/	0x00,0x00,0x06,0x08,0x10,0x20,0x20,0x60,
	      0x00,0x00,0x00,0x04,0x0c,0x14,0x14,0x24,
	      0x5e,0x62,0x42,0x43,0x43,0x42,0x62,0x3c,
	      0x24,0x44,0x44,0x7f,0x04,0x04,0x04,0x04,/*64 10*/
/*ac*/	0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
	      0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
	      0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
	      0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,/*....11*/
/*b0*/	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
	      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
	      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
	      0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,/*全黑12*/
/*b4*/	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*全白13*/
/*b8*/	0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*上边14*/
/*bc*/	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*下边15*/
/*c0*/	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左边16*/
/*c4*/	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右边17*/
/*c8*/	0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
	      0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左上18*/
/*cc*/	0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0xff,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右上19*/
/*d0*/	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xff,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*左下20*/
/*d4*/	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
	      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
	      0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xff /*右下21*/
	};
	
void r_st(uchar w);       
void wdata(bit cd_flag,uchar d);     /*数据写操作*/
void dmod(uchar x0,uchar x1,uchar c);
void smod(uchar x1,uchar c);
void nmod(uchar c);

/* 使用寄存0 组 */
#pragma REGISTERBANK(0)
void soft_10ms()
{
	register int i;
	for(i=0;i<711;i++);
}
/* 初始化 */  
void initcomm(void)
{
    IE=0;
    P0=0xff;	
    P1=0xff;    
    P2=0xff;    
    P3=0xff;
    TMOD=0x11;  
    TH0 = 0;    
    TL0 = 0;    
    TR0 = 1;
    ET0 = 1;    
    EA = 1;
}

/*  初始化 lcd240128      */
void initlcd(void)
{
    dmod(0x00,0x00,0x40);  /*文本显示区域首地址*/
    dmod(0x1e,0x00,0x41);  /*文本显示宽度和一行显示字节数*/
    dmod(0x00,0x08,0x42);  /*图形显示区域首地址*/
    dmod(0x1e,0x00,0x43);  /*图形显示宽度,一行显示所占字节*/
    dmod(0x03,0x00,0x22);  /*cgram首地址 00011 100000000 000 = 1c00h*/
    nmod(0xa7);            /*光标形状设置*/		
    nmod(0x80);            /*显示方式:逻辑“或”合成*/
    nmod(0x9c);            /*显示开关设置,开文本和图形显示*/
}
/* lcd 清0*/
void clear(void)
{
    dmod(0x00,0x00,0x24);        /*显示存储器首地址*/
    nmod(0xb0);                  /*自动写方式*/
    for (i = 0;i < 0x2000;i++)
    {
        r_st(3);                  /*等待自动写状态*/
        wdata(0,0);
    }
    nmod(0xb2);			 /*自动写结束*/
}
/****************************************************
 读状态字
 cd_flag = 1 读命令通到。 = 0 读数据通到。
 w = 0 指令读,写状态,   返回1 准备好 返回0 忙。  
 w = 1 数据读,写状态,   返回1 准备好 返回0 忙。
 w = 2 数据自动读状态,   返回1 准备好 返回0 忙。
 w = 3 数据自动写状态,   返回1 准备好 返回0 忙。
 w = 5 控制运行检测可能性,返回1 准备好 返回0 忙。  
 w = 6 屏读/栲贝出错状态, 返回1 正确 返回0 出错。
 w = 7 闪烁状态检测,     返回1 正常显示 返回0 关显示。 
******************************************************/
void r_st (uchar w)       
{
    uchar data i = 0;	    	
    uchar data c;     
    cd = 1;    
    lcdbus = 0xff;    
    ce = 0; 
    while(--i)
    {
        rd = 0;        
        c = lcdbus;        
        rd = 1;        
        ce = 1;
        if ((w==1)&&((c&3)==3))		
        return;
        if((w==3)&&(c&8))	   	
        return;         
    }
}

void wdata(bit cd_flag,uchar d)     /*数据写操作*/
{
    cd = cd_flag;
    lcdbus = d;
    ce = 0;     
    wr = 0;    
    wr = 1;    
    ce = 1;    
    cd = 0;
}

/*双参数指令*/
void dmod(uchar x0,uchar x1,uchar c)
{
    r_st(1);    
    wdata(0,x0);
    r_st(1);    
    wdata(0,x1);
    r_st(1);    
    wdata(1,c);
}

/*单参数指令*/
void smod(uchar x1,uchar c)
{
    r_st(1);    
    wdata(0,x1);
    r_st(1);    
    wdata(1,c);
}

/*无参数指令*/
void nmod(uchar c)
{
    r_st(1);    
    wdata(1,c);
}

/*************************************************************
建立CGRAM 函数(图形方式)
    *p 汉字库字符首地址
*************************************************************/
void cgram(uchar code *p)
{
    dmod(0x00,0x1c,0x24);
    nmod(0xb0);
    for (i=0;i<0x0400;i++)
        wdata(0,*p++);
    nmod(0xb2);        
}	

/*************************************************************
汉字写入函数(文本方式)
    o_y  Y 坐标(0-7)*2
    o_x  X 坐标(0-14)*2
    d_code 写入字符代码
*************************************************************/
void wri_ct(uchar code *p,uchar o_y,uchar o_x)
{
    uint c;
    c= o_y*0x1e+o_x;
    dmod(c,c>>8,0x24);
    smod(*p++,0xc0);
    smod(*p++,0xc0);
    c+=0x1e;
    dmod(c,c>>8,0x24);
    smod(*p++,0xc0);
    smod(*p++,0xc0);	
}

/****绘点子函数  o_y  Y 坐标(0-127)   o_x  X 坐标(0-239)****/
void wri_d(uchar o_y,uchar o_x)
{
    uint c;
    c=o_y*0x1e;
    dmod(c+(o_x/8),(c+(o_x/8)+0x0800)>>8,0x24);
    nmod((~(o_x%8))|0xf8);
}     
  	
/****   主函数   ****/
void main(void) using 0
{
    uchar ii,jj;
    ce = 1;    
    rst = 0;                 
    initcomm();              /*初始化*/
    for(i=0;i<0x1000;i++);
    rst = 1;                 /*复位*/
    fs  = 0;
    initlcd();               /*初始化 lcd240128 */
    clear();                 /* lcd 清0*/
    cgram(TAB);
    
    while(1)
    {
	for(ii=0;ii<4;ii++)
	{
		for(jj=0;jj<15;jj++)
		{
			wri_ct(han11,ii*2,jj*2);
	    }
	}
	for(ii=0;ii<150;ii++)
	{
		soft_10ms();
	}

	for(ii=0;ii<4;ii++)
	{
		for(jj=0;jj<15;jj++)
		{
			wri_ct(han12,ii*2,jj*2);
		}
	}
	for(ii=0;ii<150;ii++)
	{
		soft_10ms();
	}

	for(ii=0;ii<4;ii++)
	{
		for(jj=0;jj<15;jj++)
		{
			wri_ct(han13,ii*2,jj*2);
		}
	}
	wri_ct(han0,2,3);	
	wri_ct(han0,4,3);
	wri_ct(han1,2,6);	
	wri_ct(han1,4,6);
	wri_ct(han2,2,9);	
	wri_ct(han2,4,9);
	wri_ct(han3,2,12);	
	wri_ct(han3,4,12);
	wri_ct(han4,2,15);	
	wri_ct(han4,4,15);
	wri_ct(han5,2,18);	
	wri_ct(han5,4,18);
	wri_ct(han6,2,21);	
	wri_ct(han6,4,21);
	wri_ct(han7,2,24);	
	wri_ct(han7,4,24);
	
	for(jj=0;jj<15;jj++)
	{
		wri_ct(han14,0,jj*2);
	}
	for(jj=0;jj<15;jj++)
	{
		wri_ct(han15,6,jj*2);
	}
	for(jj=0;jj<4;jj++)
	{
		wri_ct(han16,jj*2,0);
	}
	for(jj=0;jj<4;jj++)
	{
		wri_ct(han17,jj*2,28);
	}
	
	wri_ct(han18,0,0);	
	wri_ct(han19,0,28);
	wri_ct(han20,6,0);	
	wri_ct(han21,6,28);
	for(ii=0;ii<150;ii++)
	{
		soft_10ms();
	}   
    }//while(1)
}//main()

⌨️ 快捷键说明

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