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

📄 lcd240128.c

📁 液晶 OCM/TG240128 驱动 编程语言: C 原产品硬件ATMega128/1280 ,晶振14.7456M 软件AVR ICC7.14C 破解版 由产品源码中提取,详细的
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
*                    (c) Copyright xxing's studio
*                        All Rights Reserved
* name : 
* desc :  LCD Driver for OCM/TG240128-07 .
*        OCM240128-07/TG240128A-10  驱动程序与API接口函数  
*        Controler: T6963C
*
* 接口 : 并行
*        字符显示起始地址:0x00
*        显示坐标:            
*        --------->Y(0-29)列  
*        |
*        |
*        |
*        v X(0-16)行
*
*        图形显示起始地址:0x01e0
*        显示坐标:            
*        --------->Y(0x01e0 + (0-29))列  
*        |
*        |
*        |
*        v X(0x01e0 + (0-(128*30-1)))行
*
*        画图坐标: 
*        --------->X(0-239)  
*        |
*        |
*        |
*        v Y(0-127)
*        
* 完成日期: 2007.10
* 修    改: xxing :) 2008.09.29
* Email: cuiss83@163.com
* 
******************************************************************************/

/*****************************************************************************
NOTE: 2008.10.07 重阳
一, 字体
1, FS 为字体选项 FS=1,8X6. FS=0,8X8 由硬件或软件设定
2, RAM地址由左到右开始, 例:
   FS=1, 显示区宽度为240/6=40(字宽), 地址分布:
   第一行:  0x00,0x01....0x27 
   第二行:  0x28,0x29...
3, 文本显示以字宽为单位
4, 图形显示时, 取字横向取模左高位,数据排列:从左到右从上到下, 当FS=1时, 横向取低6位,特殊处理.
   
5, 栈存问题, 系统预留 (AVRX)

08.10.08 AM
   不使用LCD自带字库, 使用自定义ASCII码字库和汉字库. FS=0. 字体使用8X16
   完成字符串输出功能.
   10.08 PM
   完成图形显示读取驱动, 图形操作与或, 反显等功能.
   NOTE:
   LCD ram 地址分布从左到右递增.左位高. 单屏8*8字体宽度为30个字
   
******************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include "LCD240128.h"
#include "../include/Functions.h"

extern const unsigned char HZST16X16[]; 
extern const  unsigned char ST12X12[];
extern const unsigned char ASCII8X16E[];
extern const unsigned char Zuobiao[];
extern const unsigned char ASCII6X12E[];


/**********************************************************************
* Name: 
* Desc: 
**********************************************************************/

void write_comm (U8 comm);
void write_data (U8 data);
void check_busy (U8 autowr);
void write_auto (U8 data) ;
void write_od (U8 data, U8 comm);   
void write_td (U8 datl, U8 dath, U8 comm); 
void write_xd (U16 data, U8 comm);

/**********************************************************************
* Name: 
* Desc: Initialize the lcd 
**********************************************************************/

void LCD_Init (void)
{
  U8 delay;
  U16 i;
  
  DDRG|=0XFF;    //A为输出
  DDRL|=0XFF;    // 
   
  
  CS_LL;
  RST_L;   
  #ifdef FS_8X8
  FS_8;
  #else 
   FS_6;
   #endif
  for(i=0;i<1200;i++)
   for(delay=0;delay<250;delay++);
  RST_H;      
  
  WR_H;
  RD_H;
  
  
  for(delay=0;delay<20;delay++);

  write_xd(ADDR_T, COM_SET_TEXTHOMEADDR);        //文本显示区首地址
  write_xd(ADDR_G, COM_SET_GRAPHICHOMEADDR);     //图形显示区首地址
  write_td(width, 0x00, COM_SET_TEXTAREA);          //文本显示区宽度
  write_td(width, 0x00, COM_SET_GRAPHICAREA);       //图形显示区宽度
  write_comm(COM_SET_MODE_OR);                 //逻辑"异或", Becareful while the data is 0x83 , the AND mode!!
   
  write_td(0x02, 0x00, COM_SET_OFFSETREGISTER);    //CGRAM偏置地址设置
                 
  write_comm(COM_SET_DISPMOME( DISP_TEXTON | DISP_GRAPHICON));  //启用文本显示, 启用图形显示| DISP_CURSORBLINKDISP_CURSORON |
  LCD_ClrRam(); 
}
/**********************************************************************
* Name: 
* Desc: 
**********************************************************************/
void LCD_ON(unsigned char on)
{
 if(on)
  BLON;
  else BLOFF;
}
/**********************************************************************
* Name: write_comm (U8 comm) 
* Desc:  写命令
**********************************************************************/
void write_comm (U8 comm)      
{  
  check_busy (0);    //check busy
  CS_L;             //cs enable
  CD_H;            //seletct command
  RD_H;            //read disable
  LCDDATAPORT=comm; //output the data
  asm("nop");       //delay
  WR_L;             //enable write   
  asm("nop"); 
  WR_H;             //disable write
  CS_H;             //disable cs
}

