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

📄 hx8310tft.c

📁 手机常用的TFT液晶驱动器HX8310驱动程序,该程序为完整的演示程序,其中核心部分作为模块已经在产品中大量应用.
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************/
/*                                                                     */
/*  FILE        :hx8310tft.c                                           */
/*  DATE        :Sun, Jan 01, 2006                                     */
/*  DESCRIPTION :Main Program                                          */
/*  CPU TYPE    :H8/36064                                              */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.0).     */
/*                                                                     */
/***********************************************************************/
///////程序基本编写完毕, 只有简单的显示功能, 以后再扩展

/*
本程序是128*160 TFT	 显示器演示驱动程序, 控制器为HX8310A
驱动器接口为18线方式, 一次输出一点显示数据, 262144色数据
本程序只进行基本的显示驱动, 细化的功能使用, 请参考数据手册和本程序进行重新编程使用

芯片具有从上向下顺序显示的功能, 也有从下向上显示的功能, 所以对于BMP转换来的数据, 不必倒转就可以直接使用
*/              

#include "iodefine.h"
#include <machine.h>
#include "hx8310tft.h"

#include "tupian.h"


#ifdef __cplusplus
extern "C" {
void abort(void);
#endif
void main(void);
#ifdef __cplusplus
}
#endif

void main(void)
{
	uint i;
	nop();
	nop();
main_1:
	CLOSE_WATCHDOG();
	ini_ram();	//RAM初始化,主要写入0外的数据
	ini_pp();	//端口及外围功能初始化
	buzzeron();
		ram_CE=1;
		lcm_CE=1;
		lcm_WR=1;
		lcm_RD=1;
		lcm_RST=1;
//对扩展 RAM 操作
/*
	set_imask_ccr(1);
	for (i=0;i<32767;i++)
	{
		wr_ram_rand(0x55,i);
		if (rd_ram_rand(i)!=0x55)
		{
			nop();
		}
		else
		{
		}
	}
*/
	//set_imask_ccr(1);
	//显示处理
	ini_lcm();
	for(;;) 
	{
//		emi_p();
		CLOSE_WATCHDOG();
		//不对LCM操作时,主流程定时置这些口的状态,以免出错
		display();
	}
}

#ifdef __cplusplus
void abort(void)
{
	
}
#endif


//-----------------------------------------------------
//清RAM
//-----------------------------------------------------
void ini_ram(void)
{
	gflg1=0;
	disp_pro_flg=0;

}

