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

📄 example_gb2312.c

📁 C8051F020单片机开发板演示程序
💻 C
字号:
/************************************************************************************
*  Copyright (c), 2004-2007,西安铭朗电子科技有限责任公司
*            All rights reserved.
*
* Http:  www.mlarm.com
* Email: mlarm@mlarm.com
*
* File name: Example_GB2312.c
*
* Project  : ML-F020ICB
* Processor: C8051F020
* Compiler : Keil C51 Compiler
* 
* Author:  EagleC
* Version: 1.00
* Date:    2007.07.05
* Email:   
* 
* Description: 下载字库到flash中。
*
* Others: none;
*
* Function List:
*
* History:
*   1. Author:       Eagle Cao
*	   Version: 	 1.00
*      Date:         2007.07.05
*      Modification: 建立文件
*
*************************************************************************************/

/************************************************************************************/
// 引用外部头文件
#include  "driver.h"
#include  "api.h"
#include  "ShowLCD.h"
extern unsigned char code HZ_H_8X2[16];

/***********************************************************************************
* 函数名称:Flash_Proc;
*
* 函数功能描述:下载字库到Flash中
*              
* 输入参数:none;
*
* 返回数据:none;
*
* 注意:    none;
************************************************************************************/
void Flash_Proc(void)
{
	unsigned int i;
	unsigned char j,cmd,key;
	unsigned char ucRet,ucRecTimes;
	unsigned char nX;
	unsigned int  nY;	
	
	unsigned long addres;
	char *pMessage;
	
	unsigned char temp[128];
	
	unsigned long showAdd;
	unsigned char cBit;
	unsigned char *pItem; 
	
	LCDB_ClearScreen();
	Show_Title();
	LCDB_DispFWord(32,8*(20-5),"字 库 下 载");
	
	WDTCN = 0xde;
   	WDTCN = 0xad;	
	CH452_Write(CH452_DIG7 | 0);
	CH452_Write(CH452_DIG6 | 0);
	CH452_Write(CH452_DIG5 | 0);
	CH452_Write(CH452_DIG4 | 0);
	CH452_Write(CH452_DIG3 | 0);
	CH452_Write(CH452_DIG2 | 0);
	CH452_Write(CH452_DIG1 | 0);
	CH452_Write(CH452_DIG0 | 0);

	//功能确认
	pMessage = "Push'D' to continue or Push'F' to end";
	LCDB_DispFWord(240-16, 16,pMessage);					
	while (1) 
	{
		EWachdog_Clear();
		key = Key_Read();
		switch(key) {
		case 0x0D:
			ALARM_Ctrl(1);
			Delay_ms(20);
			ALARM_Ctrl(0);				
			Show_ClareX64();
			pMessage = "Wait for FSend Begin                 ";
			LCDB_DispFWord(240-16, 16*2,pMessage);					
			//等待上层通讯开始
			do{
				EWachdog_Clear();
				ucRet = Uart0_RecvChar(&cmd);
				key = Key_Read();
				if(key == 0x0F)//在等待中可以返回
				{
					CH452_Write(CH452_DIG7 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG6 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG5 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG4 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG3 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG2 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG1 | CH452_BCD_SPACE);
					CH452_Write(CH452_DIG0 | CH452_BCD_SPACE);
					return;
				}
				if(ucRet != UART_ERR_OK) continue;
			}while(cmd!='C');
			
			pMessage = "Begin, Send......                    ";
			LCDB_DispFWord(240-16, 16*2,pMessage);					
			//擦除Flash
			Flash_Erase();
			
			//通讯开始
			Uart0_SendChar('C');
			Delay_ms(100);
		
			nX = 64;	nY = 32;
			i=0;
			addres=0x00000;	
			do{	
				EWachdog_Clear();
				j=0;
				//通知上层开始发送
				Uart0_SendChar('S');
				Delay_ms(20);
				ucRecTimes = 0;
				while(Uart0_GetCharsRxBuf() <128)
				{
					EWachdog_Clear();
					Delay_ms(20);
					if(ucRecTimes++>5) break;
				}
				ucRecTimes = 0;
				while(j<128)//接收128字节
				{					
					EWachdog_Clear();
					ucRet = Uart0_RecvChar(&temp[j]);
					if(ucRet == UART_ERR_OK) j++;
					else if(ucRecTimes++>5)
					{
					 	Uart0_SendChar('T');
						pMessage = "下载失败                             ";
						LCDB_DispFWord(240-16, 16*2,pMessage);					
						ALARM_Ctrl(1);
						Delay_ms(600);
						ALARM_Ctrl(0);	
						return;
					 }
				}
				//将接收的数据写入Flash中。
				Flash_Write(addres,temp,128);
				
				// 绘制进度条
				if(addres%0x8000 == 0) {nX += 16; nY =32;}
				if(addres%0x400 == 0){LCDB_ShowHZxy (nX, nY, 16, 8, HZ_H_8X2);nY += 8;}
				// 数码管显示当前显示存储位置
				addres+=128;i++;
				showAdd = addres;cBit = showAdd % 10;CH452_Write(CH452_DIG0 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG1 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG2 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG3 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG4 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG5 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG6 | cBit);
				showAdd /= 10;cBit = showAdd % 10;CH452_Write(CH452_DIG7 | cBit);				
			}while(i<2048);
			//发送接收通知。
			Uart0_SendChar('T');
			pMessage = "下载完毕                             ";
			LCDB_DispFWord(240-16, 16*2,pMessage);					
			ALARM_Ctrl(1);
			Delay_ms(20);
			ALARM_Ctrl(0);	
			break;
		case 0x0E:
			ALARM_Ctrl(1);
			Delay_ms(20);
			ALARM_Ctrl(0);				
			Show_ClareX64();
			nX = 64;
			pItem = "本测试程序主要是下载字库到Flash中。屏幕最下边有步骤提示。此程序与PC机字库下载软件配合使用,完成字库下载。"; 
			LCDB_DispFWord(nX, 32,pItem);
			
			pItem = "D:下载确认";
			LCDB_DispFWord(nX+16*3, 56,pItem);
			pItem = "E:帮助";
			LCDB_DispFWord(nX+16*4, 56,pItem);
			pItem = "F:返回";
			LCDB_DispFWord(nX+16*5, 56,pItem);
			break;
		case 0x0F:
			ALARM_Ctrl(1);
			Delay_ms(20);
			ALARM_Ctrl(0);				
			CH452_Write(CH452_DIG7 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG6 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG5 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG4 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG3 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG2 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG1 | CH452_BCD_SPACE);
			CH452_Write(CH452_DIG0 | CH452_BCD_SPACE);
			return;
		}
	}// end while(1)
}

⌨️ 快捷键说明

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