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

📄 lcm.c

📁 ATmega64+12864液晶
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
file name:lcm.c
function: lcm applicantion interface
author :Einsn
date:2006-12-24



*/

#include "lcm.h"

#include <stdlib.h>  //malloc free
#include <string.h>
#include <avr/pgmspace.h>//for pgmreadbyte

//#include "at45db041b.h"  //include the asc & hz lib
//#include "clib.h"

#include "sigtimer.h"   //the cursor use the timer signal

#define SetBit(dat,bit,val)   (dat=(dat&(~(1<<bit)))|(val<<bit))

/*
file name:LcmGetHZLibData
function: use internel lib
author :Einsn
date:2007-01-06


*/
#if 0
static void LcmGetHZLibData(char *chn,uint8* pbyte){
PGB16 pGb16=(PGB16)&CLIBHZ16[0];
prog_char *pgm=&pGb16->Index[0];

do{
if(*chn==pgm_read_byte(pgm)&&*(chn+1)==pgm_read_byte(pgm+1)){
	//find the lib byte;
	pgm=&pGb16->Msk[0];
	for(uint8 i=0;i<32;i++){
		*pbyte++=pgm_read_byte(pgm++);
		}
	return;
	}
pGb16++;
pgm=&pGb16->Index[0];
}while(pgm_read_byte(pgm)!=0);
//not find
memset(pbyte,0xe7,32);

}




/*
file name:LcmGetASC16LibData
function: use internel lib
author :Einsn
date:2007-01-06


*/

static void LcmGetASC16LibData(char ch,uint8 *pbyte){
prog_char *pgm=(prog_char*)&CLIBAsc16[0];
uint16 offset;
if(ch<0x20||ch>0x80)return;
offset=(ch-0x20)*16;
pgm+=offset;
for(uint8 i=0;i<16;i++){
	*pbyte++=pgm_read_byte(pgm++);
	}
}

#endif



/*
#define HZLIBPAGEOFFS  1024

void LcmGetHZLibData(uint32 hzoffs,uint8* pbyte){
uint16 page=HZLIBPAGEOFFS;
page+=hzoffs/PAGESIZESOFBYTE;
uint16 byte=hzoffs%PAGESIZESOFBYTE;
DFContinousArrayRead(page,byte,pbyte,32);
}

#define ASCLIBPAGEOFFS   (1024+1014)

void LcmGetASC16LibData(char ch,uint8 *pbyte){
uint16 page=ASCLIBPAGEOFFS;
uint16 byte=(ch-0x20)*16;
page+=byte/PAGESIZESOFBYTE;
byte=byte%PAGESIZESOFBYTE;
DFContinousArrayRead(page,byte,pbyte,16);
}

*/



//--------------------------------------------------
//
//Author: 刘传森
//Date:2006-11-05
//
//xrow 列向点地址
//col 行向点地址 
//
//--------------------------------------------------

/*
name:LcmDLine
function:
author:einsn
date :2006-12-24


*/

#define MIN(x,y)  (y>x?x:y)
#define MAX(x,y)   (y<=x?x:y)
#define DIF(x,y)     (y>x?y-x:x-y)

int8 LcmDLine(uint8 sxrow,uint8 scol,uint8 dxrow,uint8 dcol)
{
uint8 bf;

bf=!(sxrow>>7);
sxrow=sxrow&0x7f;
if(sxrow==dxrow)
{
	uint8 n=DIF(scol,dcol)+1;
	uint8 xl;
	char *pbyte=(char *)malloc(n);
	LcmGetRowData(sxrow/8,MIN(scol,dcol), pbyte,n);
	xl=0;
	while(xl<n){
		SetBit(*(pbyte+xl),sxrow%8,bf);
		xl++;
		}
	LcmPutRowData(sxrow/8,MIN(scol,dcol), pbyte,n);
	free(pbyte);

}else if(scol==dcol)
	{
		for(uint8 i=MIN(sxrow,dxrow);i<=MAX(sxrow,dxrow);i++)
		{
			LcmDot(i,scol,bf);
		}
	}
else return -1;
return 0;
}


//--------------------------------------------------
//
//Author: 刘传森
//Date:2006-11-05
//
//xrow 列向点地址
//col 行向点地址 
//--------------------------------------------------

/*
name:LcmDRect
function:
author:einsn
date :2006-12-24


*/

#define RECT_LINE_CLR(ctrl)   ((ctrl&RECT_CLR)<<7)
#define RECT_SHADOW_SIZE(ctrl)   ((ctrl&RECT_SHADOW)>>2) 
#define RECT_FRAME_SIZE(ctrl)  ((ctrl&RECT_FRAME)>>4)

