![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
Command.c@116:66f1f0ff2dab, 2016-04-05 (annotated)
- Committer:
- Kovalev_D
- Date:
- Tue Apr 05 16:52:31 2016 +0000
- Revision:
- 116:66f1f0ff2dab
- Parent:
- 115:e5a230e5af52
- Child:
- 119:4d7fcece9e8e
111;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "stdlib.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "LPC17xx.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "Global.h" |
Kovalev_D | 106:250ddd8629c6 | 4 | int tempNH,tempNL; |
igor_v | 0:8ad47e2b6f00 | 5 | unsigned int Rate_Flag; |
igor_v | 0:8ad47e2b6f00 | 6 | unsigned int CountBuFFIn; |
igor_v | 21:bc8c1cec3da6 | 7 | unsigned int N=0,CRC_N; |
igor_v | 21:bc8c1cec3da6 | 8 | unsigned int Param1=0; |
igor_v | 21:bc8c1cec3da6 | 9 | unsigned int Param2=0; |
igor_v | 21:bc8c1cec3da6 | 10 | unsigned int Param3=0; |
igor_v | 21:bc8c1cec3da6 | 11 | unsigned int Param4=0; |
Kovalev_D | 102:4270092be987 | 12 | unsigned int Consol=123; |
igor_v | 0:8ad47e2b6f00 | 13 | /* |
igor_v | 21:bc8c1cec3da6 | 14 | void exec_CMD(void) //r. === процедура окончательной дешифрации и исполнения команды |
igor_v | 0:8ad47e2b6f00 | 15 | { |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int Comand_code; |
igor_v | 21:bc8c1cec3da6 | 17 | |
igor_v | 21:bc8c1cec3da6 | 18 | //rx_buf_copy = 1; //r. предустанов флага копирования приемного буфера |
igor_v | 0:8ad47e2b6f00 | 19 | |
igor_v | 0:8ad47e2b6f00 | 20 | Comand_code = (rcv_buf[2] & 0xFF) << 8; |
igor_v | 21:bc8c1cec3da6 | 21 | PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. сохранить его в памяти для обратной передачи |
igor_v | 0:8ad47e2b6f00 | 22 | }*/ |
igor_v | 0:8ad47e2b6f00 | 23 | void CMD_Maintenance(void) |
igor_v | 0:8ad47e2b6f00 | 24 | { |
igor_v | 30:17c84ed091b3 | 25 | BuffTemp[0] = Gyro.SOC_Out; |
igor_v | 30:17c84ed091b3 | 26 | BuffTemp[1] = Gyro .My_Addres; |
igor_v | 30:17c84ed091b3 | 27 | BuffTemp[2] = Gyro .Firmware_Version; |
igor_v | 30:17c84ed091b3 | 28 | BuffTemp[3] = Gyro .GLD_Serial; |
igor_v | 21:bc8c1cec3da6 | 29 | BuffTemp[4]=0x00; |
igor_v | 21:bc8c1cec3da6 | 30 | BuffTemp[5]=0x00; |
igor_v | 21:bc8c1cec3da6 | 31 | Check(BuffTemp, 8); |
igor_v | 21:bc8c1cec3da6 | 32 | WriteConN (BuffTemp,8); |
igor_v | 0:8ad47e2b6f00 | 33 | } |
igor_v | 0:8ad47e2b6f00 | 34 | |
igor_v | 0:8ad47e2b6f00 | 35 | void CMD_Rate(void) |
igor_v | 21:bc8c1cec3da6 | 36 | { |
Kovalev_D | 107:4d178bcc9d8a | 37 | |
Kovalev_D | 115:e5a230e5af52 | 38 | |
Kovalev_D | 108:030cdde08314 | 39 | unsigned int Temp; |
Kovalev_D | 115:e5a230e5af52 | 40 | |
igor_v | 21:bc8c1cec3da6 | 41 | unsigned int Cnt_PlsL , Cnt_PlsH; // Счетчик +. |
igor_v | 21:bc8c1cec3da6 | 42 | unsigned int Cnt_MnsL , Cnt_MnsH; // Счетчик -. |
igor_v | 21:bc8c1cec3da6 | 43 | unsigned int Cnt_DifL , Cnt_DifH; // Разность счетчиков. |
igor_v | 21:bc8c1cec3da6 | 44 | unsigned int F_rasL , F_rasH; // Частота расщепления. |
igor_v | 21:bc8c1cec3da6 | 45 | |
Kovalev_D | 106:250ddd8629c6 | 46 | unsigned int HF_regL , HF_regH; // Выход регулятора ГВЧ. |
Kovalev_D | 106:250ddd8629c6 | 47 | unsigned int HF_difL , HF_difH; // Сигнал ошибки регулячтора ГВЧ. |
igor_v | 21:bc8c1cec3da6 | 48 | |
igor_v | 21:bc8c1cec3da6 | 49 | unsigned int WP_regL , WP_regH; |
igor_v | 21:bc8c1cec3da6 | 50 | |
igor_v | 21:bc8c1cec3da6 | 51 | unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; |
igor_v | 21:bc8c1cec3da6 | 52 | unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; |
Kovalev_D | 106:250ddd8629c6 | 53 | |
Kovalev_D | 108:030cdde08314 | 54 | |
Kovalev_D | 107:4d178bcc9d8a | 55 | |
igor_v | 30:17c84ed091b3 | 56 | Gyro.Firmware_Version=0xff; /// промежуточная затычка |
igor_v | 21:bc8c1cec3da6 | 57 | |
Kovalev_D | 108:030cdde08314 | 58 | |
Kovalev_D | 108:030cdde08314 | 59 | |
Kovalev_D | 106:250ddd8629c6 | 60 | |
igor_v | 30:17c84ed091b3 | 61 | Cnt_PlsH = ( Gyro.Cnt_Pls>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 62 | Cnt_PlsL = Gyro.Cnt_Pls TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 63 | Gyro.Cnt_Pls= 0; |
Kovalev_D | 106:250ddd8629c6 | 64 | |
igor_v | 30:17c84ed091b3 | 65 | Cnt_MnsH = ( Gyro.Cnt_Mns>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 66 | Cnt_MnsL = Gyro.Cnt_Mns TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 67 | Gyro.Cnt_Mns=0; |
Kovalev_D | 106:250ddd8629c6 | 68 | |
Kovalev_D | 106:250ddd8629c6 | 69 | Cnt_DifH = ( Dif_QEI>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 70 | Cnt_DifL = ( Dif_QEI ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 71 | |
Kovalev_D | 106:250ddd8629c6 | 72 | //Spi.DAC_A |
igor_v | 30:17c84ed091b3 | 73 | F_rasH = ( Gyro.F_ras>>8 ) TakeByte; |
igor_v | 30:17c84ed091b3 | 74 | F_rasL = ( Gyro.F_ras ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 75 | |
Kovalev_D | 107:4d178bcc9d8a | 76 | HF_regL = ( Spi.DAC_A ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 77 | HF_regH = ( Spi.DAC_A>>8 ) TakeByte; |
Kovalev_D | 107:4d178bcc9d8a | 78 | |
Kovalev_D | 107:4d178bcc9d8a | 79 | WP_regH = ( Spi.DAC_A>>8 ) TakeByte; |
Kovalev_D | 107:4d178bcc9d8a | 80 | WP_regL = ( Spi.DAC_A ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 81 | |
igor_v | 21:bc8c1cec3da6 | 82 | ADC1H = ( Spi.ADC1>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 83 | ADC1L = ( Spi.ADC1 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 84 | |
igor_v | 21:bc8c1cec3da6 | 85 | ADC2H = ( Spi.ADC2>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 86 | ADC2L = ( Spi.ADC2 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 87 | |
igor_v | 21:bc8c1cec3da6 | 88 | ADC3H = ( Spi.ADC3>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 89 | ADC3L = ( Spi.ADC3 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 90 | |
igor_v | 21:bc8c1cec3da6 | 91 | ADC4H = ( Spi.ADC4>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 92 | ADC4L = ( Spi.ADC4 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 93 | |
igor_v | 21:bc8c1cec3da6 | 94 | ADC5H = ( Spi.ADC5>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 95 | ADC5L = ( Spi.ADC5 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 96 | |
igor_v | 21:bc8c1cec3da6 | 97 | WP_regH = ( Spi.DAC_B>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 98 | WP_regL = ( Spi.DAC_B ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 99 | |
igor_v | 21:bc8c1cec3da6 | 100 | HF_regH=0xff; |
igor_v | 21:bc8c1cec3da6 | 101 | HF_regL=0xff; |
igor_v | 21:bc8c1cec3da6 | 102 | |
igor_v | 21:bc8c1cec3da6 | 103 | HF_difH=0xff; |
igor_v | 21:bc8c1cec3da6 | 104 | HF_difL=0xff; |
igor_v | 21:bc8c1cec3da6 | 105 | |
igor_v | 0:8ad47e2b6f00 | 106 | |
igor_v | 30:17c84ed091b3 | 107 | BuffTemp[ 0] = Gyro.SOC_Out; |
igor_v | 30:17c84ed091b3 | 108 | BuffTemp[ 1] = Gyro.My_Addres; |
igor_v | 21:bc8c1cec3da6 | 109 | |
Kovalev_D | 108:030cdde08314 | 110 | |
Kovalev_D | 112:4a96133a1311 | 111 | BuffTemp[ 2] =(Gyro.CaunPlus >> 8) & 0xff;//старший байт счетчика +. |
Kovalev_D | 112:4a96133a1311 | 112 | BuffTemp[ 3] =(Gyro.CaunPlus >> 0) & 0xff;//младший байт счетчика +. |
Kovalev_D | 108:030cdde08314 | 113 | |
Kovalev_D | 112:4a96133a1311 | 114 | BuffTemp[ 4] =(Gyro.CaunMin >> 8) & 0xff;//старший байт счетчика -. |
Kovalev_D | 112:4a96133a1311 | 115 | BuffTemp[ 5] =(Gyro.CaunMin >> 0) & 0xff;//младший байт счетчика -. |
Kovalev_D | 108:030cdde08314 | 116 | |
Kovalev_D | 113:8be429494918 | 117 | |
Kovalev_D | 108:030cdde08314 | 118 | Temp = Gyro.CuruAngle; |
Kovalev_D | 108:030cdde08314 | 119 | Gyro.CuruAngle = 0; |
Kovalev_D | 113:8be429494918 | 120 | |
Kovalev_D | 108:030cdde08314 | 121 | BuffTemp[ 6] =(Temp >> 8) & 0xff;//старший байт разности счетчиков |
Kovalev_D | 108:030cdde08314 | 122 | BuffTemp[ 7] =(Temp >> 0) & 0xff;//младший байт разности счетчиков |
Kovalev_D | 108:030cdde08314 | 123 | |
Kovalev_D | 108:030cdde08314 | 124 | |
Kovalev_D | 108:030cdde08314 | 125 | |
igor_v | 21:bc8c1cec3da6 | 126 | |
Kovalev_D | 106:250ddd8629c6 | 127 | BuffTemp[ 8] = F_rasH;//расщипление частота |
Kovalev_D | 106:250ddd8629c6 | 128 | BuffTemp[ 9] = F_rasL;// |
igor_v | 21:bc8c1cec3da6 | 129 | |
Kovalev_D | 108:030cdde08314 | 130 | BuffTemp[10] = (Temp >> 8) & 0xff;//выход регулятора гвч; |
Kovalev_D | 108:030cdde08314 | 131 | BuffTemp[11] = (Temp >> 0) & 0xff;; |
igor_v | 21:bc8c1cec3da6 | 132 | |
Kovalev_D | 108:030cdde08314 | 133 | BuffTemp[12]=(Temp >> 8) & 0xff;//// |
Kovalev_D | 108:030cdde08314 | 134 | BuffTemp[13]=(Temp >> 0) & 0xff;//// |
igor_v | 21:bc8c1cec3da6 | 135 | |
Kovalev_D | 108:030cdde08314 | 136 | |
Kovalev_D | 108:030cdde08314 | 137 | Temp = (unsigned int)((7680000*16/(Gyro.Frq>>12))); |
Kovalev_D | 108:030cdde08314 | 138 | BuffTemp[14] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 139 | BuffTemp[15] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 140 | |
Kovalev_D | 107:4d178bcc9d8a | 141 | BuffTemp[16] = 0xf; |
Kovalev_D | 106:250ddd8629c6 | 142 | BuffTemp[17] = 0x02; |
Kovalev_D | 108:030cdde08314 | 143 | |
igor_v | 21:bc8c1cec3da6 | 144 | |
Kovalev_D | 108:030cdde08314 | 145 | Temp = (unsigned int)(((7680000*16/200) *Gyro.AmpPer /(Gyro.Frq>>12))); |
Kovalev_D | 108:030cdde08314 | 146 | BuffTemp[18] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 147 | BuffTemp[19] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 148 | |
Kovalev_D | 106:250ddd8629c6 | 149 | BuffTemp[20] = 0x00; |
Kovalev_D | 106:250ddd8629c6 | 150 | BuffTemp[21] = 0x00; |
Kovalev_D | 108:030cdde08314 | 151 | Temp = Spi.DAC_B ; |
Kovalev_D | 108:030cdde08314 | 152 | BuffTemp[22] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 153 | BuffTemp[23] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 154 | |
Kovalev_D | 106:250ddd8629c6 | 155 | BuffTemp[24] = 0x00; |
Kovalev_D | 106:250ddd8629c6 | 156 | BuffTemp[25] = 0x00;// ХЗ |
Kovalev_D | 113:8be429494918 | 157 | |
Kovalev_D | 116:66f1f0ff2dab | 158 | Temp = Gyro.PLC_Delta >> 16; |
Kovalev_D | 113:8be429494918 | 159 | BuffTemp[26] = (Temp >> 8) & 0xff; |
Kovalev_D | 113:8be429494918 | 160 | BuffTemp[27] = (Temp >> 0) & 0xff; |
Kovalev_D | 113:8be429494918 | 161 | |
Kovalev_D | 113:8be429494918 | 162 | Temp = Gyro.AD_Slow >> 16; |
Kovalev_D | 113:8be429494918 | 163 | BuffTemp[28] = (Temp >> 8) & 0xff; |
Kovalev_D | 113:8be429494918 | 164 | BuffTemp[29] = (Temp >> 0) & 0xff; |
Kovalev_D | 113:8be429494918 | 165 | |
Kovalev_D | 113:8be429494918 | 166 | Temp = Gyro.In1; |
Kovalev_D | 113:8be429494918 | 167 | BuffTemp[30] = (Temp >> 8) & 0xff;//in1//2 |
Kovalev_D | 113:8be429494918 | 168 | BuffTemp[31] = (Temp >> 0) & 0xff; |
Kovalev_D | 113:8be429494918 | 169 | |
Kovalev_D | 113:8be429494918 | 170 | Temp = Gyro.In2; |
Kovalev_D | 113:8be429494918 | 171 | BuffTemp[32] = (Temp >> 8) & 0xff; |
Kovalev_D | 113:8be429494918 | 172 | BuffTemp[33] = (Temp >> 0) & 0xff;//in2//3 |
Kovalev_D | 113:8be429494918 | 173 | |
Kovalev_D | 113:8be429494918 | 174 | Temp = Gyro.DeltaT; |
Kovalev_D | 113:8be429494918 | 175 | BuffTemp[34] = (Temp >> 8) & 0xff;//дельта |
Kovalev_D | 113:8be429494918 | 176 | BuffTemp[35] = (Temp >> 0) & 0xff; |
Kovalev_D | 115:e5a230e5af52 | 177 | |
Kovalev_D | 116:66f1f0ff2dab | 178 | Temp = Gyro.Termo;//0xa4=164 |
Kovalev_D | 115:e5a230e5af52 | 179 | |
Kovalev_D | 113:8be429494918 | 180 | BuffTemp[36] =(Temp >> 8) & 0xff;//температура |
Kovalev_D | 115:e5a230e5af52 | 181 | BuffTemp[37] =(Temp >> 0) & 0xff;//ADC6 sesnsor 5 |
igor_v | 21:bc8c1cec3da6 | 182 | |
Kovalev_D | 106:250ddd8629c6 | 183 | BuffTemp[38] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 184 | BuffTemp[39] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 185 | BuffTemp[40] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 186 | BuffTemp[41] =0x00; |
igor_v | 21:bc8c1cec3da6 | 187 | |
igor_v | 21:bc8c1cec3da6 | 188 | |
igor_v | 21:bc8c1cec3da6 | 189 | Check(BuffTemp, 44); |
igor_v | 21:bc8c1cec3da6 | 190 | WriteConN (BuffTemp,44); |
Kovalev_D | 92:c892f0311aa7 | 191 | |
igor_v | 0:8ad47e2b6f00 | 192 | } |
igor_v | 0:8ad47e2b6f00 | 193 | |
igor_v | 21:bc8c1cec3da6 | 194 | void CMD_M_Control_D8()///установка\сброс регистров управления |
igor_v | 21:bc8c1cec3da6 | 195 | { |
Kovalev_D | 104:ab1cb4ff56b2 | 196 | unsigned int bit,NReg,Pa; |
Kovalev_D | 104:ab1cb4ff56b2 | 197 | unsigned int SR,V,A,Bit_num; |
Kovalev_D | 104:ab1cb4ff56b2 | 198 | SR=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 199 | V=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 200 | A=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 201 | Bit_num=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 202 | |
igor_v | 30:17c84ed091b3 | 203 | BuffTemp[0] = Gyro.SOC_Out; //DD |
igor_v | 30:17c84ed091b3 | 204 | BuffTemp[1] = Gyro.My_Addres; //00 |
igor_v | 30:17c84ed091b3 | 205 | BuffTemp[2] = Gyro.CMD_In; //D8 |
Kovalev_D | 104:ab1cb4ff56b2 | 206 | |
Kovalev_D | 104:ab1cb4ff56b2 | 207 | /* |
Kovalev_D | 104:ab1cb4ff56b2 | 208 | |
Kovalev_D | 104:ab1cb4ff56b2 | 209 | FrqON |
Kovalev_D | 104:ab1cb4ff56b2 | 210 | PlcON |
Kovalev_D | 104:ab1cb4ff56b2 | 211 | HFOOFF |
Kovalev_D | 104:ab1cb4ff56b2 | 212 | HFOON |
igor_v | 21:bc8c1cec3da6 | 213 | |
Kovalev_D | 104:ab1cb4ff56b2 | 214 | PlcOFF |
Kovalev_D | 104:ab1cb4ff56b2 | 215 | PlcON |
Kovalev_D | 104:ab1cb4ff56b2 | 216 | */ |
Kovalev_D | 104:ab1cb4ff56b2 | 217 | Pa = BuffTemp[3]; |
Kovalev_D | 104:ab1cb4ff56b2 | 218 | |
Kovalev_D | 104:ab1cb4ff56b2 | 219 | SR = Pa >> 0x7; |
Kovalev_D | 104:ab1cb4ff56b2 | 220 | |
Kovalev_D | 104:ab1cb4ff56b2 | 221 | V = Pa >> 0x5; |
Kovalev_D | 104:ab1cb4ff56b2 | 222 | V = V & 0x3; |
Kovalev_D | 104:ab1cb4ff56b2 | 223 | |
Kovalev_D | 104:ab1cb4ff56b2 | 224 | A = Pa >> 0x4; |
Kovalev_D | 104:ab1cb4ff56b2 | 225 | A = A & 0x1; |
Kovalev_D | 104:ab1cb4ff56b2 | 226 | |
Kovalev_D | 104:ab1cb4ff56b2 | 227 | Bit_num = Pa & 0xf; |
Kovalev_D | 104:ab1cb4ff56b2 | 228 | |
Kovalev_D | 104:ab1cb4ff56b2 | 229 | if(SR) { |
Kovalev_D | 104:ab1cb4ff56b2 | 230 | switch (Bit_num){ |
Kovalev_D | 105:bd01d8d20fb6 | 231 | |
Kovalev_D | 104:ab1cb4ff56b2 | 232 | case 0x06: |
Kovalev_D | 104:ab1cb4ff56b2 | 233 | FrqON |
Kovalev_D | 105:bd01d8d20fb6 | 234 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 235 | |
Kovalev_D | 104:ab1cb4ff56b2 | 236 | case 0x03: |
Kovalev_D | 105:bd01d8d20fb6 | 237 | HFOON |
Kovalev_D | 105:bd01d8d20fb6 | 238 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 239 | |
Kovalev_D | 105:bd01d8d20fb6 | 240 | case 0x01: |
Kovalev_D | 105:bd01d8d20fb6 | 241 | PlcON |
Kovalev_D | 105:bd01d8d20fb6 | 242 | break; |
Kovalev_D | 104:ab1cb4ff56b2 | 243 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 244 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 245 | else{ |
Kovalev_D | 104:ab1cb4ff56b2 | 246 | switch (Bit_num){ |
Kovalev_D | 105:bd01d8d20fb6 | 247 | |
Kovalev_D | 105:bd01d8d20fb6 | 248 | case 0x06: |
Kovalev_D | 104:ab1cb4ff56b2 | 249 | FrqOff |
Kovalev_D | 105:bd01d8d20fb6 | 250 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 251 | |
Kovalev_D | 105:bd01d8d20fb6 | 252 | case 0x03: |
Kovalev_D | 105:bd01d8d20fb6 | 253 | HFOOFF |
Kovalev_D | 105:bd01d8d20fb6 | 254 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 255 | |
Kovalev_D | 105:bd01d8d20fb6 | 256 | case 0x01: |
Kovalev_D | 105:bd01d8d20fb6 | 257 | PlcOFF |
Kovalev_D | 105:bd01d8d20fb6 | 258 | break; |
Kovalev_D | 104:ab1cb4ff56b2 | 259 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 260 | } |
igor_v | 21:bc8c1cec3da6 | 261 | |
igor_v | 0:8ad47e2b6f00 | 262 | } |
igor_v | 0:8ad47e2b6f00 | 263 | |
igor_v | 21:bc8c1cec3da6 | 264 | void CMD_M_Control_D9()///чтение регистров управления |
igor_v | 21:bc8c1cec3da6 | 265 | { |
igor_v | 21:bc8c1cec3da6 | 266 | int bit,NReg; |
igor_v | 30:17c84ed091b3 | 267 | BuffTemp[0] = Gyro.SOC_Out; //DD |
igor_v | 30:17c84ed091b3 | 268 | BuffTemp[1] = Gyro.My_Addres; //00 |
igor_v | 30:17c84ed091b3 | 269 | BuffTemp[2] = Gyro.CMD_In; //D9 |
igor_v | 21:bc8c1cec3da6 | 270 | if ((Param1 & 0x10) == 0) { |
igor_v | 21:bc8c1cec3da6 | 271 | BuffTemp[3]=0<<4; |
igor_v | 30:17c84ed091b3 | 272 | BuffTemp[4] = (Gyro.RgConA>>8 )& 0xff; |
igor_v | 30:17c84ed091b3 | 273 | BuffTemp[5] = Gyro.RgConA & 0xff; |
igor_v | 21:bc8c1cec3da6 | 274 | } else { |
igor_v | 21:bc8c1cec3da6 | 275 | BuffTemp[3]=1<<4; |
igor_v | 30:17c84ed091b3 | 276 | BuffTemp[4] = (Gyro.RgConB>>8 ) & 0xff; |
igor_v | 30:17c84ed091b3 | 277 | BuffTemp[5] = Gyro.RgConB & 0xff; |
igor_v | 21:bc8c1cec3da6 | 278 | } |
igor_v | 21:bc8c1cec3da6 | 279 | Check(BuffTemp, CRC_N); |
igor_v | 21:bc8c1cec3da6 | 280 | WriteConN (BuffTemp,CRC_N); |
igor_v | 21:bc8c1cec3da6 | 281 | } |
igor_v | 21:bc8c1cec3da6 | 282 | // (номер (код) ЦАПа 0...3, старший байт требуемого ЦАПа, младший байт треб ЦАПа) |
igor_v | 0:8ad47e2b6f00 | 283 | void CMD_M_Stymul() |
igor_v | 0:8ad47e2b6f00 | 284 | { |
igor_v | 21:bc8c1cec3da6 | 285 | int temp; |
Kovalev_D | 102:4270092be987 | 286 | int HFO; |
Kovalev_D | 102:4270092be987 | 287 | temp=BuffTemp[3]; |
Kovalev_D | 102:4270092be987 | 288 | Consol = temp&0x3; |
Kovalev_D | 103:e96f08947def | 289 | HFO = temp&0x3;// // (номер (код) ЦАПа 0...3, HFO - 3dac, PLC - 0DAC |
igor_v | 21:bc8c1cec3da6 | 290 | temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 21:bc8c1cec3da6 | 291 | // temp=0; |
igor_v | 21:bc8c1cec3da6 | 292 | temp=temp&0xFFFF; |
Kovalev_D | 102:4270092be987 | 293 | |
Kovalev_D | 102:4270092be987 | 294 | if(HFO) |
Kovalev_D | 102:4270092be987 | 295 | { |
Kovalev_D | 102:4270092be987 | 296 | Spi.DAC_A=(unsigned int)temp; |
Kovalev_D | 102:4270092be987 | 297 | } |
Kovalev_D | 102:4270092be987 | 298 | else{ |
igor_v | 21:bc8c1cec3da6 | 299 | DACF =(temp*K_DAC)+deltaDAC; |
igor_v | 21:bc8c1cec3da6 | 300 | Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); |
igor_v | 21:bc8c1cec3da6 | 301 | } |
igor_v | 0:8ad47e2b6f00 | 302 | } |
Kovalev_D | 103:e96f08947def | 303 | void Gph_W() |
Kovalev_D | 103:e96f08947def | 304 | { |
Kovalev_D | 108:030cdde08314 | 305 | Out_G_photo(BuffTemp[4],BuffTemp[5]); |
Kovalev_D | 103:e96f08947def | 306 | } |
igor_v | 0:8ad47e2b6f00 | 307 | |
Kovalev_D | 98:95b8e79f13e1 | 308 | void CMD_M_vib() |
Kovalev_D | 115:e5a230e5af52 | 309 | { |
Kovalev_D | 102:4270092be987 | 310 | unsigned int temp1,temp2; |
Kovalev_D | 102:4270092be987 | 311 | |
Kovalev_D | 102:4270092be987 | 312 | temp1 =((BuffTemp[4]<<8) | BuffTemp[5]); |
Kovalev_D | 102:4270092be987 | 313 | temp1=temp1&0xFFFF; |
Kovalev_D | 102:4270092be987 | 314 | |
Kovalev_D | 102:4270092be987 | 315 | temp2 =((BuffTemp[6]<<8) | BuffTemp[7]); |
Kovalev_D | 102:4270092be987 | 316 | temp2=temp2&0xFFFF; |
Kovalev_D | 102:4270092be987 | 317 | Gyro.Frq = ((unsigned int) ((7680000*16/temp1)))*16*16*16; |
Kovalev_D | 102:4270092be987 | 318 | Consol=Gyro.Frq ; |
Kovalev_D | 98:95b8e79f13e1 | 319 | } |
igor_v | 0:8ad47e2b6f00 | 320 | unsigned int Check(char *c, unsigned int Count) |
igor_v | 0:8ad47e2b6f00 | 321 | { |
igor_v | 21:bc8c1cec3da6 | 322 | int i=1; |
igor_v | 21:bc8c1cec3da6 | 323 | unsigned int temp,CRC; |
igor_v | 21:bc8c1cec3da6 | 324 | |
igor_v | 21:bc8c1cec3da6 | 325 | |
igor_v | 21:bc8c1cec3da6 | 326 | temp=1; |
igor_v | 21:bc8c1cec3da6 | 327 | CRC=0; |
igor_v | 21:bc8c1cec3da6 | 328 | |
igor_v | 21:bc8c1cec3da6 | 329 | |
igor_v | 21:bc8c1cec3da6 | 330 | for(; i<Count-2; i++) { |
igor_v | 21:bc8c1cec3da6 | 331 | CRC+=c[i]; |
igor_v | 21:bc8c1cec3da6 | 332 | } |
igor_v | 0:8ad47e2b6f00 | 333 | |
igor_v | 21:bc8c1cec3da6 | 334 | if(c[Count-2]!=((CRC>>8)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 335 | temp=0; |
igor_v | 30:17c84ed091b3 | 336 | Gyro.RsErrLine = (Gyro.RsErrLine)&=0x2; |
igor_v | 21:bc8c1cec3da6 | 337 | } |
igor_v | 0:8ad47e2b6f00 | 338 | |
igor_v | 21:bc8c1cec3da6 | 339 | if(c[Count-1]!=((CRC>>0)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 340 | temp=0; |
igor_v | 30:17c84ed091b3 | 341 | // Gyro.RsErrLine= (Gyro.RsErrLine)=0x2; |
igor_v | 21:bc8c1cec3da6 | 342 | } |
igor_v | 21:bc8c1cec3da6 | 343 | |
igor_v | 21:bc8c1cec3da6 | 344 | c[Count-2]=(CRC>>8)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 345 | c[Count-1]=(CRC>>0)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 346 | |
igor_v | 21:bc8c1cec3da6 | 347 | |
igor_v | 21:bc8c1cec3da6 | 348 | |
igor_v | 21:bc8c1cec3da6 | 349 | return temp; |
igor_v | 0:8ad47e2b6f00 | 350 | } |
igor_v | 0:8ad47e2b6f00 | 351 | |
igor_v | 0:8ad47e2b6f00 | 352 | int Getlengf(void) |
igor_v | 0:8ad47e2b6f00 | 353 | { |
igor_v | 21:bc8c1cec3da6 | 354 | unsigned int lengf=0; |
igor_v | 30:17c84ed091b3 | 355 | switch(Gyro.CMD_In) { |
igor_v | 30:17c84ed091b3 | 356 | case 0x99://Gyrotainance |
Kovalev_D | 92:c892f0311aa7 | 357 | |
igor_v | 21:bc8c1cec3da6 | 358 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 359 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 360 | break; |
igor_v | 0:8ad47e2b6f00 | 361 | |
igor_v | 21:bc8c1cec3da6 | 362 | case 0x0A: //m_stymul |
igor_v | 21:bc8c1cec3da6 | 363 | lengf=8; |
igor_v | 21:bc8c1cec3da6 | 364 | break; |
igor_v | 21:bc8c1cec3da6 | 365 | |
igor_v | 21:bc8c1cec3da6 | 366 | case 0xA5://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 367 | |
igor_v | 21:bc8c1cec3da6 | 368 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 369 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 370 | break; |
igor_v | 21:bc8c1cec3da6 | 371 | |
igor_v | 21:bc8c1cec3da6 | 372 | case 0xDD://m_rate |
igor_v | 0:8ad47e2b6f00 | 373 | |
igor_v | 21:bc8c1cec3da6 | 374 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 375 | CRC_N=44; |
igor_v | 21:bc8c1cec3da6 | 376 | break; |
igor_v | 21:bc8c1cec3da6 | 377 | |
igor_v | 21:bc8c1cec3da6 | 378 | case 0xB0://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 379 | |
igor_v | 21:bc8c1cec3da6 | 380 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 381 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 382 | break; |
igor_v | 21:bc8c1cec3da6 | 383 | |
igor_v | 21:bc8c1cec3da6 | 384 | case 0xD8://m_control |
igor_v | 0:8ad47e2b6f00 | 385 | |
igor_v | 21:bc8c1cec3da6 | 386 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 387 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 388 | break; |
igor_v | 21:bc8c1cec3da6 | 389 | |
igor_v | 21:bc8c1cec3da6 | 390 | case 0xD9://m_control |
igor_v | 0:8ad47e2b6f00 | 391 | |
igor_v | 21:bc8c1cec3da6 | 392 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 393 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 394 | break; |
Kovalev_D | 102:4270092be987 | 395 | |
Kovalev_D | 102:4270092be987 | 396 | case 0xE4: |
Kovalev_D | 98:95b8e79f13e1 | 397 | lengf=8; |
Kovalev_D | 98:95b8e79f13e1 | 398 | break; |
Kovalev_D | 103:e96f08947def | 399 | |
Kovalev_D | 103:e96f08947def | 400 | |
Kovalev_D | 103:e96f08947def | 401 | case 0xE6: |
Kovalev_D | 103:e96f08947def | 402 | lengf=8; |
Kovalev_D | 103:e96f08947def | 403 | break; |
Kovalev_D | 103:e96f08947def | 404 | |
igor_v | 21:bc8c1cec3da6 | 405 | } |
Kovalev_D | 98:95b8e79f13e1 | 406 | |
igor_v | 21:bc8c1cec3da6 | 407 | return lengf; |
igor_v | 0:8ad47e2b6f00 | 408 | } |
igor_v | 0:8ad47e2b6f00 | 409 | |
igor_v | 0:8ad47e2b6f00 | 410 | void Read_CMD(void) |
igor_v | 21:bc8c1cec3da6 | 411 | { |
Kovalev_D | 92:c892f0311aa7 | 412 | |
Kovalev_D | 45:cbc955aecebe | 413 | |
Kovalev_D | 45:cbc955aecebe | 414 | Gyro.RsErrLine = (Gyro.RsErrLine)& 0xffff;//для сброса ошибки |
igor_v | 21:bc8c1cec3da6 | 415 | |
Kovalev_D | 93:b3803774f110 | 416 | CountBuFFIn=ReadChekCon1(BuffTemp); // чтение данных из консоли |
igor_v | 42:6fc307c4963e | 417 | |
Kovalev_D | 92:c892f0311aa7 | 418 | if(CountBuFFIn==1) { // если есть первый байт |
igor_v | 21:bc8c1cec3da6 | 419 | if (BuffTemp[0] != SOC_In) { |
Kovalev_D | 93:b3803774f110 | 420 | ReadCon1(BuffTemp); |
igor_v | 30:17c84ed091b3 | 421 | Gyro.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); |
Kovalev_D | 93:b3803774f110 | 422 | BuffTemp[99]=Gyro.RsErrLine; |
Kovalev_D | 102:4270092be987 | 423 | |
igor_v | 21:bc8c1cec3da6 | 424 | } |
Kovalev_D | 92:c892f0311aa7 | 425 | } else if(CountBuFFIn==2) { //если второй ,fqn |
igor_v | 30:17c84ed091b3 | 426 | if (BuffTemp[1] != Gyro.My_Addres) { |
Kovalev_D | 93:b3803774f110 | 427 | ReadCon1(BuffTemp); |
igor_v | 30:17c84ed091b3 | 428 | Gyro.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); |
igor_v | 21:bc8c1cec3da6 | 429 | } |
igor_v | 42:6fc307c4963e | 430 | } else if(CountBuFFIn==3) { // если ьоетий байт |
igor_v | 30:17c84ed091b3 | 431 | Gyro.CMD_In=BuffTemp[2]; |
Kovalev_D | 92:c892f0311aa7 | 432 | N=Getlengf(); |
Kovalev_D | 92:c892f0311aa7 | 433 | } |
Kovalev_D | 92:c892f0311aa7 | 434 | else if(CountBuFFIn==4 && (N==6)) |
Kovalev_D | 92:c892f0311aa7 | 435 | { // N - длина посылки аскглд(для записи параметров). определяется по коду команды в Getlengf(); |
igor_v | 21:bc8c1cec3da6 | 436 | Param1=BuffTemp[3]; |
Kovalev_D | 92:c892f0311aa7 | 437 | } |
Kovalev_D | 92:c892f0311aa7 | 438 | else if((CountBuFFIn==5)&&(N==7)) |
Kovalev_D | 92:c892f0311aa7 | 439 | { |
Kovalev_D | 92:c892f0311aa7 | 440 | |
igor_v | 21:bc8c1cec3da6 | 441 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 442 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 443 | |
Kovalev_D | 92:c892f0311aa7 | 444 | } |
Kovalev_D | 92:c892f0311aa7 | 445 | else if((CountBuFFIn==6)&&(N==8)) |
Kovalev_D | 92:c892f0311aa7 | 446 | { |
igor_v | 21:bc8c1cec3da6 | 447 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 448 | Param2=BuffTemp[4]; |
igor_v | 21:bc8c1cec3da6 | 449 | Param3=BuffTemp[5]; |
Kovalev_D | 92:c892f0311aa7 | 450 | } |
Kovalev_D | 102:4270092be987 | 451 | else if((CountBuFFIn==8)&&(N==10)) |
Kovalev_D | 102:4270092be987 | 452 | { |
Kovalev_D | 102:4270092be987 | 453 | Param1=BuffTemp[4]; |
Kovalev_D | 102:4270092be987 | 454 | Param2=BuffTemp[5]; |
Kovalev_D | 102:4270092be987 | 455 | Param3=BuffTemp[6]; |
Kovalev_D | 102:4270092be987 | 456 | Param4=BuffTemp[7]; |
Kovalev_D | 102:4270092be987 | 457 | } |
Kovalev_D | 98:95b8e79f13e1 | 458 | |
Kovalev_D | 92:c892f0311aa7 | 459 | else if(CountBuFFIn > (N-1)) |
Kovalev_D | 92:c892f0311aa7 | 460 | { |
Kovalev_D | 93:b3803774f110 | 461 | ReadCon1(BuffTemp); |
igor_v | 30:17c84ed091b3 | 462 | switch(Gyro.CMD_In) { |
Kovalev_D | 92:c892f0311aa7 | 463 | case 0x99: |
igor_v | 21:bc8c1cec3da6 | 464 | CMD_Maintenance(); |
igor_v | 21:bc8c1cec3da6 | 465 | break; |
igor_v | 21:bc8c1cec3da6 | 466 | case 0xD8: |
igor_v | 21:bc8c1cec3da6 | 467 | CMD_M_Control_D8(); |
igor_v | 21:bc8c1cec3da6 | 468 | case 0xD9: |
igor_v | 21:bc8c1cec3da6 | 469 | CMD_M_Control_D9(); |
igor_v | 21:bc8c1cec3da6 | 470 | break; |
igor_v | 21:bc8c1cec3da6 | 471 | case 0x0A: |
Kovalev_D | 45:cbc955aecebe | 472 | CMD_M_Stymul(); |
igor_v | 21:bc8c1cec3da6 | 473 | break; |
igor_v | 21:bc8c1cec3da6 | 474 | case 0xDD: |
igor_v | 21:bc8c1cec3da6 | 475 | Rate_Flag=1; |
Kovalev_D | 102:4270092be987 | 476 | break; |
Kovalev_D | 102:4270092be987 | 477 | case 0xE4: |
Kovalev_D | 102:4270092be987 | 478 | CMD_M_vib(); |
Kovalev_D | 102:4270092be987 | 479 | break; |
Kovalev_D | 103:e96f08947def | 480 | case 0xE6: |
Kovalev_D | 103:e96f08947def | 481 | Gph_W(); |
Kovalev_D | 103:e96f08947def | 482 | break; |
Kovalev_D | 108:030cdde08314 | 483 | |
Kovalev_D | 103:e96f08947def | 484 | |
igor_v | 30:17c84ed091b3 | 485 | Gyro.RsErrLine = 0; |
Kovalev_D | 103:e96f08947def | 486 | |
Kovalev_D | 103:e96f08947def | 487 | |
Kovalev_D | 102:4270092be987 | 488 | } |
igor_v | 21:bc8c1cec3da6 | 489 | } |
igor_v | 0:8ad47e2b6f00 | 490 | } |
igor_v | 0:8ad47e2b6f00 | 491 | |
igor_v | 0:8ad47e2b6f00 | 492 | |
igor_v | 21:bc8c1cec3da6 | 493 |