用51单片机来驱动12232液晶
    

上排屏幕和下排屏幕重复我就不说了。字体难看我就不说了。这个液晶真是烦人啊,引脚定义都是反的……唉………先放个程序。发现如何setpage,set到0、1没问题,2、3就显示不出了。真不知道是我的错还是液晶的错。无论是左还是右都一样。

这个是模拟8080时序的,比6800稍微简单。在STC89C52 @ 11.0592下通过。

这块液晶最后还让我用串口进行调试了,晕。






这个液晶真是……哎……

好吧。附上真正的引脚定义(淘宝卖家那个害死我了):

GND VCC Vo A0 CS1 CS2 CLK(2KHZ的时钟输入) RD WR DB0~DB7 RST LED+ LED-

注意在5V系统上用的时候LED+需要串个20~47R的电阻。要不然会严重发热。

CLK不能直接接单片机的ALE脚,否则不会有任何显示(那个是2M)

RESET无法拉高所以6800时序没法用。只能用8080时序。

貌似上下两排显示公用一个VRAM。我现在还没找到解决显示重复的办法……

顺带提醒一下,这个液晶的视角很窄,所以更加建议使用3块钱紫晶的。更便宜更好用,资料也比较齐全。

全部的完整源代码从http://www.51hei.com/f/12232ces.rar 这里下载

/*------
 *FILE main.c
 * 测试驱动12232
 * 万致远@rwzy.co.cc
 */
#include <at89x52.h>
#include <type-def.h>
#include <stdio.h>
/*-----DEVICE IO Pin map.
* NMTB-S000389FGHSAY-A
* 死马当活马医吧!!!
* 时序68 series 	*/
//仿二进制赋值
#define  HEX__(n)   0x##n##UL
#define  B8__(x)   ( (x & 0x0000000FUL) ? 1:0 )\
    +( (x & 0x000000F0UL) ? 2:0 )\
    +( (x & 0x00000F00UL) ? 4:0 )\
    +( (x & 0x0000F000UL) ? 8:0 )\
    +( (x & 0x000F0000UL) ? 16:0 )\
    +( (x & 0x00F00000UL) ? 32:0 )\
    +( (x & 0x0F000000UL) ? 64:0 )\
    +( (x & 0xF0000000UL) ? 128:0 )
#define  B8(x)                                     ((unsigned char)B8__(HEX__(x)))
#define  B16(x_msb,x_lsb)                (((unsigned int)B8(x_msb)<<8) + B8(x_lsb))
#define  B32(x_msb,x_2,x_3,x_lsb)   (((unsigned long)B8(x_msb)<<24) + ((unsigned long)B8(x_2)<<16) + ((unsigned long)B8(x_3)<<8) + B8(x_lsb))
#define TH		0xFE
#define TL		0x40//2K定时器值

#define LCD_RESET        0xE2    //复位 
#define LCD_DISPLAY_ON	 0xAF    //显示开 
#define LCD_DISPLAY_OFF	 0xAE	 //显示关 
#define LCD_PS_ON   	 0xA5    //节电驱动    
#define LCD_PS_OFF  	 0xA4	 //正常驱动 
#define LCD_DUTY16       0xA8    //占空比1/16 
#define LCD_DUTY32       0xA9	 //占空比1/32 
#define LCD_END          0xEE 
#define LCD_RWMODE       0xE0 
#define LCD_LINE0        0xC0     //开始行 
#define LCD_PAGE0        0xB8     //开始页 
#define LCD_COLUMN0      0x00	  //开始列 
#define Both_Write_Cmd(cmd) LCD_Write(0,0,cmd);LCD_Write(1,0,cmd)
#define Both_Write_Data(dat) LCD_Write(0,1,dat);LCD_Write(1,1,dat)
#define CLK		P1_3
#define RESET	P1_6
#define A0		P1_0
#define E1		P1_2
#define E2		P1_1
#define LCD_RD		P1_4	
#define LCD_WR		P1_5	
#define DATA	P0