int8 LcmDRect(uint8 sxrow,uint8 scol,uint8 rlen,uint8 clen,uint8  ctrl)
{

if(ctrl&RECT_FILL)//Fill the Rect with the CLR bit
	{
	if(rlen>clen)
		{
		for(uint8 i=0;i<clen;i++)
			{
			LcmDLine(sxrow|RECT_LINE_CLR(ctrl) ,scol,sxrow+rlen-1,scol);
			scol++;
			}		
		}else {//rlen<clen,fill the rect by col line
			for(uint8 i=0;i<rlen;i++)
			{
			LcmDLine(sxrow|RECT_LINE_CLR(ctrl) ,scol,sxrow,scol+clen-1);
			sxrow++;
			}
		}
		
	}else {//draw the rect with a frame,size:FRAME bits	
	if(ctrl&RECT_SHADOW)
		{
		LcmDLine((sxrow+rlen+1)|RECT_LINE_CLR(ctrl) ,scol+1,(sxrow+rlen+1),scol+clen+1);//shadow  line1
		LcmDLine((sxrow+1)|RECT_LINE_CLR(ctrl) ,scol+clen+1,sxrow+rlen+1,scol+clen+1);//right line
		if(RECT_SHADOW_SIZE(ctrl)>1){
		LcmDLine((sxrow+rlen+2)|RECT_LINE_CLR(ctrl) ,scol+1,(sxrow+rlen+2),scol+clen+2);//shadow line2
		LcmDLine((sxrow+1)|RECT_LINE_CLR(ctrl) ,scol+clen+2,sxrow+rlen+1,scol+clen+2);//right line
		}
		}
	
	uint8 frame=RECT_FRAME_SIZE(ctrl)+1;//get the frame size;
	if(frame>rlen||frame>clen)return -1;//wrong parameter
	for(uint8 i=0;i<frame;i++)
	{
	LcmDLine(sxrow|RECT_LINE_CLR(ctrl) ,scol,sxrow,scol+clen-1);//top line
	LcmDLine((sxrow+rlen-1)|RECT_LINE_CLR(ctrl) ,scol,(sxrow+rlen-1),scol+clen-1);//bottom line
	LcmDLine(sxrow|RECT_LINE_CLR(ctrl) ,scol,sxrow+rlen-1,scol);//left  line
	LcmDLine(sxrow|RECT_LINE_CLR(ctrl) ,scol+clen-1,sxrow+rlen-1,scol+clen-1);//right line
	sxrow++;
	scol++;
	rlen-=2;
	clen-=2;
	}	
	}
return 0;
}


/*
name:DispChnAsc
function:
author:einsn
date :2006-12-25


*/

#if 0
static void DispChnAsc(uint8 xrow,uint8 col, uint8 *ph,uint8 colwide)
{

if(xrow%8==0)
{
xrow/=8;
LcmPutRowData(xrow,col,ph,colwide);
LcmPutRowData(xrow+1,col,ph+colwide,colwide);

}else{

uint8 xl=xrow%8;
uint8 ByteMask[8]={0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};
uint8 i;
uint8 *pm=(uint8 *)malloc(colwide);
if(pm==NULL){
	return ;
	}
xrow/=8;
LcmGetRowData(xrow,col, pm, colwide);
for( i=0;i<colwide;i++)
	{
	*(pm+i)=(*(ph+i)<<xl)|(*(pm+i)&ByteMask[xl]);
	}
LcmPutRowData(xrow,col,pm,colwide);
for( i=0;i<colwide;i++)
	{
	*(pm+i)=(*(ph+i)>>(8-xl))|(*(ph+colwide+i)<<xl);	
	}
LcmPutRowData(xrow+1,col,pm,colwide);
LcmGetRowData(xrow+2,col, pm, colwide);
for( i=0;i<colwide;i++)
	{
	*(pm+i)=(*(ph+i+colwide)>>(8-xl))|(*(pm+i)&~ByteMask[xl]);
	}
LcmPutRowData(xrow+2,col,pm,colwide);

free(pm);

}

}


//--------------------------------------------------
//向液晶写个18*16的ASCII字符
//Author: 刘传森
//Date:2006-11-05
//
//xrow 列向点地址
//col 行向点地址 
//--------------------------------------------------
/*
name:LcmPAsc
function:
author:einsn
date :2006-12-25


*/

static int  LcmPAsc(uint8 xrow,uint8 col,char asc)
{
uint8 rev=xrow>>7;
uint8 *pch;
xrow&=0x7f;
pch=(uint8 *)malloc(16);
if(pch==NULL)return -1;
//memset(phz,0,16);

LcmGetASC16LibData(asc,pch);

if(rev){
	for(uint8 i=0;i<16;i++){
		*(pch+i)=~(*(pch+i));
		}
	}
DispChnAsc(xrow,col,pch,8);
free(pch);
return 0;
}


//--------------------------------------------------
//向液晶写个16*16的汉字
//Author: 刘传森
//Date:2006-11-05
//
//xrow 列向点地址
//col 行向点地址 
//--------------------------------------------------

/*
name:LcmPChn
function:
author:einsn
date :2006-12-25


*/