//-----------------------------------------------------
//外围功能初始化
//端口   0---input    1:output
//		7	6	5	4	3	2	1	0
//P1	1	1	1	1	/	1	1	1
//P2	/	/	/	1	1	1	1	1
//P3	1	1	1	1	1	1	1	1
//P5	1	1	1	1	1	1	1	1
//P6	1	1	1	1	1	1	1	1
//P7	/	1	1	1	/	1	1	1
//P8	0	0	0	/	/	/	/	/
//PB	0	0	0	0	0	0	0	0
//TV: 暂不用
//TW: 定时
//外中断: 无
#define DEFA_PCR 0xff	//P1口初始化置, 因为P1.5 P1.1 P1.0方向运行中会改变, 所以设置一个默认值,剩余的与之与/或处理
//-----------------------------------------------------
void ini_pp(void)
{
	portmr1 =0x00;	//0b00001010;	//TXD TXD2
	PORT1 =0xff;	//0b
	portcr1 =DEFA_PCR;	//0b11111111;	//方向
	portur1=0x00;	//0b00000000;

	PORT2 =0xff;	//0b
	portcr2 =0xff;	//0b11111111;	//方向

	PORT3 =0xff;	//0b
	portcr3 =0xff;	//0b11111111;	//方向

	portmr5 =0x00;	//0b00000000;	//为普通IO
	PORT5 =0xff;	//0b
	portcr5 =0xff;	//0b11111111;	//方向
	portur5=0x00;	//0b00000000;

	PORT6 =0xf1;	//0b11110001;
	portcr6 =0xff;	//0b11111111;	//方向

	PORT7 =0xff;	//0b
	portcr7 =0xff;	//0b11111111;	//方向

	PORT8 =0xffb;	//0b
	portcr8 =0x00;	//0b00000000;	//方向

/*
//TIMERV初始化
//输出2.5K频率 驱动蜂鸣器
	TV.TCNTV=0;
	TV.TCRV0.BYTE=0x0b;	//0b00001011;	//与A匹配 计数器清0  输入脉冲为1/64振荡频率
	TV.TCORA=50;			//2.5K比较常数
	TV.TCORB=25;			//在50%时与B比较匹配, 则获得了50%占空比
*/
	TV.TCORA=2500;		//与输入脉冲分频情况配合(64分频), 这里每1/1800秒中断1次
	TV.TCRV0.BYTE=0x4b;		//01001011	与A比较符合后中断允许
	TV.TCRV1.BYTE=0xE2;		//11100010---
	TV.TCSRV.BYTE=0x10;		//00010000
	TV.TCNTV=0;
/*
	TV.TCRV0.BYTE=0x26;		//溢出中断
	TV.TCRV1.BYTE=0x01;		//
	TV.TCSRV.BYTE=0x00;		//
	TV.TCNTV=0x00;
*/
/*
	IRR2.BIT.IRRTB1=0;
	TB1.TLB1=178;
	TB1.TCB1=0;
	TB1.TMB1.BYTE=0xF9;
*/
/*
//TIMERW初始化
//定时20毫秒,定时计时
	TW.GRA=0xffff;
	TW.GRB=0xffff;
	TW.GRC=0xffff;
	TW.GRD=0xffff;
	TW.TCNT=25536;	//20毫秒						//25536;		//20毫秒
	TW.TIOR0.BYTE=0x88;	//0b10001000;
	TW.TIOR1.BYTE=0x88;	//0b10001000;
	TW.TMRW.BYTE=0xc8;	//0b11001000;
	TW.TCRW.BYTE=0xa0;	//0b10100000; 4倍分频
	TW.TSRW.BYTE=0x70;	//0b01110000
	TW.TIERW.BYTE=0xf0;	//0b11110000;
	TW.TMRW.BIT.CTS=1;	//START
*/
/*
//ADC初始化
	AD.ADCSR.BYTE=0x12;	//00010010   SCAN模式 AN0~AN2通道
	AD.ADCR.BYTE =0x00;		//00000000
	AD.ADCSR.BIT.ADST=1;	//启动ADC
//SCI--1 初始化
//9600BPS 1个起始  1个停止 无校验
	SCI3.SCR3.BYTE=0x00;
	SCI3.SMR.BYTE=0x00;	//00000000  1 开始  1结束  8数据 内部1:1 无校验
	SCI3.BRR=51;		//9600BPS
	delayus(120);
	SCI3.SSR.BYTE=(SCI3.SSR.BYTE|0x80)&0x80;
	SCI3.SCR3.BYTE=0x50;	//接收允许  发送禁止 接收中断允许  发送中断禁止

//SCI--2 初始化
//9600BPS 1个起始  1个停止 无校验
	SCI3_2.SCR3.BYTE=0x00;
	SCI3_2.SMR.BYTE=0x00;	//00000000  1 开始  1结束  8数据 内部1:1 无校验
	SCI3_2.BRR=51;		//9600BPS
	delayus(120);
	SCI3_2.SSR.BYTE=(SCI3_2.SSR.BYTE|0x80)&0x80;
	SCI3_2.SCR3.BYTE=0x50;	//接收允许  发送禁止 接收中断允许  发送中断禁止

*/
//中断初始化
	set_imask_ccr(0);
}


