/******************** (C) COPYRIGHT 2010 Embest Info&Tech Co.,LTD. ************
* 文件名: main.c
* 作者 : Wuhan R&D Center, Embest
* 日期 : 01/18/2010
* 描述 : 主程序源文件.
*******************************************************************************
*******************************************************************************
* 历史:
* 01/18/2010 : V1.0 初始版本
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stdfx.h"
uint8_t dest_addr[SSP_RECEIVEBUFSIZE];
uint8_t current_pageNum; //当前页的号码
uint8_t page_count; //页的数量最小值为1
uint8_t line_count;
uint8_t rowNum;//每一页上的行号
uint8_t page_type;//0x31,表示常显页面;0x032 代表分组画面,0x33代表的是项目详细画面
extern volatile uint8_t UARTBuffer[32][BUFSIZE];
extern volatile uint32_t timer32_0_counter;
extern volatile uint8_t receive_finish_flag;
extern uint8_t keyboard_nm;
void parseuartdata(void);
//void showLogoPage(void);
void gbcodetospi(uint8_t *ss,uint8_t type);
void outputprojectName(volatile uint8_t *data,uint8_t len,uint8_t x,uint8_t y);
void outputascii(volatile uint8_t *data,uint8_t len,uint8_t x,uint8_t y); //项目数值和项目单位用ascii来输出
void init_receive_uart_info(void);
//void test(void);
/**
* @函数名:main
* @描述:主函数
* @参数: 无
* @返回值:无
*/
int main (void)
{
SystemInit();
/* NVIC配置包含在UARTInit()函数中 */
/* 初始化 IO */
GPIOInit();
/* 配置输入管脚 */
setInputPins();
/* 配置输出管脚 */
setOutputPins();
KEYBOARD_Init();
//spi configuration and spi initialization
SSP_IOConfig();
SSP_Init();
//LCD initialization
LCD_IO_INIT();
LCD_INIT();
UARTInit(9600);
//测试点“啊”的显示
CLR_SCR();
//showLogoPage();
init_timer32(0, TIME_INTERVAL);
enable_timer32(0);
// test();
while(1)
{
//处理键盘按键事件
detectKEYBOARD();
//receive the data from the comm port
if(receive_finish_flag){
CLR_SCR();
init_receive_uart_info();
parseuartdata();
}
if((keyboard_nm==0x01) | (keyboard_nm==0x02) ){
//当有向上或者向下的按键时候
CLR_SCR();
parseuartdata();
keyboard_nm=0x00;
}
//wait 15s to close the lamp
if (timer32_0_counter==1500){
if(!GPIOGetValue(PORT1, 9)){
GPIOSetValue( PORT1, 9, 1 );//关闭背景光
timer32_0_counter=0;
}
}
}
}
/**
* @ k,l 初始化显示的坐标,k 为x轴,l为y轴
*/
void parseuartdata(){
uint8_t cyc_flag,data_len,x;
uint8_t l_len,r_len;
uint8_t lineNum,off_len;
uint8_t newLineFlag;
uint8_t gb_code[2]={0xa1,0xef};
cyc_flag=0x00;
page_type=UARTBuffer[0][1];
data_len=UARTBuffer[0][3];
x=0;
lineNum=0x00;
off_len=0x00;
newLineFlag=0x00;//0x02是汉字输出 0x03是ascii
if(page_type==0X31 | page_type==0x33){
x=4;
}else if(page_type==0x32){
x=14;
gbcodetospi(gb_code,TYPE_12);
Write_Hanzi_Single(0,rowNum*16,dest_addr,TYPE_12);
}
while(cyc_flag!=0x0f && UARTBuffer[0][0]==0x01){
if(newLineFlag==0x02){
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputprojectName(UARTBuffer[0]+3+off_len,data_len,x,lineNum*16-current_pageNum*64);
}
off_len+=(data_len+1);
newLineFlag=0x00;
}
//当协议包没有结束的时候
if(*(UARTBuffer[0]+2+off_len)==0x02){
//当有项目名称要输出的时候
off_len+=1; //data_length bit
data_len=*(UARTBuffer[0]+2+off_len);
//off_len+=1;//指向待输出的单元
if(data_len>20){
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputprojectName(UARTBuffer[0]+3+off_len,20,x,lineNum*16-current_pageNum*64);
}
off_len+=20;
data_len-=20; //下一行需要输出的汉字byte数量
newLineFlag=0x02;
}else{
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputprojectName(UARTBuffer[0]+3+off_len,data_len,x,lineNum*16-current_pageNum*64);
}
off_len+=(data_len+1);
}
}
if(*(UARTBuffer[0]+2+off_len)==0x03){
uint8_t val_data_len_byte,val_data_len,start_pos;
off_len+=1; //data_length bit
val_data_len_byte=*(UARTBuffer[0]+2+off_len);
l_len=(val_data_len_byte&0xf0)>>4;
r_len=(val_data_len_byte&0x07);
val_data_len=l_len+((val_data_len_byte&0x08)>>3)+r_len;
//获取数字起始坐标
// if((val_data_len_byte&0x08)){
// //当有小数点的时候
// start_pos=95-(val_data_len*6-1);
// }else{
// start_pos=95-(val_data_len*6);
// }
start_pos=95-(val_data_len*6);
if((4+data_len*6)<start_pos){
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputascii(UARTBuffer[0]+3+off_len,val_data_len,start_pos,lineNum*16-current_pageNum*64);
}
}else{
lineNum++;
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputascii(UARTBuffer[0]+3+off_len,val_data_len,start_pos,lineNum*16-current_pageNum*64);
}
}
off_len+=(val_data_len+1);
}
if(*(UARTBuffer[0]+2+off_len)==0x04){
uint8_t unit_len,start_pos;
off_len+=1; //data_length bit
unit_len=*(UARTBuffer[0]+2+off_len);
start_pos=99;
if((lineNum*16-current_pageNum*64)>=0 && (lineNum*16-current_pageNum*64)<=63){
outputascii(UARTBuffer[0]+3+off_len,unit_len,start_pos,lineNum*16-current_pageNum*64);
}
off_len+=(unit_len+1);
}
lineNum++;
cyc_flag=*(UARTBuffer[0]+2+off_len);
}
page_count=lineNum/4;
if(lineNum%4){
page_count++;
}
line_count=lineNum;
}
void gbcodetospi(uint8_t *gbcode,uint8_t type){
uint8_t i;
uint8_t AddH,AddM,AddL;
uint8_t ssp_receive_size;
uint8_t src_addr[SSP_SENDBUFSIZE];
unsigned long gb_dot_address; //存储汉字 “啊” 的点阵起始地址。
if(type==TYPE_12){
ssp_receive_size=24;
}else if(type==TYPE_16){
ssp_receive_size=32;
}else if(type==TYPE_8){
ssp_receive_size=8;
}
gb_dot_address=GB2312_Addr(gbcode,type);
AddH=0xff&(gb_dot_address>>16);
AddM=0xff&(gb_dot_address>>8);
AddL=0xff&gb_dot_address;
src_addr[0] = 0x03;
src_addr[1] = AddH;
src_addr[2] = AddM;
src_addr[3] = AddL;
for ( i = 0; i <ssp_receive_size; i++ )
{
dest_addr[i] = 0;
}
GPIOSetValue( PORT1, 10, 0 );
SSP_Send((uint8_t *)src_addr,SSP_SENDBUFSIZE);
SSP_Receive((uint8_t *)dest_addr,ssp_receive_size);
GPIOSetValue( PORT1, 10, 1 );
}
void outputprojectName(volatile uint8_t *data,uint8_t len,uint8_t x,uint8_t y){
uint8_t i;
uint8_t gbcode[2];
for(i=0;i<len;i++){
gbcode[(i%2)]=data[i];
if((i%2)==1){
gbcodetospi(gbcode,TYPE_12);
Write_Hanzi_Single(x+(i-1)*6,y,dest_addr,TYPE_12);
}
}
}
void outputascii(volatile uint8_t *data,uint8_t len,uint8_t x,uint8_t y){
uint8_t i;
uint8_t gbcode;
int8_t j;
uint8_t ledcode[]={0x02,0x05,0x02}; //℃符号自定义显示部分
j=-1;
for(i=0;i<len;i++){
gbcode=data[i];
if(gbcode==0X05){ //当要显示的是℃的时候
Write_Picture(x+i*6,y+4,3,8,ledcode);
j=i;
gbcode=0x43;
}
gbcodetospi(&gbcode,TYPE_8);
if(j>=0 && i>=j){
//Write_Hanzi_Single(x+i*6+3,y+4,dest_addr,TYPE_8);
}else{
Write_Hanzi_Single(x+i*6,y+4,dest_addr,TYPE_8);
}
}
}
// void test(){
// uint8_t i;
// //无功电度 300.7KVAH
// //uint8_t gb_code[8][2]={{0xa3,0xb7},{0xa3,0xb8},{0xa3,0xae},{0xa3,0xb5},{0xa1,0xe6},{0xa3,0xd7},{0xa3,0xd0},{0xa3,0xe1}};//87.5℃ W Pa
////uint8_t gb_code[2]={0xa3,0xae};
////gbcodetospi(gb_code,TYPE_12);
////Write_Hanzi_Single(3,0,dest_addr,TYPE_12);
//
// //uint8_t gb_code[2]={42,67};
//// for(j=0;j<8;j++){
//// gbcodetospi(gb_code[j],TYPE_12);
//// if(j==4){
//// Write_Hanzi_Single(j*8-2,0,dest_addr,TYPE_12);
//// }else if(j==3){
//// Write_Hanzi_Single(j*8-3,0,dest_addr,TYPE_12);
//// }else if(j>4){
//// Write_Hanzi_Single(j*12-2,0,dest_addr,TYPE_12);
//
评论0