static int8 LcmPChn(uint8 xrow,uint8 col,char *str)
{
uint8 rev=xrow>>7;
//uint32 ChnCode=*str;
uint8 *phz;

xrow&=0x7f;

phz=(uint8 *)malloc(32);
if(phz==NULL)return -1;

LcmGetHZLibData(str,phz);

/*
ChnCode=(ChnCode<<8)+(*(str+1)&0x00ff);
if(ChnCode<0xa0a0)
	return -1;
ChnCode-=0xa0a0;

//memset(phz,0,32);

uint32 HZOffs=32*(((ChnCode>>8)-1)*94+(ChnCode&0x00ff)-1);

LcmGetHZLibData(HZOffs,phz);

*/
if(rev){
	for(uint8 i=0;i<32;i++){
		*(phz+i)=~(*(phz+i));
		}
	}

DispChnAsc(xrow,col,phz,16);

free(phz);
return 0;
}


/*
name:LcmPStr
function:
author:einsn
date :2006-12-25


*/

int8 LcmWStr(uint8 xrow,uint8 col,char *str)
{

while(*str!='\0'){
if(*(uint8 *)str<=128){
	LcmPAsc(xrow,col,*str++);
	col+=8;
	}else {
	if(LcmPChn(xrow,col,str++)==0){
		str++;
		col+=16;
		}
	}
}
return 0;
}


/* 
 * Name:LcmWCStr( )
 * Function: 
 * 
 * In:the lstr struct handle
 * Out:true
 *
 * Author:Einsn Liu
 * Date:2007-01-20
 * 
 */
 int8 LcmWCStr(uint8 xrow,uint8 col,char *str,uint8 cnt)
{
while(*str!='\0'&&cnt-->0){
if(*(uint8 *)str<=128){
	LcmPAsc(xrow,col,*str++);
	col+=8;
	}else if(cnt!=0){
	if(LcmPChn(xrow,col,str++)==0){
		str++;
		col+=16;
		cnt--;
		}
	}
}
return 0;
}




/*
name:LcmWStr
function:Add to support the Flash data write
author:einsn
date :2006-12-09


*/

void LcmWFStr(uint8 xrow,uint8 col,prog_char *fstr)
{
char *p;
p=malloc(strlen_P(fstr)+1);
if(p==NULL)return;
strcpy_P(p,fstr);
LcmWStr(xrow,col,p);
free(p);
}

#endif 
//--------------------------------------------------
//Function MemCopy()
//Author: 刘传森
//Date:2006-11-26
//列向驱动
//xrow 列向点地址
//col 行向点地址 
//--------------------------------------------------

/*
7	6	5	4	3	2	1	0
|	|	|	|	|	|	|	|	
|	|	|	|	|	|	|	Revers 			
|	|	|	|	|	| 	Left shift en
|	|	|	|	|	right shift en
|	|	shift bits value

*/


#define MCREVERS  0
#define MCLSEN   1
#define MCRSEN   2
#define MCSHIFTBITS  3

#define MC_REVERS(x)   (x&(1<<MCREVERS))
#define MC_LSEN(x)   (x&(1<<MCLSEN))
#define MC_RSEN(x)  (x&(1<<MCRSEN))
#define MC_SHIFTBITS(x)  ((x&(7<<MCSHIFTBITS))>>3) 
/*
name:MemCopy
function:
author:einsn
date :2006-12-24


*/

#ifdef AVRBITMAPPGM
static int8 MemCopy(BITMAP*src,uint8 *dst,uint16 size,uint8 ctrl){
#else
static int8 MemCopy(uint8 *src,uint8 *dst,uint16 size,uint8 ctrl){
#endif
//if(src==NULL||dst==NULL)return -1;
while(size--){	
if(MC_REVERS(ctrl)){	
#ifdef AVRBITMAPPGM
*dst=~(pgm_read_byte(src++));
#else
*dst=~(*src++);
#endif
}else {
#ifdef AVRBITMAPPGM
*dst=pgm_read_byte(src++);
#else
*dst=*src++;
#endif
}
if(MC_LSEN(ctrl)){
*dst=(*dst)<<MC_SHIFTBITS(ctrl);
}else if(MC_RSEN(ctrl)){
*dst=(*dst)>>MC_SHIFTBITS(ctrl);
}
dst++;
}
return 0;
}




//--------------------------------------------------
//Function:LcmDPic()
//Author: 刘传森
//Date:2006-11-26
//列向驱动
//xrow 列向点地址
//col 行向点地址 
//--------------------------------------------------

/*
name:LcmDPic
function:
author:einsn
date :2006-12-24


*/
#ifdef AVRBITMAPPGM
int8 LcmDPic(uint8 sxrow,uint8 scol,uint8 high,uint8 wide,uint8  ctrl,BITMAP* pp){
#else
int8 LcmDPic(uint8 sxrow,uint8 scol,uint8 high,uint8 wide,uint8  ctrl,uint8* pp){
#endif
uint8 row,drow;
uint8 *pm;
uint8 offs;
uint8 ByteMask[8]={0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};
drow=(sxrow+high)/8;
offs=sxrow%8;

if((sxrow&0x7f)> ROWSIZE*8-1 || scol > COLSIZE-1)
	return -1;

//alloc a scol size mem
pm=(uint8*)malloc(wide);
if(pm==NULL)return -1;
//memset(pm,0,wide);

for( row=sxrow/8;row<drow+1;row++){
//Get a row line data
{

⌨️ 快捷键说明

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