/**********************************************************************
* Name: write_data (U8 data) 
* Desc:  写数据
**********************************************************************/

void write_data (U8 data)      
{  	 
  check_busy (0);
  CS_L;
  CD_L;
  RD_H;
  LCDDATAPORT=data;
 // asm("nop"); 
  WR_L;  
  asm("nop"); 
  WR_H;    
  CS_H; 
}

/**********************************************************************
* Name: 
* Desc: data and command together
**********************************************************************/

void write_od (U8 data, U8 comm)       //写一个数据和一个命令
{
  write_data(data);
  write_comm(comm);
}

void write_td (U8 datl, U8 dath, U8 comm)  //写两个数据和一个命令
{
  write_data(datl);
  write_data(dath);
  write_comm(comm);
}

void write_xd(U16 data, U8 comm)       //写一个16进制数据和一个命令
{
  U8 datl, dath;
  datl=data;
  dath=data>>8;
  write_data(datl);
  write_data(dath);
  write_comm(comm);
}


/**********************************************************************
* Name: read_data (U8 data) 
* Desc:  read the data from lcd ram
**********************************************************************/

U8 read_data (void)       //写数据
{ 
  U8 data; 
  
  check_busy (0);     //check whether the operation is ready
  DDRPORT = 0x00;   // set the pin as input
  LCDDATAPORT = 0xff; //initializa the port
  CD_L; 
  CS_L;
  WR_H;
  RD_L; 
  asm("nop");   //delay long enough or it will be read wrong data.
  asm("nop");
  asm("nop");   
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");  
  data = PINPORT; 
  RD_H;  
  CD_H;   
  CS_H;
  LCDDATAPORT = 0x00;
  DDRPORT = 0xff;   //output 
  
  return  data; 
}

/**********************************************************************
* Name: check_busy (U8 autowr) 
* Desc: autowr: auto write
**********************************************************************/

void check_busy (unsigned char autowr)    //测状态
{   
  LCDDATAPORT=0xff;
  DDRL=0X00;      // set the pin as input
  CS_L;
  CD_H;
  WR_H;
  RD_L;
 // asm("nop");   
 // asm("nop");
  if(autowr)
  {
   while((PINPORT&0X08)==0x00);
  }
  else
  {
   while(((PINPORT&0X01)==0x00)|((PINPORT&0X02)==0x00));
  }
  RD_H; 
  CS_H;
  DDRL=0Xff;
} 
 
/**********************************************************************
* Name: 
* Desc: 
**********************************************************************/
void write_auto (U8 data)               //自动写数据
{ 
  check_busy (1);
 
  CS_L;
  CD_L;      //selete data         
  RD_H;      //disable read    
  LCDDATAPORT=data;           
  //asm("nop"); 
  WR_L;       //enable write     
  asm("nop");   
  WR_H;       //close write     
  CS_H;  
} 

/**********************************************************************
* Name: 
* Desc: Read data from the lcd ram 
**********************************************************************/
U8 ReadData(U16 addr)       //读数据
{  	 
  write_xd(addr, COM_SET_ADDRESSPOINTER);//pos/8相对显示坐标值
  write_comm(COM_SET_RNONADP);  
  return  read_data(); 
}

/**********************************************************************
* Name:
* Desc: position the cursor(text) or set the address(graphics)
*      len means the cursor length
**********************************************************************/
 void GMoveTo(U8 yline, U8 xcolumn)
{
  U16 pos;
  pos = yline*width + xcolumn/8;
  write_xd(ADDR_G + pos, COM_SET_ADDRESSPOINTER);//pos/8相对显示坐标值
}
 
void TMoveTo(U8 y, U8 x,U8 len)
{
    write_comm(COM_SET_CRUSORLENGTH(len));
    write_td(x, y, COM_SET_CRUSORPOINTER);  
	
	//write_xd(ADDR_T + y*8, COM_SET_ADDRESSPOINTER);//pos/8相对显示坐标值
}

 /**********************************************************************
* Name:
* Desc: position the display line
*      gt: text or graphics
*     
**********************************************************************/
void DispStartLine(U8 gt, U8 line)
{ 

 if(gt==G)
  write_xd(ADDR_G+ LINE(line),COM_SET_GRAPHICHOMEADDR);  
 else if(gt==T)
  write_xd(ADDR_T+ LINE(line), COM_SET_TEXTHOMEADDR);
 else if(gt==GT)   
 {
   write_xd(ADDR_G+ LINE(line),COM_SET_GRAPHICHOMEADDR);  
   write_xd(ADDR_T+ LINE(line), COM_SET_TEXTHOMEADDR); 
 }
 
}

