12864

#define data P3OUT                //P3为8位数据口
#define RS_low P4OUT &= ~BIT0      //P4.0接RS 高为数据,低为指令
#define RS_high P4OUT |= BIT0 
#define RW_low P4OUT &= ~BIT1      //P4.1接RW 高为读,低为写
#define RW_high P4OUT |= BIT1 
#define EN_low P4OUT &= ~BIT2      //P4.2接EN
#define EN_high P4OUT |= BIT2
#define FIRST   0x80
#define SECOND  0x90
#define THIRD  0x88
#define FOURTH  0x98


void write_data(unsigned char d);
void write_instructction(unsigned char d);
void initial();
void display_string(char*t1,char*t2);                 //两行显示两个字符串
void display_char(unsigned char add,unsigned char c); //在一个位置显示一个字符



// 0x01 清屏
// 0x02 归零
// 0x0c 关光标
// 0x0e 开光标,不闪烁
// 0x0f 开光标,闪烁
// 0x14 光标右移
// 0x10 光标左移


void write_data(unsigned char d)
{
    
    
	__delay_cycles(100);
	EN_low;
	RS_high;
	RW_low;
	EN_high;
	data = d;
	__delay_cycles(100);
	EN_low;
	__delay_cycles(100);
}
void write_instructction(unsigned char d)
{
    
    
	__delay_cycles(100);
	EN_low;
	RS_low;
	RW_low;
	EN_high;
	data = d;
	__delay_cycles(100);
	EN_low;
	__delay_cycles(100);
}
void initial()
{
    
    
	P3DIR = 0XFF;
	P4DIR |= BIT0+BIT1+BIT2;
	write_instructction(0x06); //AC加一
	write_instructction(0x0c); //显示开 
	write_instructction(0x30);
}
void display_string(char*t1,char*t2)
{
    
    
	unsigned char i; //定义计数值
	//initial(); //初始化12864
	write_instructction(0x88); //写指令
        for(i=0;i<16;i++) //发送数据第一行
	    {
    
      
            write_data(t1[i]);			
	    } 
	write_instructction(0x98);
		for(i=0;i<16;i++) //发送数据第二行
		{
    
    
			write_data(t2[i]);
		}
	
}
void display_char(unsigned char add,unsigned char c)
{
    
    
	initial(); //初始化12864
	write_instructction(add);
	write_data(c);	
}

猜你喜欢

转载自blog.csdn.net/qq_43710693/article/details/103345750