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

📄 lcm.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 5 页
字号:
		else
		{
			Lcm_mirror[y][x] = dd;
			Lcm_Write(dd, LCD_DATA);
		}
		x++;
	}
	y += 1;
	x -= 8;
	Lcm_WriteDot(x++, y, array[8]);
	for (j=9; j<16; j++)
	{
		dd = array[j];
//		Lcm_WriteDot(x, y, dd);
		if ((x % 64) == 0)
			Lcm_WriteDot(x, y, dd);
		else
		{
			Lcm_mirror[y][x] = dd;
			Lcm_Write(dd, LCD_DATA);
		}
		x++;
	}
	Lcm_Cs(LCD_CS_OFF);
}

/*
 Write special format digit & letter to LCD == dot matrix: 16 * 4
*/
void Lcm_WriteSp16x4(byte x, byte y, byte *array)
{
	byte j, dd;
	
	// 8 byte for every charcter.
	Lcm_WriteDot(x++, y, array[0]);
	for (j=1; j<4; j++)
	{
		dd = array[j];
		if ((x % 64) == 0)
			Lcm_WriteDot(x, y, dd);
		else
		{
			Lcm_mirror[y][x] = dd;
			Lcm_Write(dd, LCD_DATA);
		}
		x++;
	}
	y += 1;
	x -= 4;
	Lcm_WriteDot(x++, y, array[4]);
	for (j=5; j<8; j++)
	{
		dd = array[j];
		if ((x % 64) == 0)
			Lcm_WriteDot(x, y, dd);
		else
		{
			Lcm_mirror[y][x] = dd;
			Lcm_Write(dd, LCD_DATA);
		}
		x++;
	}
	Lcm_Cs(LCD_CS_OFF);
}