/**********************************************************************
* Name: clrram (void)
* Desc: clean the lcd ram
**********************************************************************/

void LCD_ClrRam (void)
{
  U8 i, j;
  
  write_xd(ADDR_T, COM_SET_ADDRESSPOINTER);
  write_comm(COM_SET_AUTOWRITE);
  for(j=0;j<144;j++)//
  {
    for(i=0;i<width;i++)  
		write_auto(0x00); 	
  }
 
  
  write_comm(COM_SET_AUTORESET);
}
/*****************************************************************************
* name: Clear_Pixel();
* decs: 画像素点 
*       x(0,240-1), Y(0,128-1)
*      
*****************************************************************************/

void Clear_Pixel(U8 x)
{ 

   U16 pos;    
   U8  bit;
   U8  y;
   
   //x+=16;
   
   if(x<240&&y<128)
   {  
    for(y=19;y<120;y++)
    { 
	   //FeedDog();
	   pos = y*width*8 + x ;//绝对坐标点
       bit = ~(1<<(7-pos%8));  //获得点显示值    
	   pos = ADDR_G +pos/8;//pos相对显示坐标值
	   bit &= ReadData(pos);	//OR the LCD data
       write_xd(pos, COM_SET_ADDRESSPOINTER);//set address pointer
       write_od(bit, COM_SET_WINCADP);       //write the data
	 }
	} 	 
}


/*****************************************************************************
* name: Draw_Pixel();
* decs: 画像素点 
*       x(0,240-1), Y(0,128-1)
*      while write to the lcd it will read from the lcd ram first 
*****************************************************************************/

void Draw_Pixel(U8 x, U8 y)
{ 
   U16 pos;    
   U8  bit;
   
   if(x<240&&y<128)
   { 
 #ifdef FS_6X8 
    pos = y*width + x/6 ;//绝对坐标点
    bit =  1<<(5-x%6);  //获得点显示值    
    bit |= ReadData(ADDR_G + pos);		
    write_xd(ADDR_G + pos, COM_SET_ADDRESSPOINTER);//pos/8相对显示坐标值
    write_od(bit, COM_SET_WINCADP);  
    
 #else
    pos = y*width*8 + x ;//绝对坐标点
    bit = 1<<(7-pos%8);  //获得点显示值    
	pos = ADDR_G +pos/8;//pos相对显示坐标值
	bit |= ReadData(pos);	//OR the LCD data
    write_xd(pos, COM_SET_ADDRESSPOINTER);//set address pointer
    write_od(bit, COM_SET_WINCADP);       //write the data
	
#endif	

	} 	
}

/*****************************************************************************
* name: LineTo()
* decs:  draw the line
* parameter: x(0,240-1), Y(0,128-1)
*
*****************************************************************************/
 
void LineTo(U8 x0, U8 y0, U8 x1, U8 y1)
{
 U8 i;
 
 for(i = x0; i<=x1; i++)  
 	Draw_Pixel(i,(i-x0)*(y1-y0)/(x1-x0) + y0); 	
	
}

/*****************************************************************************
* name: Draw_LineH();
* decs: 画线(横线)
*
*****************************************************************************/
 
void Draw_LineH (unsigned char x0, unsigned char y0, unsigned char xl)
{
 U8 i;
 
 for (i=x0;i<=xl;i++)  
  Draw_Pixel(i, y0);
  
}

/*****************************************************************************
* name: Draw_VLineH();
* decs: 画虚线(横线)
*
*****************************************************************************/
 
void Draw_VLineH(unsigned char x0, unsigned char y0, unsigned char xl)
{
 U8 i;
 
 for(i=x0;i<=xl;i+=2) 
  Draw_Pixel(i, y0);
 
} 

/*****************************************************************************
* name: Draw_LineV();
* decs: 画线(纵线)
*
*****************************************************************************/
 
void Draw_LineV(unsigned char x0, unsigned char y0, unsigned char yl)
{
 U8 j;
 
 for(j=y0;j<=yl;j++) 
   Draw_Pixel(x0, j);
  
}
/*****************************************************************************
* name: Draw_VLineV();
* decs: 画虚线(纵线)
*
*****************************************************************************/
 
void Draw_VLineV(unsigned char x0, unsigned char y0, unsigned char yl)
{
 U8 j;
 
 for(j=y0;j<=yl;j+=2)  
    Draw_Pixel(x0, j);
}

/**********************************************************************
* Name: 
* Desc: 显示点阵
**********************************************************************/

void disp_dz(U8 data1, U8 data2)
{
  U8 i, j;
  write_xd(ADDR_G, COM_SET_ADDRESSPOINTER);

⌨️ 快捷键说明

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