//渣字库,从16x8转到8x8
unsigned char __code ASCII[][8]={
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0xE,0xFF,0xFF,0xE,0x0,0x0},
{0x0,0x3,0x7,0x0,0x0,0x7,0x3,0x0},
{0x8,0xFE,0xFE,0x8,0xFE,0xFE,0x8,0x0},
{0xE,0x9F,0x91,0x91,0x91,0xF3,0x66,0x0},
{0x8C,0xC,0x40,0x60,0x30,0x98,0x8C,0x0},
{0x60,0xF6,0x9F,0xB9,0x6F,0xF6,0x90,0x0},
{0x0,0x4,0x7,0x3,0x0,0x0,0x0,0x0},
{0x0,0x0,0x7C,0x7E,0x83,0x81,0x0,0x0},
{0x0,0x0,0x81,0x83,0x7E,0x7C,0x0,0x0},
{0x20,0x28,0x78,0x70,0x70,0x78,0x28,0x20},
{0x0,0x20,0x20,0x78,0x78,0x20,0x20,0x0},
{0x0,0x0,0x0,0x80,0x80,0x0,0x0,0x0},
{0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0},
{0x0,0x0,0x0,0x80,0x80,0x0,0x0,0x0},
{0x80,0x0,0x40,0x60,0x30,0x18,0xC,0x0},
{0x7C,0x7E,0x83,0xB1,0x83,0x7E,0x7C,0x0},
{0x0,0x84,0x86,0xFF,0xFF,0x80,0x80,0x0},
{0x82,0xC3,0xE1,0xB1,0x99,0x8F,0x86,0x0},
{0x2,0x83,0x91,0x91,0x91,0xFF,0x6E,0x0},
{0x30,0x38,0x2C,0xA6,0xFF,0xFF,0xA0,0x0},
{0x1F,0x9F,0x91,0x91,0x91,0xF1,0x61,0x0},
{0x7C,0xFE,0x93,0x91,0x91,0xF0,0x60,0x0},
{0x3,0x3,0xC1,0xE1,0x31,0x1F,0xF,0x0},
{0x6E,0xFF,0x91,0x91,0x91,0xFF,0x6E,0x0},
{0xE,0x9F,0x91,0x91,0x91,0x7F,0x7E,0x0},
{0x0,0x0,0x0,0xC,0xC,0x0,0x0,0x0},
{0x0,0x0,0x80,0x8C,0xC,0x0,0x0,0x0},
{0x0,0x20,0x70,0x58,0xC,0x86,0x82,0x0},
{0x0,0x48,0x48,0x48,0x48,0x48,0x48,0x0},
{0x0,0x82,0x86,0xC,0x58,0x70,0x20,0x0},
{0x6,0x7,0x1,0xF1,0xF9,0xF,0x6,0x0},
{0x7C,0xFE,0x82,0xF2,0xF2,0xFE,0x7C,0x0},
{0xF8,0xFC,0x26,0x23,0x26,0xFC,0xF8,0x0},
{0x81,0xFF,0xFF,0x91,0x91,0xFF,0x6E,0x0},
{0x7C,0x7E,0x83,0x81,0x81,0x83,0x6,0x0},
{0x81,0xFF,0xFF,0x81,0x83,0x7E,0x7C,0x0},
{0x81,0xFF,0xFF,0x91,0xB9,0x83,0x87,0x0},
{0x81,0xFF,0xFF,0x91,0x39,0x3,0x7,0x0},
{0x7C,0x7E,0x83,0xA1,0xA1,0x63,0xE6,0x0},
{0xFF,0xFF,0x10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0xF0,0x98,0x89,0x7F,0xFF,0x80,0x0},
{0x70,0xF8,0xA8,0xA8,0xA8,0xB8,0x30,0x0},
{0x90,0xFE,0xFF,0x91,0x3,0x6,0x0,0x0},
{0x70,0xF8,0x88,0x88,0xF0,0xF8,0x8,0x0},
{0x81,0xFF,0xFF,0x10,0x8,0xF8,0xF0,0x0},
{0x0,0x0,0x88,0xFB,0xFB,0x80,0x0,0x0},
{0x0,0x0,0x0,0x0,0x8,0xFB,0xFB,0x0},
{0x81,0xFF,0xFF,0x60,0x70,0x98,0x88,0x0},
{0x0,0x0,0x81,0xFF,0xFF,0x80,0x0,0x0},
{0xF8,0xF8,0x18,0x70,0x18,0xF8,0xF0,0x0},
{0x8,0xF8,0xF0,0x8,0x8,0xF8,0xF0,0x0},
{0x70,0xF8,0x88,0x88,0x88,0xF8,0x70,0x0},
{0x8,0xF8,0xF0,0x88,0x88,0xF8,0x70,0x0},
{0x70,0xF8,0x88,0x88,0xF0,0xF8,0x8,0x0},
{0x88,0xF8,0xF0,0x98,0x8,0x38,0x30,0x0},
{0x10,0xB8,0xE8,0xC8,0xC8,0x98,0x10,0x0},
{0x8,0x8,0x7E,0xFF,0x88,0x88,0x0,0x0},
{0x78,0xF8,0x80,0x80,0x78,0xF8,0x80,0x0},
{0x0,0x78,0x78,0x80,0x80,0x78,0x78,0x0},
{0x78,0xF8,0x80,0x60,0x80,0xF8,0x78,0x0},
{0x88,0x98,0x70,0x60,0x70,0x98,0x88,0x0},
{0x78,0xF8,0x80,0x80,0x80,0xF8,0xF8,0x0},
{0x98,0x98,0xC8,0xE8,0xB8,0x98,0x88,0x0},
{0x0,0x10,0x10,0x7E,0xEF,0x81,0x81,0x0},
{0x0,0x0,0x0,0xEF,0xEF,0x0,0x0,0x0},
{0x0,0x81,0x81,0xEF,0x7E,0x10,0x10,0x0},
{0x2,0x3,0x1,0x3,0x2,0x3,0x1,0x0}
};
void OutCLK() __interrupt 1 __using 1//CLK out 2kHz
{
	TF0=0;//CLR
	TR0=0;
	EA=0;
	TH0=TH;TL0=TL;
	CLK=!CLK;
	TR0=1;
	EA=1;
}
void Delay_ms(UINT x)
{
	UINT y;
	while(x--)
	{
		for(y=0;y<600;y++);
	}
}
void Init_Timer()
{
	TMOD=0x21;//T0计数器模式,T1八位重载模式
	TH0=TH;
	TL0=TL;
	TR0=1;
	ET0=1;
	SCON = 0x50;
	TH1  = 0xFF;   //57600
	TL1  = 0xFF;         
	TR1	 =	1;
	PCON=PCON|0x80;//波特率加倍
	EA=1;
}
void putchar(char s)
{
	SBUF=s;
	while(!TI);
	TI=0;
}

