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

📄 display.c

📁 显示模块,利用51单片机UART口通讯
💻 C
📖 第 1 页 / 共 2 页
字号:
}
/*-----------------------数字点阵转换成灰度矩阵-------------------------*/
void MatrixConvertEN(uchar DotEN[16*10][2],uchar Num)
{
	uchar i,j;
	uchar xdata tmp[16][2];

	for(i=0;i<16;i++)
	{
		for(j=0;j<2;j++)
		{
			tmp[i][j] = DotEN[16*Num + i][j];
		}
	}

	MatrixConvert(tmp);
}
/*-----------------------汉字点阵转换成灰度矩阵--------------------------*/
void MatrixConvert(uchar DotHZ[16][2])
{
	uchar i,j,k,temp;
	bit Flag;
	
	for(i=0;i<16;i++)
	{
		for(j=0;j<2;j++)
		{
			temp = DotHZ[i][j];
			if(j == 0)
			{
				for(k=0;k<8;k++)
				{
					Flag = Odd_Even(k);
					if((temp & 0x80) == 0x80)//bit = 1
					{
						if(Flag)//odd
						{
							HZbuff[i][k/2] |= 0x0f;
						}
						else//Even
						{
							HZbuff[i][k/2] |= 0xf0;
						}
					}
					else//bit = 0
					{
						if(Flag)//odd, low 4 bit
						{
							HZbuff[i][k/2] &= 0xf0;
						}
						else//Even,high 4 bit
						{
							HZbuff[i][k/2] &= 0x0f;
						}
					}
					temp <<= 1;
				}
			}
			else
			{
				for(k=0;k<8;k++)
				{
					Flag = Odd_Even(k);
					if((temp & 0x80) == 0x80)//bit = 1
					{
						if(Flag)//odd
						{
							HZbuff[i][k/2+4] |= 0x0f;
						}
						else//Even
						{
							HZbuff[i][k/2+4] |= 0xf0;
						}
					}
					else//bit = 0
					{
						if(Flag)//odd, low 4 bit
						{
							HZbuff[i][k/2+4] &= 0xf0;
						}
						else//Even,high 4 bit
						{
							HZbuff[i][k/2+4] &= 0x0f;
						}
					}
					temp <<= 1;
				}
			}
		}
	}
}
/*--------------------------判断奇偶数-----------------------------*/
bit Odd_Even(uchar A)
{
	bit Flag;
	uchar temp;
	temp = A/2;
	temp = A - temp*2;
	if(temp == 0){Flag = 0;}
	else{Flag = 1;}
	return Flag;
}
/*--------------------------确定显示区域---------------------------*/
void PsetCH(uchar X,uchar Y)
{
	write_command (0x15);	    //COLUMN ADDRESS
	write_command (0x00 + X);	//START ADDRESS
	write_command (0x07 + X);	//END ADDRESS
	
	write_command (0x75);	    //ROW ADDRESS
	write_command (0x00 + Y);	//START ADDRESS
	write_command (0x0F + Y);	//END ADDRESS
}
/*--------------------------OLED复位-------------------------------*/
void oled_initial()
{
	RST = 1;
	RST = 0;				//Reset Driver IC
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	RST = 1;
}
/*---------------------------OLED初始化-----------------------------*/
void sub_comm()
{
	write_command (0x15);	//COLUMN ADDRESS
	write_command (0x00);	//START ADDRESS
	write_command (0x3F);	//END ADDRESS
	
	write_command (0x75);	//ROW ADDRESS
	write_command (0x00);	//START ADDRESS
	write_command (0x3F);	//END ADDRESS

	write_command (0x81);	//CONTRAST SETTING
	write_command (0x66);	//80% BRIGHTNESS

	write_command (0x84);	//LOW CURRENT

	write_command (0xA0);	//REMAP SETTING
	//write_command (0x52);	//ENEABLED COM SPLIT ODD EVEN,
	write_command (0x41);	//COM REMAP & NIBBLE REMAP

	write_command (0xA1);	//DISPLAY START LINE SETTING
	write_command (0x00);	//START ROW 0

	write_command (0xA2);	//SET DISPLAY OFFSET SETTING
	write_command (0x3F);	//OFFSET 64 ROWS

	write_command (0xA4);	//NORMAL DISPLAY (DEFAULT)
	
	write_command (0xA8);	//MULTIPLEX RATIO SETTING
	write_command (0x3F);	//64 MUX

	write_command (0xB2);	//SET ROW PERIOD
	write_command (0x46);	//70d

	write_command (0xAD);	//DC-DC
	write_command (0x02);	//DISABLE DC-DC
	
	write_command (0xCF);	//SET BIAS CURRENT SETTING
	write_command (0xF0);	//HIGH LEVEL (DEFAULT)
	
	write_command (0xAF);	//DISPLAY ON

	write_command (0xB3);	//DISPLAY CLOCK DIVIDE RATIO & OSC FREQ SETTING
	write_command (0xF1);	//77 Hz FRAME RATE

	write_command (0xB1);	//PHASE SETTING
	write_command (0x22);	//PHASE 1=2 PHASE 2=2

	write_command (0xBF);	//VSL
	write_command (0x0D);	//2.2V
	
	write_command (0xBE);	//VCOMH
	write_command (0x00);	//0.51*VREF=0.51*12.5V=6.375V

	write_command (0xBC);	//VP
	write_command (0x10);	//0.67*VREF=0.67*12.5V=8.375V

	write_command (0xB8);	//GRAYSCALE SETTING
	write_command (0x01);	//L1=1
	write_command (0x11);	//L2=1,L3=1
	write_command (0x22);	//L4=2,L5=2
	write_command (0x32);	//L6=2,L7=3
	write_command (0x43);	//L8=3,L9=4
	write_command (0x54);	//L10=4,L11=5
	write_command (0x65);	//L12=5,L13=6
	write_command (0x76);	//L14=6,L15=7
}
/*--------------------------清除显示RAM数据--------------------------*/
void clear_RAM()
{
	int i;
	write_command (0x15);	//COLUMN ADDRESS
	write_command (0x00);	//LOWER ADDRESS
	write_command (0x3F);	//HIGHER ADDRESS
	
	write_command (0x75);	//ROW ADDRESS
	write_command (0x00);	//LOWER ADDRESS
	write_command (0x4F);	//HIGHER ADDRESS
	
	for(i=0;i<64*64;i++)    //128 col x 64 row
		{
			data_out(0X00);
		}
}
/*--------------------------数据写入指令----------------------------*/
void data_out(uchar dat)
{
	CST		=	0;//H
	DC		=	1;
	WRT		=	0;
	READ	=	1;
	CST		=	1;//L
	P0		=	dat;
	CST		=	0;//H
	WRT		=	1;
	DC		=	1;
}
/*--------------------------命令写入指令----------------------------*/
void write_command(uchar dat)
{
	CST		=	0;//H
	DC		=	0;
	WRT		=	0;
	READ	=	1;
	CST		=	1;//L
	P0		=	dat;
	CST		=	0;//H
	WRT		=	1;
	DC		=	1;
}
/*--------------------------延时程序---------------------------------*/
void delay (uint counter)
{
		int i,j;
		for(i=0;i<500;i++)
		{
			for(j=0;j<counter;j++){}
		}
}
/*****************************************************************************/
/*                             汉字点阵数据                                  */
/*****************************************************************************/
unsigned char code Num[16*10][2] =
{
/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,

/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x01,0x00,0x03,0x00,0x05,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x07,0xC0,0x00,0x00,

/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x10,0x00,0xE0,
0x03,0x00,0x04,0x00,0x08,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,

/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x0F,0xE0,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x20,0x00,0x40,0x01,0x80,
0x00,0x40,0x00,0x20,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x20,0x0F,0xC0,0x00,0x00,

/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x01,0x80,0x02,0x80,0x02,0x80,0x02,0x80,0x04,0x80,0x04,0x80,0x08,0x80,
0x08,0x80,0x10,0x80,0x20,0x80,0x3F,0xF0,0x00,0x80,0x00,0x80,0x03,0xE0,0x00,0x00,

/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x1F,0xF0,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x17,0xC0,0x18,0x20,
0x10,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x20,0x0F,0xC0,0x00,0x00,

/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x17,0xC0,
0x18,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,

/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x00,0x20,0x00,0x20,0x00,0x40,0x00,0x80,
0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,

/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x20,0x07,0xC0,
0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00,

/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x07,0xC0,0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x30,
0x07,0xD0,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x10,0x08,0x20,0x07,0xC0,0x00,0x00
};
/*----------------------------------------------------------------------------*/
unsigned char code na[16][2] =
{
/*--  文字:  南  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,0x02,0x00,0x3F,0xFC,0x24,0x24,0x22,0x44,
0x2F,0xF4,0x21,0x04,0x3F,0xFC,0x21,0x04,0x21,0x04,0x21,0x14,0x21,0x08,0x00,0x00
};
unsigned char code mo[16][2] =
{
/*--  文字:  无  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFE,0x01,0x80,
0x02,0x80,0x02,0x80,0x04,0x80,0x08,0x80,0x10,0x82,0x20,0x82,0xC0,0x7E,0x00,0x00
};
unsigned char code a[16][2] =
{
/*--  文字:  阿  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x7B,0xFE,0x48,0x08,0x50,0x08,0x60,0x08,0x53,0xE8,0x4A,0x28,0x4A,0x28,
0x4A,0x28,0x6B,0xE8,0x50,0x08,0x40,0x08,0x40,0x08,0x40,0x08,0x40,0x28,0x40,0x10
};
unsigned char code mi[16][2] =
{
/*--  文字:  弥  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x80,0x7C,0xC0,0x04,0x80,0x05,0xFE,0x7D,0x04,0x41,0x28,0x42,0x20,0x40,0xB0,
0x7C,0xA8,0x05,0x24,0x05,0x26,0x06,0x24,0x04,0x20,0x04,0x20,0x28,0xA0,0x10,0x40
};
unsigned char code tuo[16][2] =
{
/*--  文字:  陀  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x40,0x78,0x20,0x48,0x20,0x53,0xFE,0x62,0x04,0x50,0x80,0x48,0x80,0x48,0x98,
0x48,0xE0,0x68,0x80,0x50,0x80,0x40,0x84,0x40,0x84,0x40,0x84,0x40,0x7C,0x40,0x00
};
unsigned char code fo[16][2] =
{
/*--  文字:  佛  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x08,0x90,0x08,0x90,0x17,0xFC,0x10,0x94,0x30,0x94,0x37,0xFC,0x54,0x90,0x94,0x90,
0x17,0xFE,0x10,0x92,0x10,0x92,0x11,0x1A,0x11,0x14,0x12,0x10,0x12,0x10,0x14,0x10
};



⌨️ 快捷键说明

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