//------------------------------------------------------------------
//显示输出函数
#define DIS_DLT		10
#define DIS_DLT1	6
//------------------------------------------------------------------
/*
void display(void)
{
	uchar i,j,k;
	uint m,n;
	nop();
dis_1:
//	ins_16b_h=0;
	ins_16b_l=0x21;
	wr_1word_index();
	ins_16b_h=0x00;
	ins_16b_l=0x00;	
	wr_1word_reg_data();
//	ins_16b_h=0;
	ins_16b_l=0x22;
	wr_1word_index();
	red_data_buf=0x30;
	gre_data_buf=0x00;
	blu_data_buf=0x00;
	for (i=0;i<160;i++)
	{
		for (j=0;j<128;j++)
		{
//			ins_16b_h=0;
//			ins_16b_l=0x22;
//			wr_1word_index();
			wr_1word_data();
			nop();
//			rd_1word_data();
		}
	}
	delays(2);
//	ins_16b_h=0;
	ins_16b_l=0x21;
	wr_1word_index();
	ins_16b_h=0x00;
	ins_16b_l=0x00;	
	wr_1word_reg_data();
//	ins_16b_h=0;
	ins_16b_l=0x22;
	wr_1word_index();
	red_data_buf=0x00;
	gre_data_buf=0x00;
	blu_data_buf=0x3f;
	for (i=0;i<160;i++)
	{
		for (j=0;j<128;j++)
		{
//			ins_16b_h=0;
//			ins_16b_l=0x22;
//			wr_1word_index();
			wr_1word_data();
			nop();
//			rd_1word_data();
		}
	}
	delays(2);
goto dis_1;
}
*/


void display(void)
{
	uchar i,j,q,t;
	volatile uchar k;
	uint m,n;
	switch (disp_pro_flg)
	{
		case 0:
			disp_pro_flg++;
			disp_dlt_ct=0;
			break;
		case 1:	//全亮
			ins_16b_h=0;
			ins_16b_l=0x21;
			wr_1word_index();
			ins_16b_h=0x00;
			ins_16b_l=0x00;	
			wr_1word_reg_data();
			ins_16b_h=0;
			ins_16b_l=0x22;
			wr_1word_index();
			red_data_buf=0x00;
			gre_data_buf=0x00;
			blu_data_buf=0x00;
			for (i=0;i<160;i++)
			{
				for (j=0;j<128;j++)
				{
//					ins_16b_h=0;
//					ins_16b_l=0x22;
//					wr_1word_index();
					red_data_buf=0x00+j/2;
					gre_data_buf=0x00+i/4;
					blu_data_buf=0x00+i/2;
					wr_1word_data();
//					rd_1word_data();
				}
			}
			disp_pro_flg++;
			nop();
			disp_dlt_ct=0;
			nop();
			break;
		case 2:	//全灭
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				red_data_buf=0x00;
				gre_data_buf=0x00;
				blu_data_buf=0x00;
				for (i=0;i<160;i++)
				{
					for (j=0;j<128;j++)
					{
//						wr_1word_data();
						rd_1word_data();
					}
				}
				nop();
				disp_pro_flg++;
				disp_dlt_ct=0;
				nop();
//			}
			break;
		case 3:	//红+白竖条纹
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<16;j++)
					{
						red_data_buf=0xff;
						gre_data_buf=0x00;
						blu_data_buf=0x00;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
						red_data_buf=0xff;
						gre_data_buf=0xff;
						blu_data_buf=0xff;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
					}
				}
				disp_pro_flg++;
				disp_dlt_ct=0;
				nop();
//			}
			break;
		case 4:	//绿+白竖条纹
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<16;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0xff;
						blu_data_buf=0x00;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
						red_data_buf=0xff;
						gre_data_buf=0xff;
						blu_data_buf=0xff;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
					}
				}
				disp_pro_flg++;
				nop();
				disp_dlt_ct=0;
				nop();
				nop();
//			}
			break;
		case 5:	//蓝+白竖条纹
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<16;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0x00;
						blu_data_buf=0xff;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
						red_data_buf=0xff;
						gre_data_buf=0xff;
						blu_data_buf=0xff;
						for (k=0;k<4;k++)
						{
							wr_1word_data();
						}
					}
				}
				disp_pro_flg++;
				nop();
				nop();
				nop();
				disp_dlt_ct=0;
				nop();
				nop();
				nop();