BYTE Read_Status(BOOL right)
{
	BYTE tData;
	DATA=0xff;
	LCD_WR=1;
	LCD_RD=0;
	A0=0;
	if(right)
	{
		E1=0;
	}
	else
	{
		E2=0;
	}
	tData=DATA;
	if(right)
	{
		E1=1;
	}
	else
	{
		E2=1;
	}
	LCD_RD=1;
	A0=1;
	return tData;
}

void LCD_Write(BOOL right,BOOL disp,BYTE Data)
{//模拟8080
	/*BYTE rTemp=0xff;
	while(rTemp & 0x7F)
	{
		rTemp=Read_Status(right);
	}*/
	if(right)
	{
		E1=0;
	}
	else
	{
		E2=0;
	}
	A0=disp;//disp=1数据,disp=0显示
	P0=Data;
	LCD_RD=1;
	LCD_WR=0;
	__asm
	NOP
	__endasm;
	LCD_WR=1;
	if(right)
	{
		E1=1;
	}
	else
	{
		E2=1;
	}
	__asm
	NOP
	NOP
	NOP
	NOP
	NOP
	__endasm;
}

BYTE LCD_Read(BOOL right)
{//模拟8080
	BYTE tData;
	if(right)
	{
		E1=0;
	}
	else
	{
		E2=0;
	}
	P0=0xFF;
	LCD_WR=1;
	LCD_RD=0;
	tData=P0;
	LCD_RD=1;
	if(right)
	{
		E1=1;
	}
	else
	{
		E2=1;
	}
	return tData;
}

