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

📄 画点.txt

📁 单片机驱动12864画点程序
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************
// 文件名称:LCD12864.h													  *
// 文件功能:12864驱动头文件
// 芯片型号:M64  (8M晶振)
// 日期:2006.10.12
// 端口使用:   LCD         (功能)         M8端口
                 1            GND              GND
				 2            VCC               5V
				 3            v0(对比度)      GND
				 4            RS(1:数据)      PC0   (现在:PB.0)
				 5            R/W(1:读数据)   PC1    (现在:PB.1)
				 6            EN(LCD 使能)    PC2    (现在:PB.2)
				 7-14         DB0-DB7           PA0-PA7
				 15           PS_SELECT(串并数据选择)PC3    (现在:PB.3)
				 16           NC
				 RST          L(低电平复位)    PC4    (现在:PB.5)
				 18           out
				 19           A(5V)
				 20           K (GND)
***************************************************************************/
#include <delay.h>
unsigned char data[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char data2[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char COUNT3,COUNT2,COUNT1,COUNT,LCD_X,LCD_Y,LCD_DATA1,LCD_DATA2,LCD_DATA,F3,R1,F0;

unsigned char data_new[500]; 

unsigned char ramdata[2];

#define	SETBIT(x,y) (x|=(1<<y))      //set bit y in byte x
#define	CLRBIT(x,y) (x&=(~(1<<y)))   //clear bit y in byte x
#define	CHKBIT(x,y) (x&(1<<y))       //check bit y in byte x

#define dataDDR DDRA
#define dataPORT PORTA
#define dataIN   PINA

#define RS_PORT  PORTB
#define RS_DDR   DDRB
#define RS    0     

#define RW_PORT  PORTB
#define RW_DDR   DDRB
#define RW    1

#define E_PORT  PORTB
#define E_DDR   DDRB
#define E     2

#define PSB_PORT  PORTB
#define PSB_DDR   DDRB
#define PSB   3    //(串并口选择,1:并口)

#define RESET_PORT  PORTB
#define RESET_DDR   DDRB
#define RESET   5

#define INDataEN      SETBIT(RS_PORT,RS)   //输入数据使能
#define INCommandEN   CLRBIT(RS_PORT,RS)    //输入指令使能

#define WriteEN       CLRBIT(RW_PORT,RW)     //写使能
#define ReadEN        SETBIT(RW_PORT,RW)     //读使能

#define LCDEN         SETBIT(E_PORT,E)   //使能LCD
#define LCDHalt       CLRBIT(E_PORT,E)                                                                                                                                                          //停止LCD

#define FSB           SETBIT(PSB_PORT,PSB)    //并行数据输入

#define RST           CLRBIT(RESET_PORT,RESET)    //低电平复位
#define LCDWork       SETBIT(RESET_PORT,RESET)   //高电平,LCD正常工作 



/*
void delay_10us(unsigned char x) 
{ 
  while(x--);
} 

void delay_ms(unsigned char cnt)
{
    unsigned char i;
    do 
	{
       i = 4;
       do 
	   {
          delay_10us(39);
       } while(--i);
    } while(--cnt);
}*/

/************************************************************
*   函数名称:unsigned char ReadBF(void)					*
*   功    能:读取忙标志位									*
*   入口参数:无											*
*   出口参数:忙标志位  0:ready   1:busy					*
************************************************************/
unsigned char ReadBF(void)
{
    unsigned char BFflag = 0;
	LCDHalt;
    dataDDR= 0X00;   //D口输入数据
	INCommandEN;
	ReadEN;        //读取数据使能
    LCDEN;         //使能位为高
	LCDHalt;   //命令使能端为低
	BFflag =((dataIN & 0x80)>>7);
	return(BFflag);
	
}


/************************************************************
*  函数名称:void WriteByte(unsigned char flag,unsigned char data)
*  函数功能:向LCD写入数据或者命令	 	  					*
*  入口参数:flag:0  命令  1  数据	 	  					*
             data:命令或者数据	   	 	  					*
*  出口参数:无 			   	   	 	  					*
************************************************************/
void WriteByte(unsigned char flag,unsigned char data)
{
	unsigned char a;
	while(ReadBF());
	
	WriteEN;       //写数据使能
	dataDDR = 0xff;
    if(flag == 0)   //写入指令
	{
	    INCommandEN;
		LCDEN;         //LCD使能
		dataPORT=data;
		LCDHalt;	
	}
	else if(flag == 1)             //写入数据
	{   
	    INDataEN;      
		LCDEN;  
		dataPORT= data;
		LCDHalt;
	}
}





/************************************************************
*   函数名称:void LCDInit(void)							*
*   功    能:LCD初始化										*
*   入口参数:无	   										*
*   出口参数:无	   										*
************************************************************/
void LCDInit(void)
{
    dataDDR =0Xff; //数据断输出
	dataPORT = 0xff;
	
	RS_DDR|=(1<<RS);
	SETBIT(RS_PORT,RS);
	
	RW_DDR|=(1<<RW);
	SETBIT(RW_PORT,RW);
	
	E_DDR|=(1<<E);
	SETBIT(E_PORT,E);
	
	PSB_DDR|=(1<<4);
	SETBIT(PSB_PORT,PSB);

	RESET_DDR|=(1<<RESET);
	SETBIT(RESET_PORT,RESET);
	
	FSB;              //并行数据输入
	
//	DelayMS(1);//DelayMS(80);
	RST;
	LCDWork;    //rst  由0变1,正常工作

	
}
/****************************************************************
*   函数名称:void DisplayStr(unsigned char Ps,unsigned char *p)*
*   功    能:显示字符串			   						 	*
*   入口参数:Ps寄存器的值,*P字符串指针					 	*
*   出口参数:无												*
****************************************************************/
void Display(unsigned char ps,char flash *p)
{
    unsigned int i;
	WriteByte(0,ps);
//	DelayMS(1);//DelayMS(10);
	while(*p)
	{
	    WriteByte(1,*p);
//		DelayMS(1);//DelayMS(2);
		p++;
	}	
}

void Display2(unsigned char ps,char *p)
{
    unsigned int i;
	WriteByte(0,ps);
//	DelayMS(1);//DelayMS(10);
	while(*p)
	{
	    WriteByte(1,*p);
//		DelayMS(1);//DelayMS(2);
		p++;
	}	
}
/****************************************************************
*   unsigned char Localxy(unsigned char x,unsigned char y)		*
*   功    能:通过要显示的坐标计算出要写的值的寄存器			*
*   入口参数:x:横0-15   y:纵 0-3                              *
*   出口参数:计算得到的坐标值!								*
****************************************************************/

unsigned char Localxy(unsigned char x,unsigned char y)
{
    unsigned char position=0;
	switch(y)
	{
	    case 0: position = 0x80 + x; break;
		case 1: position = 0x90 + x; break;
		case 2: position = 0x88 + x; break;
		case 3: position = 0x98 + x; break;
		default: break;
	}
	return(position);
}

/****************************************************************
*   函数名称:void DisStr(un char x, un char y,unsinged char *p)*
*   功    能:在指定的坐标开始显示字符串	 				 	*
*   入口参数:x,y ,*p											*
*   出口参数:无   												*
****************************************************************/
void DisStr(unsigned char x1,unsigned char y1,char flash *p1)
{
     unsigned char pos=0;
	 pos = Localxy(x1,y1);
	 Display(pos,p1);
} 

void DisStr2(unsigned char x1,unsigned char y1,char *p1)
{
     unsigned char pos=0;
	 pos = Localxy(x1,y1);
	 Display2(pos,p1);
}


/***********************************************************************
*   函数名称:void LCD12864Driver(void)								   *
*   函数功能:LCD12864驱动程序初始化								   *
*   入口参数:无													   *
*   出口参数:无													   *
***********************************************************************/
void LCD12864Driver(void)
{
 //   LCDInit();     //LCD初始化
	
	WriteByte(0,0x30);
	WriteByte(0,0x0c);
	WriteByte(0,0x01);
	WriteByte(0,0x06);
	

}

/**********************************************************************
*  函数名称:void LCD12864Clr(void)									  *
*  函数功能:清屏 													  *
*  入口参数:无														  *
*  出口参数:无														  *
**********************************************************************/
void LCD12864Clr(void)
{
    WriteByte(0,0x01);
    WriteByte(0,0x34);
    WriteByte(0,0x30);
       //在第二次写入数据的时候一定要先清屏
}

//**********写命令***************************
void send_com(unsigned char command )
{
  WriteByte(0,command);
}
//**********LCD初始化时的送命令******************
void send_com_init(unsigned char command_init )
{
  WriteByte(0,command_init);
}
//**********写数据***************************
void send_data(unsigned char data )
{
  WriteByte(1,data);
}
//***********读数据****************************
unsigned char read_data(void)
{
  unsigned char read_data1;
  	while(ReadBF());
	
	LCDHalt;
    dataDDR= 0X00;   //D口输入数据
	INDataEN;
	ReadEN;        //读取数据使能
    LCDEN;         //使能位为高
	LCDHalt;   //命令使能端为低
	read_data1=dataIN;
	return(read_data1);
}
//***********清屏*****************************
void clear_LCD(void)  //可省
{
  WriteByte(0,0x01);
  WriteByte(0,0x34);
  WriteByte(0,0x30);
}
//**********LCD初始化************************
void initial_LCD(void)
{  
   LCD12864Driver();
   
}
//**********写准备***************************
void WR_ZB(void)
{
   send_com(0x34);
   send_com(LCD_Y);
   send_com(LCD_X);
   send_com(0x30);   //可省
}
//*********取数送显示******************************
void QUSHU(const unsigned char *shu)
{
   for (;COUNT!=0;COUNT--)
   {
     send_data(*shu++);
//     delay_ms(80);
   }  
}
//*********Flash******************************
void flash_1(void)
{
   send_com(0x08);//关闭显示
   delay_ms(250);
   send_com(0x0c);//开显示,关光标,不闪烁。
   delay_ms(250);
   send_com(0x08);//关闭显示
   delay_ms(250);
   send_com(0x0c);//开显示,关光标,不闪烁。
   delay_ms(250);
   send_com(0x08);//关闭显示
   delay_ms(250);
}
//**********显示图形子程序*********************
void pic_clear(void)
{
   COUNT3=0X02;
   LCD_X=0X80;
   for (;COUNT3!=0;COUNT3--)
   {
       LCD_Y=0X80;
       COUNT2=0X20;//32
       for (;COUNT2!=0;COUNT2--)
       {
         COUNT1=0X10;//16
         WR_ZB();
         for (;COUNT1!=0;COUNT1--)
          {
            send_data(0);
            
          }
         LCD_Y+=1;
       }
       LCD_X=0X88;
   }
//   send_com(0x36);
//   send_com(0x30);   //可省

}

void PHO_DISP(unsigned char flash *s)
{

⌨️ 快捷键说明

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