dsPIC33驱动内藏T6963C的液晶显示模块的源代码

源代码在线查看: dspic3驱动内藏t6963c的液晶显示模块).txt

软件大小: 4 K
上传用户: foreigngirl
关键词: T6963C dsPIC 33 驱动
下载地址: 免注册下载 普通下载 VIP

相关代码

				dsPIC3驱动内藏T6963C的液晶显示模块
				
				
				#include              //dsPIC30F6014标准头文件
				#include "biaoge.h"
				#include "temp.h"
				
				#define  CD LATBbits.LATB2//RC7
				#define  CE LATBbits.LATB6//RC6
				#define  RD LATBbits.LATB5//RC5
				#define  WR LATBbits.LATB4//RC4
				
				#define  LCD_DATA_out LATD//PORTD//
				#define  LCD_DATA_in  PORTD
				#define  IO_RW   TRISD  
				
				extern union{
				      unsigned int Temp;
				  struct  { //
				        unsigned R0    :1;
				        unsigned R1    :1;
				        unsigned R2    :1;
				        unsigned R3    :1;
				        unsigned R4    :1;
				        unsigned R5    :1;
				        unsigned R6    :1;
				        unsigned R7    :1;
				        unsigned R8    :1;
				        unsigned R9    :1;
				        unsigned R10   :1;
				        unsigned R11   :1;
				        unsigned R12   :1;
				        unsigned R13   :1;
				        unsigned R14   :1;
				        unsigned R15   :1;
				     } BITS;
				
				}flag_i;
				#define  diaodian_bit  flag_i.BITS.R0 //掉电标志
				
				//extern     diaodian_bit ;
				 
				 
				/////// 延时子程序////////////////
				///#pragma  interrupt_level 1
				 void delay(uint i)
				{ 
				  while(i--)CLRWDT();
				}
				
				//-----------LCD子程序---------------------
				//----读取LCD状态字--------------------
				uchar read_data(void)
				{
				   uchar i;
				   IO_RW=0xff; //端口输入
				   CD =1;NOP();
				   RD =0;NOP();
				   i=LCD_DATA_in; //读数据
				    NOP();delay(1);
				   RD =1;
				  return i;
				}
				
				//-----判断指令(数据)读写状态--------
				void st01(void)
				{uchar i;
				 for(i=10;i>0;i--)
				   {
				      if((read_data()&0x03)==3)
				      break;
				   } 
				}
				
				//----------判断数据自动读状态------------
				void st2(void)
				{uchar i;
				 for(i=10;i>0;i--)
				   {
				     if((read_data()&0x04)==4)
				     break;
				   } 
				}
				
				//---------判断数据自动写状态-------------
				void st3(void)
				{uchar i;
				 for(i=10;i>0;i--)
				   {
				   if((read_data()&0x08)==8)
				      break;
				   } 
				}
				
				//----------数据写入函数------------------
				void write_data(uchar data_d)
				{
				  st01();
				  IO_RW=0x00;       //端口输入出
				  CD =0;NOP();
				  LCD_DATA_out=data_d;  //写读数据
				  NOP();
				  WR =0;
				   NOP(); delay(1);
				  WR=1;
				 // DATA_573= Data_573;//并口总线总是电机状态
				}
				//-------------指令写入函数-----------------
				void write_contr(uchar data_c)
				{
				  st01();
				  IO_RW=0x00;      //端口输入出
				  CD =1;NOP();
				  LCD_DATA_out=data_c; //写读数据
				  NOP();
				  WR =0;
				   NOP(); delay(1);
				  WR =1;
				 // DATA_573= Data_573;//并口总线总是电机状态
				}
				
				//-------------数据自动写入函数--------------
				void writeauto(uchar onedata)
				{
				  st3();
				  IO_RW=0x00;      //端口输入出
				  CD =0;NOP();
				  LCD_DATA_out=onedata; //写读数据
				  NOP();
				  WR =0;
				   NOP(); delay(1);
				  WR =1;
				 // DATA_573= Data_573;//并口总线总是电机状态
				}
				
				//---------双字节参数 指令写入----------------------------
				void lcd_double_operator(uchar data1,uchar data2,uchar com)
				{
				  write_data(data1);    ///-参数1-/
				  write_data(data2);    ///-参数2-/
				  write_contr(com);     ///-指令-//
				}
				//----------单字节参数 指令写入---------------------
				void lcd_single_operator(uchar data1,uchar com)
				{
				  
				  write_data(data1);     ////-参数1-/
				  write_contr(com);      ////-指令-/
				}
				//------------无参数 指令写入----------------------
				void lcd_none_operator(uchar com)
				{
				  
				  write_contr(com);         ///-指令-/
				}
				//------------内置T6963C控制器液晶初始化函数---------
				void lcd_ini()
				{ //双字节参数 指令写入
				  lcd_double_operator(0x00,0x00,0x40);//文本显示区域首地址0x0000
				  lcd_double_operator(0x1e,0x00,0x41);//文本区宽度(字节数/行)30 
				  lcd_double_operator(0x00,0x08,0x42);//图形区首址 0x800
				  lcd_double_operator(0x1e,0x00,0x43);//图形区宽度(字节数/行)30
				  lcd_none_operator(0xa0); //A7 A0无参数 指令写入 光标形状选择
				  lcd_none_operator(0x81); //81 80 82//--显示方式设置逻辑"或"合成//
				  lcd_none_operator(0x9c);//9c    9F//--显示开关设置 开文本和图形显示。光标显示闪烁//
				 }
				//---------------建立CGRAM子程序-------------------------------------------
				void creat_cgram(uchar count,uchar a)// creat_cgram(32,1); //建立CGRAM子程序//插除 公司名称
				{
				 uint i,x;
				 x=count				 x=x				 lcd_double_operator(0x3,0x00,0x22); //CGRAM偏置地址设置
				 lcd_double_operator(0x00,0x1c,0x24); //地址指针位置
				for (i=0;i				  {CLRWDT();
				   if(!a)
				         lcd_single_operator(font[i] ,0xc0); //单字节参数 指令写入
				   else  lcd_single_operator(font1[i] ,0xc0); //单字节参数 指令写入
				  }
				}
				
				//-----------------清除屏幕(清所有8K存储空间)------------------------
				void lcd_clear()
				{
				   uint i;
				   lcd_double_operator(0x00,0x00,0x24);    //首地址//设置显示存储器首地址
				   lcd_none_operator(0xb0);  //设置自动写状态
				   for(i=8192;i>0;i--)
				      {writeauto(0x00 );CLRWDT();} 
				                                 //无参数 指令写入
				      lcd_none_operator(0xb2);  //关闭自动写状态   
				 
				}
				
				//---------------------清除屏幕(清0x800存储空间)----------------------------
				void lcd_clear1()
				{
				   uint i;
				   lcd_double_operator(0x00,0x08,0x24);    //首地址//设置显示存储器首地址
				   lcd_none_operator(0xb0);  //设置自动写状态
				   for(i=3840;i>0;i--)//3683 //15*8*32
				      {writeauto(0x00 );CLRWDT();if(diaodian_bit) break;} 
				                                 //无参数 指令写入
				      lcd_none_operator(0xb2);  //关闭自动写状态   
				 
				}
				
				/********************************************************
				    西文字符,汉字,点阵显示函数
				********************************************************/
				//********西文字符写入函数******
				void write_english(uchar cursor_x,uchar cursor_y,uchar c_code,uchar attr)
				{
				 uint x;
				  if(diaodian_bit) return; 
				 x=cursor_y*30;
				 x=x+cursor_x;                  //y=cursor_y*30+cursor_x
				 lcd_double_operator((uchar)(x),(uchar)(x>>8),0x24);
				 lcd_single_operator(c_code,0xc4);
				 lcd_double_operator((x&0x00ff),(x>>8)+0x0c,0x24);
				 lcd_single_operator(attr,0xc4); 
				}
				 
				//********汉字写入函数****16x16******
				 
				void write_chinese(uchar cursor_x,uchar cursor_y,uchar ct_code,uchar attr)
				{ 
				  uint x;
				   if(diaodian_bit) return;
				  x=cursor_y*30;
				  x=x+cursor_x;                            //y=cursor_y*30+cursor_x 
				  lcd_double_operator((uchar)(x),(x>>8),0x24);
				  lcd_single_operator(ct_code,0xc4);
				  lcd_double_operator((uchar)(x),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				  lcd_double_operator(((uchar)(x)+1),(x>>8),0x24);
				  lcd_single_operator(ct_code+2,0xc4);
				  lcd_double_operator(((uchar)(x)+1),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				  x+=30;
				  lcd_double_operator((uchar)(x),(x>>8),0x24);
				  lcd_single_operator(ct_code+1,0xc4);
				  lcd_double_operator((uchar)(x),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				  lcd_double_operator(((uchar)(x)+1),(x>>8),0x24);
				  lcd_single_operator(ct_code+3,0xc4);
				  lcd_double_operator(((uchar)(x)+1),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				}
				//*******************汉字写入(图形方式)函数******************************************/
				//汉字写入函数
				//x_hz:0~29;  y_hz:0~127
				void writehz(uchar x_hz,uchar y_hz,uchar code_hz)
				{
				  uchar i_hz;
				  uint address,addr_hz;
				   if(diaodian_bit) return;
				  address=y_hz*30+x_hz+0x0800;  //计算显示存储器地址
				  addr_hz=code_hz				  for(i_hz=0;i_hz				    {
				   lcd_double_operator((uchar)(address),(uchar)(address>>8),0x24);  //设置显示存储器地址
				   lcd_single_operator(font2[addr_hz],0xc0);  //写入汉字字模左部
				   lcd_single_operator((font2[16+addr_hz++]),0xc0);  //写入汉字字模右部
				   address+=30;  //修改显示存储器地址,显示下一列(共16列)
				 }
				}
				
				//************************字写入函数16x8*********************************************
				 
				void write_chinese8(uchar cursor_x,uchar cursor_y,uchar ct_code,uchar attr)
				{ 
				  uint x;
				   if(diaodian_bit) return;
				  x=cursor_y*30;
				  x=x+cursor_x;                            //y=cursor_y*30+cursor_x 
				  lcd_double_operator((uchar)(x),(x>>8),0x24);
				  lcd_single_operator(ct_code,0xc4);
				  
				  lcd_double_operator((uchar)(x),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				  x+=30;
				  lcd_double_operator((uchar)(x),(x>>8),0x24);
				  lcd_single_operator(ct_code+1,0xc4);
				   
				  lcd_double_operator((uchar)(x),(x>>8)+0x0c,0x24);
				  lcd_single_operator(attr,0xc4);
				}
				
				
				
				//实验目的:熟悉240*128LCD的使用
				//硬件设置:
				//关断所有拨码开关。30CM长杜邦头实验连接线连接240*128LCD
				
				#include              //dsPIC30F6014标准头文件
				//#include "biaoge.h"
				#include "temp.h"
				 
				 _FOSC(CSW_FSCM_OFF & XT_PLL4);  //4倍频晶振,Failsafe 时钟关闭
				  _FWDT(WDT_OFF);                 //关闭看门狗定时器
				  _FBORPOR(PBOR_OFF & MCLR_EN);   //掉电复位禁止,MCLR复位使能。
				  _FGS(CODE_PROT_OFF);            //代码保护禁止
				
				 
				 extern  void lcd_ini(void);
				 extern  void lcd_clear(void);
				 extern void write_chinese(uchar cursor_x,uchar cursor_y,uchar ct_code,uchar attr);
				 extern  void creat_cgram(uchar count,uchar a);
				
				//union IOflag_i   ;                     // 位结构体
				union 
				{
				      unsigned int Temp;
				  struct  { //
				        unsigned R0    :1;
				        unsigned R1    :1;
				        unsigned R2    :1;
				        unsigned R3    :1;
				        unsigned R4    :1;
				        unsigned R5    :1;
				        unsigned R6    :1;
				        unsigned R7    :1;
				        unsigned R8    :1;
				        unsigned R9    :1;
				        unsigned R10   :1;
				        unsigned R11   :1;
				        unsigned R12   :1;
				        unsigned R13   :1;
				        unsigned R14   :1;
				        unsigned R15   :1;
				     } BITS;
				
				}flag_i;
				#define  diaodian_bit  flag_i.BITS.R0 //掉电标志
				
				
				 void init()
				{
				  TRISB=0X0000;                     //设置B口为输出  
				  TRISD=0X0000;                     //设置D口为输出
				}
				
				void
				  main(void)
				{ 
				   uchar c,a,b;
				    uint  i;
				    NOP();//asm volatile("nop");
				   init();
				   diaodian_bit=0;
				 
				   lcd_ini();  //内置T6963C控制器液晶初始化函数
				   lcd_clear(); //清除屏幕
				   creat_cgram(8,0); //建立CGRAM子程序
				
				   b=0x80;a=4;
				      for(c=8;c>0;c--)//显示公司名称
				       {
				        CLRWDT();
				       
				         write_chinese(a+2,0x7,b,0x00);
				         a=a+2;
				         b=b+4;
				       }
				 
				//------------------------------------------------------------------------------  
				   while(1)
				   { 
				     ;
				   }
				}			

相关资源