void SetPage(BYTE page0,BYTE page1)
{
LCD_Write(0,0,0xB8|page1);
LCD_Write(1,0,0xB8|page0);
}

void SetAddress(BYTE address0,BYTE address1)
{
LCD_Write(0,0,address1);
LCD_Write(1,0,address0);
}

void clrscr(void)
{
	BYTE i;
	BYTE page;
	for (page=0;page<4;page++)
	{
		SetPage(page,page);
		SetAddress(0,0);
		for (i=0;i<61;i++)
		{
			Both_Write_Data(0x00);
		}
	}
}

void Init_LCD()
{
	RESET=1;
	RESET=0;//8080时序
	printf("Status(Chip1):0x%X\n",Read_Status(0));
	printf("Status(Chip2):0x%X\n",Read_Status(1));
	Both_Write_Cmd(LCD_RESET);//软复位
	printf("Status(Chip1):0x%X\n",Read_Status(0));
	printf("Status(Chip2):0x%X\n",Read_Status(1));
	Both_Write_Cmd(LCD_PS_OFF);//正常驱动
	Both_Write_Cmd(LCD_DISPLAY_ON);//开显示
	Both_Write_Cmd(LCD_DUTY16);//32%占空比
	printf("Status(Chip1):0x%X\n",Read_Status(0));
	printf("Status(Chip2):0x%X\n",Read_Status(1));
}
/*
 * CODE: A0 /RD /WR D7   D6    D5    D4   D3 D2 D1 D0
		  L   L   H BUSY ADC ON/OFF RESET LLLL
*/

void Draw8(BOOL right,BYTE Asc)
{
	BYTE i;
	for(i=0;i<8;i++)
	{
		LCD_Write(right,1,ASCII[Asc-32][i]);
	}
}
void printstr(BOOL right,BYTE *str)
{
	while(*str!='\0')
	{
		Draw8(right,*str);
		str++;
	}
}
void main()
{  
	BYTE i;
	BYTE page;
	Init_Timer();//启动定时器
	printf("System started.\n");
	Init_LCD();
	//Set_xyPos_LCD(0,0);
	//LCD_Write(0,1,0xff);
	//printstr("THELL");
	clrscr();
		page=0;
		SetPage(page,page);
		SetAddress(0,0);
		/*for (i=0;i<61;i++)
		{
			Both_Write_Data(0xFF);
		}*/
		printstr(0,"Hello");
		page=1;
		SetPage(page,page);
		SetAddress(0,0);
		printstr(0,"world!");
		
		page=2;
		SetPage(page,page);
		SetAddress(0,0);
		printstr(0,"are you?");
    while(1)
    {
		
	}
}

相关阅读
  • LCD1602.h和LCD1602.c文件下载(51
  • 真正的实时操作系统,如何用51单片
  • 用51单片机的外部中断来测频率
  • 基于51单片机设计的TFT液晶显示
  • 基于51单片机的tft液晶显示设计
  • 基于51单片机设计的tft液晶显示
  • 基于51单片机的TFT液晶显示设计
  • 单片机驱动19264液晶显示汉字c程序
  • 51单片机驱动步进电机
  • 51单片机驱动步进电机电路及汇编程
  • 拿来就用单片机的内容简介
  • HT1621液晶驱动芯片的51单片机程序
  • 51单片机驱动步进电机电路及程序
  • 单片机驱动ds1302时间ds18b20温度1
  • 单片机驱动DS1302时间DS18B20温度1
  • 51单片机驱动步进电机(汇编语言)
  • 51单片机驱动ds1302程序(12864液晶
  • 【程序】51单片机驱动步进电机电路
  • 用单片机中断来扫描键盘的程序
  • 利用MCS51单片机驱动步进电机电路
  • 利用mcs51单片机驱动步进电机电路
  •  



     
     
         

    收录时间:2016年10月19日 19:13:34 来源:单片机教程网 作者:匿名
    上一篇:高低优先级中断应用举例(51单片机)  (电脑版  手机版)
     
    创建分享人
    大漠沙如雪
    最新问题
     
    喜欢此文章的还喜欢
    Copyright by www.chinabaike.com;All rights reserved. 联系:QQ:469681782