/* 在指定位置显示或清除小数点 16*4点阵 */
void Lcm_DispDot(byte x, byte y, bool clr)
{
	const byte sectDot16x4[8] = {0, 0, 0, 0, 0x20, 0x70, 0x70, 0x20};
	const byte clrSectDot16x4[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	
	if (clr)
		Lcm_WriteSp16x4(y, x / 8, clrSectDot16x4);
	else
		Lcm_WriteSp16x4(y, x / 8, sectDot16x4);
}

/* 在指定位置显示或清除逗号 16*4点阵 */
void Lcm_DispComma(byte x, byte y, bool clr)
{
	const byte commaDot16x4[8] = {0x80, 0xc0, 0xc0, 0x80, 0, 0x50, 0x30, 0};
	const byte clrCommaDot16x4[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	
	if (clr)
		Lcm_WriteSp16x4(y, x / 8, clrCommaDot16x4);
	else
		Lcm_WriteSp16x4(y, x / 8, commaDot16x4);
}

void Lcm_Disp_numCn(long num, byte dots,byte posY, byte posX,BYTE Reverse,BYTE left_right)
{	
	byte tmp[MAX_LENGTH_15+1];
	byte len;

	tmp[MAX_LENGTH_15] = 0;
	len = LongAndDot2Str(num, dots, tmp, 1, 0, 0, 0);
	if(left_right)//left
		Lcm_DispCn(tmp+MAX_LENGTH_15-len,posY,posX,len,Reverse);
	else //right
		Lcm_DispCn(tmp+MAX_LENGTH_15-len,posY,posX-len,len,Reverse);
}

void Lcm_clr_set(byte posY,byte posX, byte len ,byte Reverse)
{
	byte tmp[MAX_DISP_LEN+10];
	byte i;

	if (len > MAX_DISP_LEN)
		len = MAX_DISP_LEN;
		
	for (i=0; i<len; i++)
		tmp[i] = 0x20;

	Lcm_DispCn(tmp,posY, posX,  len, Reverse);
}

/*****************************************
function: LCM display strings over than a line
be sure that the string is end by '\0'.
*******************************************/
void Lcm_DispCn_Ex(const byte *str, byte posY, byte posX, byte lines,BYTE Reverse)
{
	byte lenth;
	byte i = 0;
	byte j =0;

	lenth = strlen(str);//here the lenth <= lines*MAX_DISP_LEN, 
	
	while(lenth > MAX_DISP_LEN - posX)
	{
		for(i = 0;i<MAX_DISP_LEN;i++)
		{	
			if(str[i] >= 0xa0)
				j = 1;
			else
				j = 0;
			i += j;
		}
		if(i == MAX_DISP_LEN) j =0;
		
		Lcm_DispCn(str,posY,posX,MAX_DISP_LEN-posX-j,Reverse);
		str += MAX_DISP_LEN-posX-j;
		posX = 0;
		posY++;
		lenth -=MAX_DISP_LEN-posX-j;
	}
		Lcm_DispCn(str,posY,posX,MAX_DISP_LEN,Reverse);
}
/*
 Write Chinese/Korean String to LCD
 posX	-- 行 西文字符起始坐标, 即以8点为一个单位. ( from 0 to 3 )
 posY	-- 列 西文字符起始坐标, 即以8点为一个单位. ( from 0 to .. )
 len -- 字符长度,西文以一个字符计算,东文以两个字符计算.
 Reverse -- Reverse display or not
           FALSE for not.
           TRUE for yes.
 注:	支持西文和东方文字的同时显示,西文16*8,东文16*16.
*/
void Lcm_DispCn(const byte *str, byte posY, byte posX, byte maxLen, byte reverse)
{
	byte tmp[32+10];
	byte len;
	byte i;
	
	if (maxLen == 0)
		maxLen = strlen(str);

	posY *= 2;						/* 05-7-7 9:23 added by ZXC */
	if (posX < MAX_CHAR * 2)
	{
		for (len = 0; (len < maxLen) && (*str != 0); )
		{
			if (*str > 0xc8)	// 韩文部首 [0xc9 ~ 0xea].
			{
				memcpy(tmp, KoreaBuShou[*str - 0xc9], 32);
				str++;
				len++;
				if ( reverse )
				{
					for ( i = 0; i < 32; i ++ )				/*For Korean,it is 32 characters*/
						tmp[i] ^= 0xff;
				}
				Lcm_WriteChinese(posX * 8, posY, tmp);
				posX += 2;
			}
			// ASCII,西文字符. 16*8格式.
			else if (*str <= 0x80)
			{
				memcpy(tmp, &dotBuf16x8[(*str - 0x20) * 16], 16);
				if ( reverse )
				{
					for ( i = 0; i < 16; i ++ )
						tmp[i] ^= 0xff;
				}
				str++;
				len++;
				
				Lcm_WriteChnDigit(posX * 8, posY, tmp);
				posX++;
			}
			else // 韩文.
			{
				Lcm_GetDot(*str, *(str+1), tmp);
				str += 2;
				len += 2;
				if ( reverse )
				{
					for ( i = 0; i < 32; i ++ )				/*For Korean,it is 32 characters*/
						tmp[i] ^= 0xff;
				}
				Lcm_WriteChinese(posX * 8, posY, tmp);
				posX += 2;
			}
			if (posX >= MAX_CHAR * 2)
			{
				return;					// 只支持单行显示.
//				posX = 0;
//				posY += 2;
//				if (posY >= 8) return;
			}
		}
	}
}

/*
 Write English charater or number to LCD 12*24
*/
void Lcm_WriteEn24(byte posX, byte posY, const byte *src)
{
	byte line, dot;
	
	for (line=0; line<3; line++)
	{
		// 送起始位置的数据.
		Lcm_WriteDot(posX++, posY, *src++);

		// 送后续数据.
		for (dot=1; dot<12; dot++)
		{
//			Lcm_WriteDot(posX, posY, *src++);
			if ((posX % 64) == 0)
				Lcm_WriteDot(posX, posY, *src++);
			else
			{
				Lcm_mirror[posY][posX] = *src;
				Lcm_Write(*src++, LCD_DATA);
			}
			posX++;
		}

		// 转至下一行起始位置.
		posY += 1;
		posX -= 12;
	}

	Lcm_Cs(LCD_CS_OFF);
}

/*
 Write Chinese charater or number to LCD 24*24
*/
void Lcm_WriteCn24(byte posX, byte posY, const byte *src)
{
	byte line, dot;
	
	for (line=0; line<3; line++)
	{
		// 送起始位置的数据.
		Lcm_WriteDot(posX++, posY, *src++);

		// 送后续数据.
		for (dot=1; dot<24; dot++)
		{
//			Lcm_WriteDot(posX, posY, *src++);
			if ((posX % 64) == 0)
				Lcm_WriteDot(posX, posY, *src++);
			else
			{
				Lcm_mirror[posY][posX] = *src;
				Lcm_Write(*src++, LCD_DATA);
			}
			posX++;
		}

		// 转至下一行起始位置.
		posY += 1;
		posX -= 24;
	}

	Lcm_Cs(LCD_CS_OFF);
}

/*
 Get Chinese/Korean Dot data for LCD display. 12*24字库,每次只转换16个字节,得有效数据12字节.
*/
void Lcd_GetDotEn24Data(byte *obj, const byte *src)
{
	byte i, j, temp;
	const byte dotTrans[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
	
	for (i=0; i < 8; i++)
	{
		temp = 0;
		for (j=0; j<8; j++)
		{
			if (src[j*2] & dotTrans[i])
			{
				temp += (0x01 << j);
			}
		}
		*obj++ = temp;
	}

	// 12*24点阵中,每列的后4个字节为空,故无需转换.
	for (i=0; i < 4; i++)
	{
		temp = 0;
		for (j=0; j<8; j++)
		{
			if (src[j*2+1] & dotTrans[i])
			{
				temp += (0x01 << j);
			}
		}
		*obj++ = temp;
	}
}

#define		KRN_DOT_BASE				(FLS_BASE_ADDR + 0)			/*print characters dot-font*/
#define		ASCII_DOT_BASE				(0xfc0000 + 0x38000)
//#define		ASCII_DOT_BASE				(FLS_BASE_ADDR + 0x2a000)	/*ascii code dot-font base*/

/*
	从打印字库中转换而来. obj: 36 byte, 纵向排列, 12byte * 3行.
*/
void Lcm_GetDotEn24(byte *obj, byte ch)
{
	byte *cfontp;

	cfontp = (byte *)(ch * 48 + ASCII_DOT_BASE);

	// 经标准12*24字库(横向取模)变换得到.
	Lcd_GetDotEn24Data(obj, cfontp);
	Lcd_GetDotEn24Data(obj+12, cfontp+16);
	Lcd_GetDotEn24Data(obj+24, cfontp+32);
}

/*
 Get Chinese/Korean Dot data for LCD display. 24*24字库,每次调用只转换24个字节.
*/
void Lcd_GetDotCn24Data(byte *obj, const byte *src)
{
	byte i, j, temp;
	const byte dotTrans[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
	
	for (i=0; i < 8; i++)
	{
		temp = 0;
		for (j=0; j<8; j++)
		{
			if (src[j*3] & dotTrans[i])
			{
				temp += (0x01 << j);
			}
		}
		*obj++ = temp;
	}

	for (i=0; i < 8; i++)
	{
		temp = 0;
		for (j=0; j<8; j++)
		{
			if (src[j*3+1] & dotTrans[i])
			{
				temp += (0x01 << j);
			}
		}
		*obj++ = temp;
	}

	for (i=0; i < 8; i++)
	{
		temp = 0;
		for (j=0; j<8; j++)
		{
			if (src[j*3+2] & dotTrans[i])
			{
				temp += (0x01 << j);
			}
		}
		*obj++ = temp;
	}
}

/*
	从打印字库中转换而来. obj: 72 byte, 纵向排列, 24byte * 3行.
*/
void Lcm_GetDotCn24(byte *obj, byte qu, byte wei)
{
	byte *cfontp;
	dword offset;

	// 注: 未考虑汉字库前面的全角字符.
	offset = (qu - 0xb0) * (0xfe - 0xa1 + 1) + (wei - 0xa1);
	cfontp = (byte *)(offset * 72 + KRN_DOT_BASE);

	// 经标准24*24字库(横向取模)变换得到.
	Lcd_GetDotCn24Data(obj, cfontp);
	Lcd_GetDotCn24Data(obj+24, cfontp+24);
	Lcd_GetDotCn24Data(obj+48, cfontp+48);
}

/*
 Write Chinese/Korean String to LCD 
 posX	-- 行 西文字符起始坐标, 以4点为一个单位. <<====== 特别注意.
 posY	-- 列 西文字符起始坐标, 以8点为一个单位. ( from 0 to 7 )
 len -- 字符长度,西文以一个字符计算,东文以两个字符计算.
 reverse -- reverse display or not
           FALSE for not.
           TRUE for yes.
 注:	支持西文和东方文字的同时显示,西文12*24,东文24*24.
*/
void Lcm_DispCn24(const byte *str, byte posY, byte posX, byte maxLen, byte reverse)
{
	byte tmp[72+10];
	byte len;
	byte i;
	if (maxLen == 0)
		maxLen = strlen(str);

//	posY *= 2;						/* 05-7-7 9:23 added by ZXC */
	if (posX < MAX_CHAR24 * 6)
	{
		for (len = 0; (len < maxLen) && (*str != 0); )
		{
			// ASCII,西文字符. 12*24格式.
			if (*str <= 0x80)
			{
				Lcm_GetDotEn24(tmp, *str);
				if ( reverse )
				{
					for ( i = 0; i < 36; i ++ )
						tmp[i] ^= 0xff;
				}
				str++;
				len++;
				
				Lcm_WriteEn24(posX * 4, posY, tmp);
				posX += 3;
			}
			else
			{
				Lcm_GetDotCn24(tmp, *str, *(str+1));
				str += 2;
				len += 2;
				if ( reverse )
				{
					for ( i = 0; i < 72; i ++ )
						tmp[i] ^= 0xff;
				}
				Lcm_WriteCn24(posX * 4, posY, tmp);
				posX += 6;
			}
			if (posX >= MAX_CHAR24 * 6)
			{
				return;					// 只支持单行显示.
//				posX = 0;
//				posY += 3;
//				if (posY >= 8) return;
			}
		}
	}
}

/********************************************************************************
* 函数说明:	display picture
* 输入参数:	picture data pointer
* 输出参数:	void
* 返回值:	void
********************************************************************************/
void Lcm_DispPic(const byte *str)
{
	byte x, y;

	for (y=0; y<8; y++) 						// Total 8 pages,
	{
		for (x=0; x<LCMLIMIT; x++)				// 128 rows for every page.
		{
			Lcm_WriteDot(x, y, *str++);
		}
	}
	//LcmBlOn();
	Lcm_Cs(LCD_CS_OFF);
}

/********************************************************************************
* 函数说明:	循环显示"YOU ARE WELCOME!",
* 输入参数:	picture data pointer
* 输出参数:	void
* 返回值:	void
********************************************************************************/
void Lcm_DispPicDemo(const byte *str, byte posX, byte font, byte cnt)
{
	byte x, y, maxLine;
	byte dotBuf[LCMLIMIT*2+20];
	byte i, len = strlen(str);
	byte *ptr = dotBuf;
	byte dotBuf2[LCMLIMIT+10];

	// 转换字符串到点阵数据.
	memset(dotBuf, 0, LCMLIMIT*2);
	memset(dotBuf2, 0, LCMLIMIT);
	if (len > 22)
	{
		len = 22;
	}
	if (font == FONT_5)
	{
		for (i=0; i<len; i++)
		{
			memcpy(ptr, &dotBuf5x7[(*str++-0x20)*5], 5);
			ptr += 5;
			*ptr++ = 0;
		}
		maxLine = 1;
	}
	else
	{
		return;												// 暂不支持16*8字体.
//		for (i=0; i<len; i++)
//		{
//			memcpy(ptr, &dotBuf16x8[(*str++-0x20)*16], 8);
//			memcpy(ptr+LCMLIMIT, &dotBuf16x8[(*str++-0x20)*16+8], 8);
//			ptr += 16;
//		}
//		maxLine = 2;
	}

	if (cnt < LCMLIMIT)
	{
		memcpy(dotBuf2, &dotBuf[LCMLIMIT-1-cnt], cnt+1);
	}	
	else
	{
		memcpy(&dotBuf2[cnt-LCMLIMIT], dotBuf, LCMLIMIT-(cnt-LCMLIMIT));
	}
	
	for (y=0; y<maxLine; y++)
	{

⌨️ 快捷键说明

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