#include #include "main.h" #include "flash.h" #include "display.h" #include "buffer.h" #include "button.h" #include "usart.h" #include #include "weight.h" #include "plan.h" #include "daScreen.h" #include "xBeeAppEscapingMode.h" rt_sem_t display_lock = RT_NULL; struct rt_event display_event; uint8_t MenuItem=0; //当前菜单 uint8_t WeightConst_Feed_display[40]; //显示标题 uint8_t WeightConst_Weight_display[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量 uint8_t WeightConst_WeightCur_display[5] = {0x20,0x20,0x20,0x20,0x20}; //显示重量 uint8_t WeightConst_Weight_display_old[8] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; //显示重量 static signed long WeightConst_Weight_displayW; //显示重量 static signed long WeightConst_Weight_displayCurW; //显示重量 unsigned char WeightConst_displayTotal = 0; //0差重,1实重 unsigned char WeightConst_remoteDisplay = 0; unsigned char RemoteSendDisplay = 1; extern unsigned char iscowweight; extern unsigned char remote_sumweight; const uint8_t MenuItemList[12][8] = {{0xC9,0xE8,0xB1,0xB8,0xB5,0xD8,0xD6,0xB7}, //设备地址 {0xCC,0xE1,0xC8,0xA1,0xB7,0xBD,0xCA,0xBD}, //提取方式 {0xCD,0xF8,0xC2,0xE7,0xB1,0xE0,0xBA,0xC5}, //网络编号 {0xC9,0xE8,0xB1,0xB8,0xC0,0xE0,0xD0,0xCD}, //设备类型 {0x54,0x4D,0x52,0xCA,0xFD,0xC1,0xBF,0x20}, //铲车数量 {0x41,0x50,0x49,0x20,0x20,0x20,0x20,0x20}, //API {0xD0,0xA3,0xD5,0xFD,0xD6,0xD8,0xC1,0xBF}, //校正重量 {0xD7,0xEE,0xB4,0xF3,0xB3,0xC6,0xC1,0xBF}, //最大称量 {0xC2,0xCB,0xB2,0xA8,0xC9,0xEE,0xB6,0xC8}, //滤波深度 {0xD0,0xA1,0xCA,0xFD,0xB5,0xE3,0x20,0x20}, //小数点 {0xB7,0xD6,0xB6,0xC8,0xD6,0xB5,0x20,0x20}, //分度值 {0xB8,0xF4,0xC0,0xEB,0xD6,0xD8,0xC1,0xBF} //重量隔离 }; const uint8_t MenuTQTypeList[15][8] = { {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}, {0x4E,0x45,0x57,0x4C,0x61,0x62,0x65,0x6C}, //NewLabel {0x5A,0x4D,0x33,0x30,0x33,0x20,0x20,0x20}, //AWT_ZM303 {0x58,0x4B,0x33,0x31,0x39,0x30,0x20,0x20}, //XK3190_A27E() {0x54,0x4D,0x52,0x20,0x32,0x20,0x20,0x20}, //TMR2 {0x54,0x4D,0x52,0x20,0x33,0x20,0x20,0x20}, //TMR3 {0x45,0x5A,0x33,0x34,0x30,0x30,0x20,0x20}, //EZ3400 {0x41,0x44,0x32,0x35,0x30,0x20,0x20,0x20}, //AD250 TQ {0x50,0x54,0x4D,0x20,0x20,0x20,0x20,0x20}, //PTM {0x54,0x2D,0x32,0x30,0x30,0x30,0x20,0x20}, //T_2000 {0x53,0x4C,0x31,0x30,0x30,0x30,0x30,0x20}, //XL10000 {0x58,0x4B,0x33,0x31,0x39,0x30,0x43,0x38}, //P_XK3190_C8(); {0x54,0x44,0x49,0x32,0x30,0x30,0x49,0x20}, //TDI200I {0x49,0x44,0x35,0x31,0x31,0x20,0x20,0x20}, //ID511; {0xD7,0xD4,0xB6,0xAF,0x20,0x20,0x20,0x20} //自动 }; const uint8_t MenuSBTypeList[5][8] = { {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}, {0xBF,0xD8,0xD6,0xC6,0xC6,0xF7,0x20,0x20}, //控制器 {0xD4,0xB6,0xB3,0xCC,0xCF,0xD4,0xCA,0xBE}, //远程显示 {0xB4,0xF3,0xC6,0xC1,0x20,0x20,0x20,0x20}, //大屏 {0xB4,0xF3,0xC6,0xC1,0x31,0x20,0x20,0x20} //LED大屏 }; static uint8_t TDisplay = 1; // CRC 高位字节值表 const unsigned char auchCRCHi[] = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 } ; // CRC 低位字节值表 const unsigned char auchCRCLo[] = { 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 }; static void MenuDisplay_entry(void *parameter) { extern IWDG_HandleTypeDef hiwdg; while(1) { if (MenuItem<11) for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量 WeightConst_Weight_display[SendDisplay_i]=0x20; if (MenuItem==0) { if (XbeeConst_DeviceAddress>9) { WeightConst_Weight_display[6] = (XbeeConst_DeviceAddress/10)%10 + 0x30; WeightConst_Weight_display[5] = XbeeConst_DeviceAddress%10 + 0x30; } else WeightConst_Weight_display[6] = XbeeConst_DeviceAddress + 0x30; } else if (MenuItem==1) { for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题 WeightConst_Weight_display[SendDisplay_i] = MenuTQTypeList[WeightConst_TQ][7-SendDisplay_i]; } else if (MenuItem==2) { if (XbeeConst_NetAddress>99) WeightConst_Weight_display[7] = XbeeConst_NetAddress/100 + 0x30; if (XbeeConst_NetAddress>9) WeightConst_Weight_display[6] = (XbeeConst_NetAddress/10)%10 + 0x30; WeightConst_Weight_display[5] = XbeeConst_NetAddress%10 + 0x30; } else if (MenuItem==3) { for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题 WeightConst_Weight_display[SendDisplay_i] = MenuSBTypeList[WeightConst_SBType][7-SendDisplay_i]; } else if (MenuItem==4) { if (WeightConst_ChanCheShu>9) { WeightConst_Weight_display[6] = (WeightConst_ChanCheShu/10)%10 + 0x30; WeightConst_Weight_display[5] = WeightConst_ChanCheShu%10 + 0x30; } else WeightConst_Weight_display[6] = WeightConst_ChanCheShu + 0x30; } else if (MenuItem==5) { WeightConst_Weight_display[6] = XbeeConst_UseAPI + 0x30; } else if (MenuItem==6) { TDisplay++; WeightConst_Weight_display[4] = (WeightConst_JZZ_==4 && TDisplay%2? 0x20:(WeightConst_JZZ>9999 ? (WeightConst_JZZ/10000)%10 : 0x00) + 0x30); WeightConst_Weight_display[3] = (WeightConst_JZZ_==3 && TDisplay%2? 0x20:(WeightConst_JZZ>999 ? (WeightConst_JZZ/1000)%10 : 0x00) + 0x30); WeightConst_Weight_display[2] = (WeightConst_JZZ_==2 && TDisplay%2? 0x20:(WeightConst_JZZ>99 ? (WeightConst_JZZ/100)%10 : 0x00) + 0x30); WeightConst_Weight_display[1] = (WeightConst_JZZ_==1 && TDisplay%2? 0x20:(WeightConst_JZZ>9 ? (WeightConst_JZZ/10)%10 : 0x00) + 0x30); WeightConst_Weight_display[0] = (WeightConst_JZZ_==0 && TDisplay%2? 0x20:(WeightConst_JZZ%10 + 0x30)); } else if (MenuItem==7) { TDisplay++; WeightConst_Weight_display[4] = (WeightConst_ZD_==4 && TDisplay%2? 0x20:(Maxval>9999 ? (Maxval/10000)%10 : 0x00) + 0x30); WeightConst_Weight_display[3] = (WeightConst_ZD_==3 && TDisplay%2? 0x20:(Maxval>999 ? (Maxval/1000)%10 : 0x00) + 0x30); WeightConst_Weight_display[2] = (WeightConst_ZD_==2 && TDisplay%2? 0x20:(Maxval>99 ? (Maxval/100)%10 : 0x00) + 0x30); WeightConst_Weight_display[1] = (WeightConst_ZD_==1 && TDisplay%2? 0x20:(Maxval>9 ? (Maxval/10)%10 : 0x00) + 0x30); WeightConst_Weight_display[0] = (WeightConst_ZD_==0 && TDisplay%2? 0x20:(Maxval%10 + 0x30)); } else if (MenuItem==8) { WeightConst_Weight_display[6] = ad_FS + 0x30; } else if (MenuItem==9) { WeightConst_Weight_display[6] = ad_Point + 0x30; } else if (MenuItem==10) { WeightConst_Weight_display[6] = ad_Inteval + 0x30; } else if (MenuItem==11) { WeightConst_Weight_display[6] = WeightConst_BLE + 0x30; } if (WeightConst_SBType<3 || WeightConst_SBType==6) { uart4_send_data[0] = 0x7E; uart4_send_data[1] = 0x45; for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题 uart4_send_data[2 + SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i]; for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示重量 uart4_send_data[10 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i]; // USART_Send_DMA(displaySerial,18); uart4_send_data[18]=0; for (int i = 2; i <18; i++) //校验和 uart4_send_data[18]=uart4_send_data[18]+uart4_send_data[i]; rt_sem_take(uart4_lock, RT_WAITING_FOREVER); HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19); rt_sem_release(uart4_lock); } else if (WeightConst_SBType==3||WeightConst_SBType==7) { for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示菜单标题 { WeightConst_feed[ SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i]; } for (int SendDisplay_i = 7; SendDisplay_i >=0; SendDisplay_i--) //显示当前值 { WeightConst_feed[8 + SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i]; } //---------------------------- get_msg(0,//Xstart 12,//Ystart 1,//size 0,//reset 0,//speed 8,//字符个数 3,//界面数 0,//id 0xbF,//Xend 0, &WeightConst_feed[0]//字码 ); get_msg(0,//Xstart 12,//Ystart 2,//size 0,//reset 0,//speed 8,//字符个数 3,//界面数 1,//id 0xbF,//Xend 0, &WeightConst_feed[8]//字码 ); } else { for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示标题 WeightConst_feed[SendDisplay_i] = MenuItemList[MenuItem][SendDisplay_i]; //---------------------------- //display_menu(); if(isn==0) { clearScreenAll(); display_Current_noweight(); display_Now(); for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j]; send_uart4_send_data(); } else { display_Current_noweight_(); display_Now_(WeightConst_WeightCurTem); } } // HAL_IWDG_Refresh(&hiwdg); rt_thread_mdelay(400); } } static rt_thread_t display_tid = RT_NULL; void threadMenuDisplay_init(void) { //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO); display_tid = rt_thread_create("MenuDisp", MenuDisplay_entry, RT_NULL, 0x200, 4, 5); /* 如果获得线程控制块,启动这个线程 */ if (display_tid != RT_NULL) rt_thread_startup(display_tid); } void getDisplay(void) { rt_uint8_t nullindex; rt_sem_take(display_lock, RT_WAITING_FOREVER); if (tsdb_recordcount('k')>0 || XbeeConst_CanSend==0) TDisplay++; //是否有按键需要传输 else TDisplay = 1; rt_memset(WeightConst_Feed_display, 0x20, 40); if(WeightConst_DELAYON>0) { WeightConst_Feed_display[0]=0xC7; WeightConst_Feed_display[1]=0xEB; WeightConst_Feed_display[2]=0xBD; WeightConst_Feed_display[3]=0xC1; WeightConst_Feed_display[4]=0xB0; WeightConst_Feed_display[5]=0xE8; WeightConst_Feed_display[6]=0x20; WeightConst_Feed_display[7]=0x20; } else if (!isWeight){ nullindex = 0; for (int i = 0; i < 40; i++) //显示标题 { WeightConst_Feed_display[i] = WeightConst_feed[i]; if (i>0 && nullindex==0 && WeightConst_feed[i]==0x20 && WeightConst_feed[i-1]==0x20 && WeightConst_feed[i-2]==0x20) { nullindex = i-2; } if ((nullindex>8 && nullindex<14)||(nullindex<7 && nullindex>0)) nullindex=nullindex+2; if (nullindex>1){ if(TDisplay%2==0) { WeightConst_Feed_display[nullindex-1]=0x3E; WeightConst_Feed_display[nullindex-2]=0x3E; } else { WeightConst_Feed_display[nullindex-1]=WeightConst_feed[nullindex-1]; WeightConst_Feed_display[nullindex-2]=WeightConst_feed[nullindex-2]; } } } } if(WeightConst_DELAYON>0) { WeightConst_Weight_display[0]=0xEB; WeightConst_Weight_display[1]=0xC3; WeightConst_Weight_display[2]=0x20; WeightConst_Weight_display[3]=0x20; WeightConst_Weight_display[4]=0x20; WeightConst_Weight_display[5]=0x20; WeightConst_Weight_display[6]=0x20; WeightConst_Weight_display[7]=0x20; WeightConst_Weight_displayW = (pf_comp.data.delaytime * 60 - WeightConst_DELAYTIME); for (int SendDisplay_i = 2; SendDisplay_i < 8; SendDisplay_i++) { if (SendDisplay_i>2) WeightConst_Weight_displayW=WeightConst_Weight_displayW/10; if (abs(WeightConst_Weight_displayW)>0) WeightConst_Weight_display[SendDisplay_i] = abs((WeightConst_Weight_displayW)%10)+'0'; else break; } } else { if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1) WeightConst_Weight_displayW = WeightConst_WeightCurTem - WeightConst_WeightTarget; else WeightConst_Weight_displayW = WeightConst_WeightCurTem; WeightConst_Weight_displayCurW = WeightConst_WeightCurTem; for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //显示重量 WeightConst_Weight_display[SendDisplay_i]=0x20; if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1) { if ((WeightConst_Weight_displayW<=0 && pf_comp.data.addorout==0) || (WeightConst_Weight_displayW>=0 && pf_comp.data.addorout == 1) ) { //少 WeightConst_Weight_display[6]=0xD9; WeightConst_Weight_display[7]=0xC9; } else { WeightConst_Weight_display[6]=0xE0; //多 WeightConst_Weight_display[7]=0xB6; } } else { if (WeightConst_Weight_displayW<0) { WeightConst_Weight_display[6]=0x2D; //- WeightConst_Weight_display[7]=0x20; } else { WeightConst_Weight_display[6]=0x20; // WeightConst_Weight_display[7]=0x20; } } if (WeightConst_Weight_displayW==0) { WeightConst_Weight_display[0]=0x30; } else { for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) { if (SendDisplay_i>0) WeightConst_Weight_displayW=WeightConst_Weight_displayW/10; if (abs(WeightConst_Weight_displayW)>0) WeightConst_Weight_display[SendDisplay_i] = abs(WeightConst_Weight_displayW%10)+'0'; else break; } if (WeightConst_WeightWS>0) { for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--) if (WeightConst_Weight_display[SendDisplay_i]!=0x20) WeightConst_Weight_display[SendDisplay_i+1]=WeightConst_Weight_display[SendDisplay_i]; WeightConst_Weight_display[WeightConst_WeightWS]=0x2E; if (WeightConst_Weight_display[WeightConst_WeightWS+1]==0x20) WeightConst_Weight_display[WeightConst_WeightWS+1] = 0x30; for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++) if (WeightConst_Weight_display[SendDisplay_i]==0x20) WeightConst_Weight_display[SendDisplay_i] = 0x30; } } /////////////////广泽 if (remote_sumweight==1) { for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) { WeightConst_WeightCur_display[SendDisplay_i] = 0x20; }; if (WeightConst_Weight_displayCurW==0){ WeightConst_WeightCur_display[0] = 0x30; } else { if (WeightConst_Weight_displayCurW<0) { WeightConst_WeightCur_display[4]=0x2D; //- } for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) { if (SendDisplay_i>0) WeightConst_Weight_displayCurW=WeightConst_Weight_displayCurW/10; if (abs(WeightConst_Weight_displayCurW)>0) WeightConst_WeightCur_display[SendDisplay_i] = abs(WeightConst_Weight_displayCurW%10)+'0'; else break; } if (WeightConst_WeightWS>0) { for (int SendDisplay_i = 4; SendDisplay_i >= WeightConst_WeightWS; SendDisplay_i--) if (WeightConst_WeightCur_display[SendDisplay_i]!=0x20) WeightConst_WeightCur_display[SendDisplay_i+1]=WeightConst_WeightCur_display[SendDisplay_i]; WeightConst_WeightCur_display[WeightConst_WeightWS]=0x2E; if (WeightConst_WeightCur_display[WeightConst_WeightWS+1]==0x20) WeightConst_WeightCur_display[WeightConst_WeightWS+1] = 0x30; for (int SendDisplay_i = 0; SendDisplay_i < WeightConst_WeightWS; SendDisplay_i++) if (WeightConst_WeightCur_display[SendDisplay_i]==0x20) WeightConst_WeightCur_display[SendDisplay_i] = 0x30; } } } /////////////////广泽 end if (WeightConst_WeightHaveBegin==0 && pf_comp.data.needBegin == 1) { if (WeightConst_SBType==1||WeightConst_SBType==6) { //for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) //如果没有开始则空显示重量 // WeightConst_Weight_display[SendDisplay_i]=0x20; WeightConst_Weight_display[5]=WeightConst_Weight_display[6]; WeightConst_Weight_display[6]=0xF8; WeightConst_Weight_display[7]=0xCB; } else if (WeightConst_SBType==3) { WeightConst_Weight_display[5]=WeightConst_Weight_display[6]; WeightConst_Weight_display[6]=0xF8; WeightConst_Weight_display[7]=0xCB; /* WeightConst_Weight_display[0]=0xCC; WeightConst_Weight_display[1]=0xC5; WeightConst_Weight_display[2]=0xD3; WeightConst_Weight_display[3]=0xB3; WeightConst_Weight_display[4]=0xD5; WeightConst_Weight_display[5]=0xBF; WeightConst_Weight_display[6]=0xE5; WeightConst_Weight_display[7]=0xC7;//清空秤盘 */ } else if (WeightConst_SBType==4||WeightConst_SBType==6) { WeightConst_Weight_display[0]=0xBC; WeightConst_Weight_display[1]=0xCA; WeightConst_Weight_display[2]=0xAA; WeightConst_Weight_display[3]=0xBF; WeightConst_Weight_display[4]=0xCF; WeightConst_Weight_display[5]=0xC8; WeightConst_Weight_display[6]=0xB7; WeightConst_Weight_display[7]=0xC8;//确认开始 }; }; } rt_sem_release(display_lock); } static void sendRemote(void *parameter) { rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0; while(1) { if (RemoteSendDisplay == 1 ) { if ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI>=3))|| (flag_uart3_send==0 && XbeeConst_UseAPI==0)) { if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[0] = 28; else XbeeConst_FRemoteTxBuf[0] = 23; XbeeConst_FRemoteTxBuf[1] = 0x7E; XbeeConst_FRemoteTxBuf[2] = 0x15; if(remote_sumweight==1) XbeeConst_FRemoteTxBuf[2] = 0x1A; else XbeeConst_FRemoteTxBuf[2] = 0x15; XbeeConst_FRemoteTxBuf[3] = XbeeConst_DeviceAddress; if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3) XbeeConst_FRemoteTxBuf[4] = 0xA1; else { if (WeightConst_ChanCheShu>9) XbeeConst_FRemoteTxBuf[4] = 0xA1; else XbeeConst_FRemoteTxBuf[4] = 0xF1; } XbeeConst_FRemoteTxBuf[5] = 0x7E; XbeeConst_FRemoteTxBuf[6] = 0x45; haveAscii=0; for(rt_uint8_t i=0; i<8; i++){ if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); } } ismulti = 0; for(rt_uint8_t i=8;i<16;i++){ if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; } } if (ismulti==0) displayrow = 0; if (forcount<1) forcount++; else{ forcount = 0; if (ismulti==1 && displayrow==1) displayrow = 0; else if (ismulti==1 && displayrow==0) displayrow = 1; } for (rt_uint8_t i = 0; i < 8; i++) //显示标题 { if (haveAscii==1 && displayrow==1) XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i+displayrow*8-1];//显示标题 else if (haveAscii==1 && displayrow==0){ if (i==7) XbeeConst_FRemoteTxBuf[7+i] = 0x20; else XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8]; } else XbeeConst_FRemoteTxBuf[7+i] = WeightConst_Feed_display[i + displayrow * 8]; }; for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) { XbeeConst_FRemoteTxBuf[15+SendDisplay_i] = WeightConst_Weight_display[7-SendDisplay_i];//显示重量 } ////////////广泽 if(remote_sumweight==1){ for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) { XbeeConst_FRemoteTxBuf[23+SendDisplay_i] = WeightConst_WeightCur_display[4-SendDisplay_i];//显示重量 } } ////////////广泽 XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0x00; for (int SendDisplay_i = 1; SendDisplay_i < XbeeConst_FRemoteTxBuf[0]; SendDisplay_i++) { XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]+XbeeConst_FRemoteTxBuf[SendDisplay_i]; } XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]] = 0xFF - XbeeConst_FRemoteTxBuf[XbeeConst_FRemoteTxBuf[0]]; if (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3) { rt_sem_take(uart2_lock, RT_WAITING_FOREVER); if (XbeeConst_UseAPI==1) setSendFrame_t(0x01,0x02,0x40); else setSendFrame_t(0x02,0x02,0x40); XbeeConst_PRemoteTxBuf0 = xBeeApp2MakeFrame(&userSendFrame_t, XbeeConst_FRemoteTxBuf); for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出 usart2_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i]; if (XbeeConst_UseAPI==1 || (XbeeConst_UseAPI==3 && ccsend==1)) { HAL_UART_Transmit_DMA(&huart2, usart2_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial rt_thread_mdelay(50); } rt_sem_release(uart2_lock); rt_thread_mdelay(XbeeConst_DeviceAddress*30); // rt_thread_mdelay(200); } else if (XbeeConst_UseAPI>3) { rt_sem_take(uart3_lock, RT_WAITING_FOREVER); AT_on(); for(int xcount=0;xcount<2;xcount++){ XbeeConst_PRemoteTxBuf0 = BleApp2MakeFrame(0xFFFF, 0x00, xcount, XbeeConst_FRemoteTxBuf); for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_PRemoteTxBuf0[0]; SendWifi_i++) //将缓冲区发出 usart3_send_data[SendWifi_i-1] = XbeeConst_PRemoteTxBuf0[SendWifi_i]; HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_PRemoteTxBuf0[0]);//xbeeSerial rt_thread_mdelay(100); } AT_off(); rt_sem_release(uart3_lock); } else { if (iscowweight<1 ) { rt_sem_take(uart3_lock, RT_WAITING_FOREVER); for (int SendWifi_i = 1; SendWifi_i <= XbeeConst_FRemoteTxBuf[0]; SendWifi_i++) //将缓冲区发出 usart3_send_data[SendWifi_i-1] = XbeeConst_FRemoteTxBuf[SendWifi_i]; HAL_UART_Transmit_DMA(&huart3, usart3_send_data, XbeeConst_FRemoteTxBuf[0]); //remoteSerial rt_thread_mdelay(50); rt_sem_release(uart3_lock); } } } } if (XbeeConst_UseAPI<4) rt_thread_mdelay(500); else rt_thread_mdelay(250); } } void ChancheShow(void) { uart4_send_data[0] = 0x7E; uart4_send_data[1] = 0x45; uart4_send_data[2] = XbeeConst_RemoteAddress + '0'; for (int i = 3; i < 18; i++) //将缓冲区发出 uart4_send_data[i] = 0x20; rt_sem_take(uart4_lock, RT_WAITING_FOREVER); HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 12); rt_sem_release(uart4_lock); } void send_uart4_send_data(void) { rt_sem_take(uart4_lock, RT_WAITING_FOREVER); HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39); rt_sem_release(uart4_lock); rt_thread_mdelay(100); // rt_sem_take(uart4_lock, RT_WAITING_FOREVER); // HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 39); // rt_sem_release(uart4_lock); // rt_thread_mdelay(100); } extern unsigned char inMenu; static void Display_entry(void *parameter) { rt_uint32_t e; rt_uint8_t displayrow = 0,ismulti = 0,forcount = 0,haveAscii=0,row=0,rowx=5; extern IWDG_HandleTypeDef hiwdg; while (1) { getDisplay(); ismulti = 0; haveAscii=0; for(rt_uint8_t i=0;i<8;i++){ if ( WeightConst_Feed_display[i] < 0x80) { haveAscii = ((haveAscii + 1) & 0x01); } } for(rt_uint8_t i=8;i<16;i++){ if ( WeightConst_Feed_display[i] > 0x20) { ismulti=1; break; } } if (ismulti==0) displayrow = 0; if (forcount<2) forcount++; else{ forcount = 0; if (ismulti==1 && displayrow==1) displayrow = 0; else if (ismulti==1 && displayrow==0) displayrow = 1; } if (WeightConst_SBType<3||WeightConst_SBType==6) { uart4_send_data[0] = 0x7E; uart4_send_data[1] = 0x45; for (int i = 0; i < 8; i++) //显示标题 { if (haveAscii==1 && displayrow==1) uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8 - 1]; else if (haveAscii==1 && displayrow==0){ if (i==7) uart4_send_data[i+2] = 0x20; else uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8]; } else uart4_send_data[i+2] = WeightConst_Feed_display[i + displayrow * 8]; }; for (int i = 7; i >=0; i--) //显示重量 uart4_send_data[i + 10] = WeightConst_Weight_display[7-i]; uart4_send_data[18]=0; for (int i = 2; i <18; i++) //校验和 uart4_send_data[18] = uart4_send_data[18] + uart4_send_data[i]; rt_sem_take(uart4_lock, RT_WAITING_FOREVER); HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 19); rt_sem_release(uart4_lock); // HAL_IWDG_Refresh(&hiwdg); rt_thread_mdelay(500); } else if (WeightConst_SBType==4) { if (rt_event_recv(&display_event, (EVENT_clearall | EVENT_Current_noweight | EVENT_PlanName | EVENT_Current | EVENT_Stop | EVENT_Next) , RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 10, &e) == RT_EOK) { if (e & EVENT_clearall) { if(isn>=1 ) { clearScreenAll_(); } else { clearScreenAll(); } } if (e & EVENT_Current_noweight) { if(isn>=1 ) { display_Current_noweight_(); } else { display_Current_noweight();; } } if (e & EVENT_PlanName) { if(isn>=1 ) { display_productName_(0); } else { display_productName(); } } if (e & EVENT_Current) { if(isn>=1 ) { display_Current_(WeightConst_WeightTargetTemp); } else { display_Current(WeightConst_WeightTargetTemp); } } if (e & EVENT_Stop) { if(isn>=1 ) { ; } else { ; } } if (e & EVENT_Next) { if(isn>=1) { display_Next_(); } else { display_Next(); } } } // if(WeightConst_Run || inMenu==1) { if (isn>=1) { display_Now_(WeightConst_WeightCurTem); } else{ display_Now(); display_Total(WeightConst_WeightCurTem); row++; if (row%rowx==0){ for (int j=0; j<39; j++) uart4_send_data[j] = display_productName_v[j]; send_uart4_send_data(); } for (int j=0; j<39; j++) uart4_send_data[j] = display_Current_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Process_v[j]; send_uart4_send_data(); for (int j=0; j<39; j++) uart4_send_data[j] = display_Total_v[j]; send_uart4_send_data(); if (row%rowx==0){ for (int j=0; j<39; j++) uart4_send_data[j] = display_Next_v[j]; send_uart4_send_data(); } if (row%rowx==0){ for (int j=0; j<39; j++) uart4_send_data[j] = display_Stop_v[j]; send_uart4_send_data(); } } } if (isn>=1){ rt_thread_mdelay(500); } else{ rt_thread_mdelay(300); } // HAL_IWDG_Refresh(&hiwdg); } else if (WeightConst_SBType==3){// || WeightConst_SBType==7) { // if (WeightConst_Weight_display_old[SendDisplay_i] != WeightConst_Weight_display[SendDisplay_i]) { get_msg(0,//Xstart 0,//Ystart 1,//size 0,//reset 0,//speed 16,//字符个数 3,//界面数 0,//id 0xBF,//Xend 0, &WeightConst_feed[0]//字码 ); get_msg(92,//Xstart 4,//Ystart 2,//size 0,//reset 0,//speed 8,//字符个数 3,//界面数 1,//id 0xBF,//Xend 1, &WeightConst_Weight_display[0]//字码 ); if(WeightConst_Product_Run) { rt_uint8_t index = 0,value = 0; signed long WeightConst_WeightCurTem_ = 0; uart4_send_data[0]=0x20;uart4_send_data[1]=0x20;uart4_send_data[2]=0x20; uart4_send_data[3]=0x20;uart4_send_data[4]=0x30; if (WeightConst_WeightCurTem<0) { WeightConst_WeightCurTem_ = WeightConst_WeightCurTem*-1; uart4_send_data[0] = 0x2D; } else WeightConst_WeightCurTem_ = WeightConst_WeightCurTem; for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) { if (SendDisplay_i>0) WeightConst_WeightCurTem_=WeightConst_WeightCurTem_/10; if (WeightConst_WeightCurTem_>0) uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCurTem_)%10+'0'; else break; } get_msg(0,//Xstart 0,//Ystart 1,//size 0,//reset 0,//speed 5,//字符个数 3,//界面数 4,//id 0xBF,//Xend 0, &uart4_send_data[0]//字码 ); index = 0; for(int i = 0;i< 22;i++) { if(WeightConst_product[i] >= 0xA0) { uart4_send_data[index++] = WeightConst_product[i++]; uart4_send_data[index++] = WeightConst_product[i]; // uart4_send_data[index++] = 0xA1; // uart4_send_data[index++] = 0xA2; } else { if(WeightConst_product[i] != 0x20 && WeightConst_product[i] != 0) { uart4_send_data[index++] = WeightConst_product[i]; // uart4_send_data[index++] = 0xA1; // uart4_send_data[index++] = 0xA2; } } } uart4_send_data[index++] = 0x10; // // value = (plan_comp.data .sumweight / 10000) % 10; // if(value != 0) { // uart4_send_data[index++] = value + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 1000) % 10 + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30; // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30; // } // else { // value = (plan_comp.data .sumweight / 1000) % 10; // if(value != 0) { // uart4_send_data[index++] = value + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 100) % 10 + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30; // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30; // } // else { // value = (plan_comp.data .sumweight / 100) % 10; // if(value != 0) { // uart4_send_data[index++] = value + 0x30; // uart4_send_data[index++] = (plan_comp.data .sumweight / 10) % 10 + 0x30; // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30; // } // else { // value = (plan_comp.data .sumweight / 10) % 10; // if(value != 0) { // uart4_send_data[index++] = value + 0x30; // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30; // } // else { // uart4_send_data[index++] = plan_comp.data .sumweight % 10 + 0x30; // } // } // } // } uart4_send_data[index++] = 0x10; WeightConst_WeightCurTem_ = WeightConst_WeightTargetTemp; value = (WeightConst_WeightCurTem_ / 10000) % 10; if(value != 0) { uart4_send_data[index++] = value + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 1000) % 10 + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30; uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30; } else { value = (WeightConst_WeightCurTem_ / 1000) % 10; if(value != 0) { uart4_send_data[index++] = value + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30; uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30; } else { value = (WeightConst_WeightCurTem_ / 100) % 10; if(value != 0) { uart4_send_data[index++] = value + 0x30; uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30; uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30; } else { value = (WeightConst_WeightCurTem_ / 10) % 10; if(value != 0) { uart4_send_data[index++] = value + 0x30; uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30; } else { uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30; } } } } uart4_send_data[index++] = 0x10; for(int i = 0;i< 16;i++) { uart4_send_data[index++] = WeightConst_Nextfeed[i]; if (WeightConst_Nextfeed[i] ==0x20) break; } uart4_send_data[index++] = 0x10; if (pf_comp.data.isMix==1){ uart4_send_data[index++] = 0xD7; uart4_send_data[index++] = 0xE9; uart4_send_data[index++] = 0xBA; uart4_send_data[index++] = 0xCF; uart4_send_data[index++] = 0xC1; uart4_send_data[index++] = 0xCF; } uart4_send_data[index++] = 0x10; get_msg(0,//Xstart 0,//Ystart 1,//size 0,//reset 3,//speed index,//字符个数 3,//界面数 2,//id 0xBF,//Xend 0, &uart4_send_data[0]//字码 ); if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0 && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1) { int tempw; uart4_send_data[1]=0; uart4_send_data[2]=0; uart4_send_data[3]=0; if ((WeightConst_WeightTarget < WeightConst_WeightCurTem && pf_comp.data.addorout==0) || (WeightConst_WeightTarget > WeightConst_WeightCurTem && pf_comp.data.addorout==1)) { uart4_send_data[0]= 100; uart4_send_data[1]=0xFF; } else { if (WeightConst_WeightCurTem<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) && pf_comp.data.addorout==0) tempw=0; else if (WeightConst_WeightCurTem>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) && pf_comp.data.addorout==1) tempw=0; else if (pf_comp.data.addorout==0) tempw = ( WeightConst_WeightCurTem-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp)); else tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCurTem); uart4_send_data[0]=tempw*100/WeightConst_WeightTargetTemp; if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) || (WeightConst_WeightCurTemWeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)|| (WeightConst_WeightCurTem-30700 && RemoteSendDisplay && // ((flag_uart2_send==0 && (XbeeConst_UseAPI==1 || XbeeConst_UseAPI==3))|| // (flag_uart3_send==0 && XbeeConst_UseAPI==0))) // { // SendRemote_timer = 0; // } } } static void Display_clear_entry(void *parameter) { uint8_t i=0; while (i<10) { // while (WeightConst_Run<1) { if (WeightConst_Run<1){ if (isn>=1) display_KPT_TMRWatch_(); // if (isn>=1) display_KPT_TMRWatch_weight_(); else display_KPT_TMRWatch(); } rt_thread_mdelay(1000); i++; } } void threadDisplay_init(void) { if (WeightConst_SBType == 4) { if(isn>=1) clearScreenAll_(); else clearScreenAll(); } //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO); display_tid = rt_thread_create("Display", Display_entry, RT_NULL, 0x400, 5, 5); /* 如果获得线程控制块,启动这个线程 */ if (display_tid != RT_NULL) rt_thread_startup(display_tid); } static rt_thread_t display_clear_tid = RT_NULL; void threadDisplay_delay_init(void) { display_clear_tid = rt_thread_create("Displaydelay", Display_clear_entry, RT_NULL, 0x100, 5, 5); /* 如果获得线程控制块,启动这个线程 */ if (display_clear_tid != RT_NULL) rt_thread_startup(display_clear_tid); } static rt_thread_t remotedisplay_tid = RT_NULL; void threadRemoteDisplay_init(void) { //thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO); remotedisplay_tid = rt_thread_create("RemoteD", sendRemote, RT_NULL, 0x300, 5, 5); /* 如果获得线程控制块,启动这个线程 */ if (remotedisplay_tid != RT_NULL) rt_thread_startup(remotedisplay_tid); } void display_usart_Init(UART_HandleTypeDef* uartHandle) { extern unsigned char WeightConst_TQ; if ((uartHandle->Instance==UART4 && (WeightConst_SBType==0x04 && isn==0))) { uartHandle->Init.BaudRate = 9600; } else uartHandle->Init.BaudRate = 57600; } //CRC校验的函数 unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen) { unsigned char uchCRCHi = 0xFF ; unsigned char uchCRCLo = 0xFF ; unsigned uIndex ; while (usDataLen--) { uIndex = uchCRCHi ^ *puchMsg++ ; /* 计算CRC */ uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ; uchCRCLo = auchCRCLo[uIndex] ; } return (uchCRCHi << 8 | uchCRCLo) ; } unsigned char uart_send_buf_cp[100]; unsigned char get_msg( unsigned char Xstart,// 0 - 191 unsigned char Ystart, //0 - 47 unsigned char ZiTiSize,//1 or 2 or 3 unsigned char reset_enable,//0 or 1 unsigned char speed,//速度 0 or 1 or 2 or 3 unsigned char ZiFuCount,//字符个数 unsigned char JieMianCount,//3 unsigned char JieMianID,//0 or 1 or 2 unsigned char Xend, unsigned char f, unsigned char * ASCII_buf) { unsigned char i=0; unsigned char len=0; unsigned short int calcCRC; extern IWDG_HandleTypeDef hiwdg; uart_send_buf_cp[0] = 0x7E; uart_send_buf_cp[1] = Xstart; uart_send_buf_cp[2] = (Ystart<<2) |(ZiTiSize & 0x03); // uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|((speed<<5)&0x60); uart_send_buf_cp[3] = ((reset_enable<<7)&0x80)|(speed & 0x0F); uart_send_buf_cp[4] = ZiFuCount; uart_send_buf_cp[5] = ((JieMianCount<<4)&0xF0)|(JieMianID&0x0F); uart_send_buf_cp[6] = Xend; if (f==0) for(i=0; i0; i--) uart_send_buf_cp[7+i-1] = ASCII_buf[ZiFuCount-i]; len = ZiFuCount + 7; calcCRC = CRC16(uart_send_buf_cp, len); uart_send_buf_cp[7+ZiFuCount] = (unsigned char)(calcCRC>>8); //低位 uart_send_buf_cp[7+ZiFuCount+1] = (unsigned char)(calcCRC); //高位 for(i=0; i<=8+ZiFuCount; i++) uart4_send_data[i] = uart_send_buf_cp[i]; rt_sem_take(uart4_lock, RT_WAITING_FOREVER); HAL_UART_Transmit_DMA(&huart4, uart4_send_data, 9+ZiFuCount); rt_sem_release(uart4_lock); rt_thread_mdelay(150); return 0; }