//			}
			break;
		case 6:	//图片1
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<2;i++)
				{//图像数据只是70行.
					n=0;
					for (m=0;m<128*70;m++)
					{
						red_data_buf=tupian1[n]>>2;
						n++;
						gre_data_buf=tupian1[n]>>2;
						n++;
						blu_data_buf=tupian1[n]>>2;
						n++;
						wr_1word_data();
					}
				}

				for (i=0;i<20;i++)
				{
					for (j=0;j<16;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0x00;
						blu_data_buf=0x00;
						wr_1word_data();
					}
					for (j=0;j<4;j++)
					{
						for (t=0;t<3;t++)
						{
							for (q=0;q<8;q++)
							{
								k=tupian2[j*60+t+i*3];
								k=k&(0x80>>q);
//								k=tupian2[j*60+t+i*3]&(0x80>>q);
								if (k==0) k=0x00;
								else k=0xff;
								red_data_buf=k;
								gre_data_buf=0x00;
								blu_data_buf=0x00;
								wr_1word_data();
							}
							
						}
					}
					for (j=0;j<16;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0x00;
						blu_data_buf=0x00;
						wr_1word_data();
					}
				}

				disp_dlt_ct=0;
				disp_pro_flg++;
				nop();
//			}
			break;
		case 7:	//
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<128;j++)
					{
						red_data_buf=0xff;
						gre_data_buf=0x00;
						blu_data_buf=0x00;
						wr_1word_data();
					}
				}
				disp_dlt_ct=0;
				nop();
				disp_pro_flg++;
				nop();
//			}
			break;

		case 8:	//
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<128;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0xff;
						blu_data_buf=0x00;
						wr_1word_data();
					}
				}
				disp_pro_flg++;
				nop();
				disp_dlt_ct=0;
				nop();
				disp_dlt_ct=0;
				nop();
//			}
			break;
		case 9:	//
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				ins_16b_h=0;
				ins_16b_l=0x21;
				wr_1word_index();
				ins_16b_h=0x00;
				ins_16b_l=0x00;	
				wr_1word_reg_data();
				ins_16b_h=0;
				ins_16b_l=0x22;
				wr_1word_index();
				for (i=0;i<160;i++)
				{
					for (j=0;j<128;j++)
					{
						red_data_buf=0x00;
						gre_data_buf=0x00;
						blu_data_buf=0xff;
						wr_1word_data();
					}
				}
				disp_dlt_ct=0;
				disp_pro_flg++;
				nop();
				disp_dlt_ct=0;
				nop();
				nop();
				nop();
				nop();
//			}
			break;
		case 10:	//延时
			delays(2);
//			if (disp_dlt_ct>DIS_DLT)
//			{
				disp_pro_flg=1;
				disp_dlt_ct=0;
//			}
			break;
		default:
			disp_pro_flg=0;
			disp_dlt_ct=0;
			break;
	}
}


//---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---
//HX8310驱动基本函数---18位80系列接口
//---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---

//------------------------------------------------------------------
//向LCM写入一字数据程序
//对于16位设置数据,中间位和最低位不用, 对于18位图像数据,则18位全用,
//	这些在联合中已经做了处理, 直接送出即可
//	调用本函数的程序在向RGB_OUTU写入设置数据时,要向ins_16b_h ins_16b_l 写入数据
//	向RGB_OUTU写入图像数据时, 要向red_data_buf gre_data_buf blu_data_buf写入数据
//输入: 存放在RGB_OUTU 中的数据, 
//输出:无
//注:写入的是当前单元的内容, 写入地址的设置需要单独进行,然后调用本函数写入数据
//------------------------------------------------------------------
void wr_1word_data(void)
{
	lcm_CD=1;	//写数据
//	set_lcd_cd();	//写数据

	blu_data_buf&=0x3f;
	gre_data_buf&=0x3f;
	red_data_buf&=0x3f;

	dataiol=blu_data_buf;
	dataiom=gre_data_buf<<6;
	dataiol|=dataiom;
	dataiom=gre_data_buf>>2;
	dataioh=red_data_buf<<4;
	dataiom|=dataioh;
	dataioh=red_data_buf>>4;

	lcm_IOH=dataioh;
 	lcm_IOM=dataiom;
	lcm_IOL=dataiol;

	lcm_CE=0;
	nop();
	lcm_WR=0;
	nop();
	lcm_WR=1;
	nop();
//	lcm_CE=1;
}


⌨️ 快捷键说明

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