📄 main.c
字号:
#include "externh.h"
GOB g;
tagFormat Format;
U8 uc[5];
U16 us[2];
unsigned char TxBuf[]={0x55,0xAA,0x00,0x00,0x01,0x01};
unsigned char RxBuf[30];
U8 LCDBuf0[17];
U8 LCDBuf1[17];
U8 test0[] PROGMEM={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,\
0x0c,0x02,0x4e,0x98,0x00,0x00,0x44,0x00,0x03,0x00,0x9f};
U8 P00_0[] PROGMEM="000.0Hz 000V M00";
U8 P00_1[] PROGMEM=" 000W 00.0A 00C";
U8 P01_16_0[] PROGMEM="P00:Frequency 00";
U8 P01_16_1[] PROGMEM=" 000000.00Hz ";
U8 P17_32_0[] PROGMEM="P00:Rev time 00";
U8 P17_32_1[] PROGMEM=" 000000.00ms ";
U8 P33_48_0[] PROGMEM="P00 Inc Speed 00";
U8 P33_48_1[] PROGMEM=" 000000.00ms/Hz ";
U8 P49_64_0[] PROGMEM="P00 Dec Speed 00";
U8 P49_64_1[] PROGMEM=" 000000.00ms/Hz ";
U8 P65_75_0[][16] PROGMEM={\
"P65:Start Speed ",\
"P66:Stop Speed ",\
"P67:Brake Time ",\
"P68:Brake Level ",\
"P69:Brake Frequ ",\
"P70:Level Inc ",\
"P71:Base Level ",\
"P72:Base Freq. ",\
"P73:Start Freq ",\
"P74:Max Freq. ",\
"P75:Min Freq. ",\
};
U8 P65_75_1[] PROGMEM=" 000000.00ms/Hz";
void RxProcess(void);
void Div(unsigned long Div0,unsigned int radix,unsigned char w1,unsigned char Wei,unsigned char *ptr);
void BigToLittle(U16 *ptr)
{
union{
unsigned int us;
unsigned char uc[2];
}un;
unsigned char ch;
un.us=*ptr;
ch=un.uc[0];
un.uc[0]=un.uc[1];
un.uc[1]=ch;
*ptr=un.us;
}
void main(void)
{
for(uc[0]=0;uc[0]<24;uc[0]++){
RxBuf[uc[0]]=pgm_read_byte(test0+uc[0]);
}
Rs232.Flag.Full=1;
SystemInit();
// wdt_enable(WDTO_4S);
while(1){
wdt_reset();
if(g.Flag.T0){
g.Flag.T0=0;
KeyScan();
}
if(!Time60S){
Time60S=500;
for(uc[0]=0;uc[0]<6;uc[0]++){
PutCh(TxBuf[uc[0]]);
}
TxBuf[2]=0;
TxBuf[4]=1;
TxBuf[5]=1;
}
if(Rs232.Flag.Full){
RxProcess();
Rs232.Flag.Full=0;
}
GetKey();
if(!Key.hzS) continue;
Pout_LED_KEY=1;
Delay(10);
Pout_LED_KEY=0;
Time60S=0;
TxBuf[2]=0x01;
if(K1==Key.hzS){
TxBuf[4]=0x20;
TxBuf[5]=0x21;
continue;
}
if(K2==Key.hzS){
TxBuf[4]=0x04;
TxBuf[5]=0x05;
continue;
}
if(K3==Key.hzS){
TxBuf[4]=0x01;
TxBuf[5]=0x02;
continue;
}
if(K4==Key.hzS){
TxBuf[4]=0x10;
TxBuf[5]=0x11;
continue;
}
if(K5==Key.hzS){
TxBuf[4]=0x08;
TxBuf[5]=0x09;
continue;
}
if(K6==Key.hzS){
TxBuf[4]=0x02;
TxBuf[5]=0x03;
continue;
}
if(K7==Key.hzS){
TxBuf[4]=0x40;
TxBuf[5]=0x41;
continue;
}
}
}
void RxProcess(void)
{
uc[1]=0;
for(uc[0]=0;uc[0]<23;uc[0]++){
uc[1] +=RxBuf[uc[0]];
}
if(uc[1]!=RxBuf[23]){
Pout_LED_ERR=1;
return;
}
memcpy(&Format,&RxBuf,sizeof(tagFormat));
BigToLittle(&Format.Freq[0]);
BigToLittle(&Format.Freq[1]);
BigToLittle(&Format.Voltage);
BigToLittle(&Format.Parameter);
Pout_LED_ERR=0;
Pout_LED_RUN=0;
Pout_LED_FWD=0;
Pout_LED_REV=0;
Pout_LED_PAUSE=0;
Pout_LED_KEY=0;
switch(Format.BiaoShi){
case 0:
case 1:
case 2:
case 8://FWD
case 9://REV
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P00_0+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P00_1+uc[0]);
}
Div(Format.Freq[0],10,3,1,&LCDBuf0[0]);
Div(Format.Voltage,1,3,0,&LCDBuf0[8]);
LCDBuf0[15]=Format.Mode+'0';
Pout_LED_RUN=1;
if(Format.BiaoShi<8){
Pout_LED_RUN=0;
}
if(0x08==Format.BiaoShi){
Pout_LED_FWD=1;
break;
}
if(0x09==Format.BiaoShi){
Pout_LED_REV=1;
break;
}
break;
case 3:
if(Format.No<16){
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P01_16_0+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P01_16_1+uc[0]);
}
Format.No++;
Div(Format.No,1,2,0,&LCDBuf0[1]);
Div(Format.No,1,2,0,&LCDBuf0[14]);
Div(Format.Parameter,10,6,2,&LCDBuf1[1]);
break;
}
if(Format.No<32){
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P17_32_0+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P17_32_1+uc[0]);
}
Format.No++;
Div(Format.No,1,2,0,&LCDBuf0[1]);
Format.No -=16;
Div(Format.No,1,2,0,&LCDBuf0[14]);
Div(Format.Parameter,4,6,2,&LCDBuf1[1]);
break;
}
if(Format.No<48){
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P33_48_0+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P33_48_1+uc[0]);
}
Format.No++;
Div(Format.No,1,2,0,&LCDBuf0[1]);
Format.No -=32;
Div(Format.No,1,2,0,&LCDBuf0[14]);
Div(Format.Parameter,4,6,2,&LCDBuf1[1]);
break;
}
if(Format.No<64){
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P49_64_0+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P49_64_1+uc[0]);
}
Format.No++;
Div(Format.No,1,2,0,&LCDBuf0[1]);
Format.No -=48;
Div(Format.No,1,2,0,&LCDBuf0[14]);
Div(Format.Parameter,4,6,2,&LCDBuf1[1]);
break;
}
for(uc[0]=0;uc[0]<16;uc[0]++){
LCDBuf0[uc[0]]=pgm_read_byte(P65_75_0[Format.No-64]+uc[0]);
LCDBuf1[uc[0]]=pgm_read_byte(P49_64_1+uc[0]);
}
Format.No++;
switch(Format.No){
case 65:
case 66:
case 67:
Div(Format.Parameter,4,6,2,&LCDBuf1[1]);
LCDBuf1[10]='m';
LCDBuf1[11]='s';
LCDBuf1[12]='/';
LCDBuf1[13]='H';
LCDBuf1[14]='z';
LCDBuf1[15]=0;
if(67==Format.No) LCDBuf1[12]=0;
break;
case 68:
case 70:
case 71:
Div(Format.Parameter,1,6,2,&LCDBuf1[1]);
LCDBuf1[10]=0;
break;
case 69:
case 72:
case 73:
case 74:
case 75:
Div(Format.Parameter,10,6,2,&LCDBuf1[1]);
LCDBuf1[10]='H';
LCDBuf1[11]='z';
LCDBuf1[12]=0;
break;
}
break;
}
LCDBuf0[16]=0;
LCDBuf1[16]=0;
// Cls();
string=LCDBuf0;
DispStr(0,0);
string=LCDBuf1;
DispStr(0,1);
}
void Div(unsigned long Div0,unsigned int radix,unsigned char W1,unsigned char Wei,unsigned char *ptr)
{//Div0-被除数。radix-除数。W1-整数位数,Wei-小数位数。*ptr-存放结果的地址。
unsigned int ut;
unsigned long us0;
unsigned char uc0;
us0=1;
while(W1-1){
us0*=10;
W1--;
}
ut=Div0/radix;
while(1){
if(us0<10) break;
*ptr++=ut/us0+'0';
ut %=us0;
us0 /=10;
}
*ptr++=ut/us0+'0';
if(!Wei) return;
*ptr++ ='.';
*ptr='0';
for(uc0=0;uc0<Wei;uc0++){
Div0=Div0%radix;
Div0*=10;
ut=Div0/radix;
*ptr++=ut+'0';
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -