| 
 
| 程序如下和接线图如下: /*************************************************************
 FUNCTIONn:             LCD driver 8080
 AUTHOR:                科技
 DESCRIPTION:           RA8803
 E-mail:
 CREAT DATE:            2006-2-25
 MODIFICATION DATE:
 ***************************************************************/
 #include       <pic.h>//定义三个头文件
 
 #define RW_WR         RC1
 #define E_RD          RC0
 #define CS            RC2
 #define RS            RC4
 #define RST           RC5
 #define DATA_BUS      PORTD
 #define BUSY           RC3
 unsigned char font[]=
 {
 0xd2,0xab,0xd3,0xee,0xbf,0xc6,0xbc,0xbc,//耀宇科技
 0xd2,0xab,0xd3,0xee,0xbf,0xc6,0xbc,0xbc//耀宇科技
 };
 //***************************************以下为函数申明
 void Delay(unsigned char shijian);
 void Write_Data(unsigned char dat);
 void Write_Instruction(unsigned char cmd);
 void LCD_Controller_Register(unsigned char dat);
 void Misc_Register(unsigned char dat);
 void Advance_Power_Setup_Register(unsigned char dat);
 void Advance_Display_Setup_Register(unsigned char dat);
 void Cursor_Control_Register(unsigned char dat);
 void Cursor_Size_Control_Register(unsigned char dat);
 void Memory_Access_Mode_Register(unsigned char dat);
 void Active_Window(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2);
 void Display_Window(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2);
 void Cursor_Position_Register(unsigned char x,unsigned char y);
 void Begin_Segment_Position_Register(unsigned char x);
 void Shift_Action_Range(unsigned char y1,unsigned char y2);
 void Blink_Time_Register(unsigned char dat);
 void Frame_Rate_Polarity_Change_At_Common_A_B_Register(unsigned char dat1,unsigned char dat2);
 void Shift_Clock_Control_Register(unsigned char  dat);
 void Interrupt_Setup_And_Status_Register(unsigned char at);
 void Font_Control_Register(unsigned char dat);
 void Font_Size_Control_Register(unsigned char dat);
 void Display_Chinese(unsigned char fnt[]);
 void Initial(void);
 
 /***********************************
 ** 函数名称: Delay
 ** 功能描述: 延时时间=(n*9+17)*12/F
 ** 输 入: n
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: 无
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 void Delay(unsigned char shijian)
 {   unsigned char i;
 for(i=shijian;i!=0;i--)//以10MS为基数的延时函数
 {
 unsigned int d=1000;//10MS延时函数,1000为10MS,2000为20MS
 asm("clrwdt");
 while(--d){;}
 }
 }
 /****************************************
 ** 函数名称: Write_Data
 ** 功能描述: 传送数据
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Busy,
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Write_Data(unsigned char  dat)
 {   //while(BUSY);
 DATA_BUS=dat;
 E_RD=1;//置读取位为高,不能读
 RS=1;
 CS=0;
 RW_WR=0;
 Delay(1);
 RW_WR=1;
 CS=1;
 Delay(5);
 return;
 }
 
 /******************************************
 ** 函数名称: Write_Instruction
 ** 功能描述: 传送命令
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Busy,
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Write_Instruction(unsigned char  cmd)
 {    //while(BUSY);
 DATA_BUS=cmd;
 E_RD=1;//置读取位为高,不能读
 RS=0;//为低时,存取缓存器,为高时,存取数据
 CS=0;//片选端,为0时选通RA8803,为1时禁止工作
 RW_WR=0;//写入信号,低电位动作,
 Delay(1);
 RW_WR=1;
 CS=1;
 Delay(5);
 return;
 }
 
 /***********************************
 ** 函数名称: LCD_Controller_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void LCD_Controller_Register(unsigned char  dat)
 {
 Write_Instruction(0x00);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Misc_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Misc_Register(unsigned char  dat)
 {
 Write_Instruction(0x01);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Advance_Power_Setup_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Advance_Power_Setup_Register(unsigned char  dat)
 {
 Write_Instruction(0x02);
 Write_Instruction(dat);
 return;
 }
 
 
 /***********************************
 ** 函数名称: Advance_Display_Setup_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Advance_Display_Setup_Register(unsigned char  dat)
 {
 Write_Instruction(0x03);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Cursor_Control_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Cursor_Control_Register(unsigned char  dat)
 {
 Write_Instruction(0x10);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Cursor_Size_Control_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Cursor_Size_Control_Register(unsigned char  dat)
 {
 Write_Instruction(0x11);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Memory_Access_Mode_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Memory_Access_Mode_Register(unsigned char  dat)
 {
 Write_Instruction(0x12);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Active_Window
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Active_Window(unsigned char  x1,unsigned char  y1,unsigned char  x2,unsigned char  y2)
 {
 Write_Instruction(0x40); //Active Window Left Register
 Write_Instruction(x1);
 Write_Instruction(0x20); //Active Window Right Register
 Write_Instruction(x2);
 Write_Instruction(0x50); //Active Window Top Register
 Write_Instruction(y1);
 Write_Instruction(0x30); //Active Window Bottom Register
 Write_Instruction(y2);
 return;
 }
 
 /***********************************
 ** 函数名称: Display_Window
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Display_Window(unsigned char  x1,unsigned char  y1,unsigned char  x2,unsigned char  y2)
 {
 Write_Instruction(0x41); //Display Window Left Register
 Write_Instruction(x1);
 Write_Instruction(0x21); //Display Window Right Register
 Write_Instruction(x2);
 Write_Instruction(0x51); //Display Window Top Register
 Write_Instruction(y1);
 Write_Instruction(0x31); //Display Window Bottom Register
 Write_Instruction(y2);
 return;
 }
 
 /***********************************
 ** 函数名称: Cursor_Position_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Cursor_Position_Register(unsigned char  x,unsigned char  y)
 {
 Write_Instruction(0x60);
 Write_Instruction(x);
 Write_Instruction(0x70);
 Write_Instruction(y);
 return;
 }
 
 /***********************************
 ** 函数名称: Begin_Segment_Position_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Begin_Segment_Position_Register(unsigned char  x)
 {
 Write_Instruction(0x61);
 Write_Instruction(x);
 return;
 }
 
 
 /***********************************
 ** 函数名称: Shift_Action_Range
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Shift_Action_Range(unsigned char  y1,unsigned char  y2)
 {
 Write_Instruction(0x71);
 Write_Instruction(y1);
 Write_Instruction(0x72);
 Write_Instruction(y2);
 return;
 }
 
 /***********************************
 ** 函数名称: Blink_Time_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Blink_Time_Register(unsigned char dat)
 {
 Write_Instruction(0x80);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Frame_Rate_Polarity_Change_At_Common_A_B_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Frame_Rate_Polarity_Change_At_Common_A_B_Register(unsigned char  dat1,unsigned char  dat2)
 {
 Write_Instruction(0x81);
 Write_Instruction(dat1);
 Write_Instruction(0x91);
 Write_Instruction(dat2);
 return;
 }
 
 
 /***********************************
 ** 函数名称: Shift_Clock_Control_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Shift_Clock_Control_Register(unsigned char  dat)
 {
 Write_Instruction(0x90);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Interrupt_Setup_And_Status_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Interrupt_Setup_And_Status_Register(unsigned char  dat)
 {
 Write_Instruction(0xa0);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Font_Control_Register(
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Font_Control_Register(unsigned char  dat)
 {
 Write_Instruction(0xf0);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Font_Size_Control_Register
 ** 功能描述:
 ** 输 入: dat
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块: Write_Instruction
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-25
 ******************************************/
 #pragma disable
 void Font_Size_Control_Register(unsigned char  dat)
 {
 Write_Instruction(0xf1);
 Write_Instruction(dat);
 return;
 }
 
 /***********************************
 ** 函数名称: Display_Chinese
 ** 功能描述: Display_Chinese
 ** 输 入:  value
 ** 输 出 : 无
 ** 全局变量:无
 ** 调用模块:LCD_Controller_Register,Cursor_Position_Register,Write_Data
 **
 ** 作 者: 耀宇科技
 ** 日 期: 2006-2-10
 ******************************************/
 #pragma disable
 void Display_Chinese(unsigned char fnt[])
 {
 register unsigned char i,j;
 LCD_Controller_Register(0xcd);
 Cursor_Position_Register(0x00,0x00);
 for(i=0;i<0x10;i+=2)
 {
 for(j=0;j<0x0f;j++)
 {
 Write_Data(fnt);
 Write_Data(fnt[i+1]);
 }
 }
 return;
 }
 
 #pragma disable
 void Initial(void)
 {
 TRISD=0X00;//设定数据端口为输出
 TRISC=0X08;//RC3为输入,液晶端口状态忙位检测
 PORTC=0Xff;//先输出0清端口状态
 PORTD=0Xff;//清零端口
 Delay(30);//延时300ms
 RST=0;//复位信号置低电平
 Delay(30);//延时300ms
 RST=1;//复位信号置低电平
 Delay(10);//延时100ms
 // while(BUSY);//忙信号检测
 LCD_Controller_Register(0xcd);//缓存器00H正常模式,屏幕开启
 Misc_Register(0xf1);//输出允许,BUSY高电平触发,4MHZ频率
 Advance_Power_Setup_Register(0x10);
 Advance_Display_Setup_Register(0x80);
 Cursor_Control_Register(0x6b);
 Cursor_Size_Control_Register(0x00);
 Memory_Access_Mode_Register(0x91);
 Active_Window(0x00,0x00,0x1d,0x7f);
 Display_Window(0x00,0x00,0x1d,0x7f);
 Begin_Segment_Position_Register(0x0);
 Shift_Action_Range(0x00,0x9f);
 Blink_Time_Register(0xaa);
 Frame_Rate_Polarity_Change_At_Common_A_B_Register(0x00,0x00);
 Shift_Clock_Control_Register(0x10);
 Interrupt_Setup_And_Status_Register(0x11);
 Font_Control_Register(0xa0);
 Font_Size_Control_Register(0x0f);
 Cursor_Position_Register(0x00,0x00);
 }
 
 //#pragma disable
 //void Step(void) interrupt 0
 //{
 // while(IE0==1);
 // return;
 //}
 
 main()
 {   Initial();
 while(1)
 {   RS=0;
 LCD_Controller_Register(0xcd);
 Delay(600);
 Delay(600);
 Display_Chinese(font);
 Delay(600);
 Delay(600);
 }
 }
 
 相关链接:https://bbs.21ic.com/upfiles/img/20077/2007715121234883.pdf
 | 
 |