![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
Global.c@101:bb7472afb947, 2016-03-30 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Mar 30 11:03:05 2016 +0000
- Revision:
- 101:bb7472afb947
- Parent:
- 100:e197a8d2cf43
???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | |
igor_v | 0:8ad47e2b6f00 | 3 | |
igor_v | 0:8ad47e2b6f00 | 4 | |
Kovalev_D | 89:a0d344db227e | 5 | unsigned int VibroReg = 0; //регистр состаяния вибропривода. |
Kovalev_D | 89:a0d344db227e | 6 | unsigned long Global_Time, Time_UART,Time_Sec,Time_vibro,Time_1kHz; |
Kovalev_D | 99:3d8f206ceac2 | 7 | int MaxAmp=0; |
Kovalev_D | 89:a0d344db227e | 8 | unsigned char BuffTemp[100]; |
Kovalev_D | 89:a0d344db227e | 9 | unsigned char Time[500]; |
Kovalev_D | 86:398da56ef751 | 10 | unsigned int Event1Hz; |
Kovalev_D | 88:b5c1d9d338d1 | 11 | unsigned int Event1K ; |
Kovalev_D | 88:b5c1d9d338d1 | 12 | unsigned int Event100K; |
Kovalev_D | 88:b5c1d9d338d1 | 13 | unsigned int EventVibro; |
Kovalev_D | 88:b5c1d9d338d1 | 14 | unsigned int Time1K; |
Kovalev_D | 88:b5c1d9d338d1 | 15 | unsigned int Time100K; |
Kovalev_D | 88:b5c1d9d338d1 | 16 | unsigned int Time1Hz; |
Kovalev_D | 88:b5c1d9d338d1 | 17 | unsigned int Clock1Hz; |
Kovalev_D | 86:398da56ef751 | 18 | unsigned int ShiftD; |
Kovalev_D | 86:398da56ef751 | 19 | unsigned int ShiftL; |
Kovalev_D | 86:398da56ef751 | 20 | |
Kovalev_D | 100:e197a8d2cf43 | 21 | |
Kovalev_D | 101:bb7472afb947 | 22 | |
Kovalev_D | 100:e197a8d2cf43 | 23 | |
Kovalev_D | 86:398da56ef751 | 24 | void GLD_Init(void) |
Kovalev_D | 86:398da56ef751 | 25 | { |
Kovalev_D | 90:d9b6a4bc5065 | 26 | int Dummy; // инициализация мусорки для очистки буфера приема. |
Kovalev_D | 89:a0d344db227e | 27 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 28 | ///////////инициализация таймеров//////////// |
Kovalev_D | 89:a0d344db227e | 29 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 30 | Init_TIM1(TIME_INTERVAL ); //Timer 1: CCLK / 7812 = 12800.819Hz; Vibro: Timer1/32 = 400.025Hz; 10ms??? |
Kovalev_D | 89:a0d344db227e | 31 | Init_TIM2(); //Timer 2: CCLK / 4 / 250 = 100kHz |
Kovalev_D | 89:a0d344db227e | 32 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 33 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 34 | |
Kovalev_D | 89:a0d344db227e | 35 | |
Kovalev_D | 86:398da56ef751 | 36 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 37 | ///////////обнуление счетчиков/////////////// |
Kovalev_D | 86:398da56ef751 | 38 | ///////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 39 | Global_Time = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 40 | Time_UART = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 41 | Time_Sec = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 42 | Time_vibro = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 43 | Time_1kHz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 44 | Event1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 45 | Event1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 46 | Event100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 47 | EventVibro = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 48 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 49 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 50 | Time1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 51 | Clock1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 52 | ShiftD = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 53 | ShiftL = 0; |
Kovalev_D | 101:bb7472afb947 | 54 | |
Kovalev_D | 86:398da56ef751 | 55 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 56 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 57 | |
Kovalev_D | 88:b5c1d9d338d1 | 58 | |
Kovalev_D | 88:b5c1d9d338d1 | 59 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 60 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 61 | ///////////расчета значений буферов ВП/////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 62 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 63 | /////////////инициализация переменных в структ вибро///////////////// |
Kovalev_D | 101:bb7472afb947 | 64 | Gyro.FrqHZ=435; |
Kovalev_D | 88:b5c1d9d338d1 | 65 | Gyro.Frq = Gyro.FrqHZ<<16; |
Kovalev_D | 88:b5c1d9d338d1 | 66 | Gyro.AmpPer=20; |
Kovalev_D | 88:b5c1d9d338d1 | 67 | Gyro.AmpPerDel=10; |
Kovalev_D | 88:b5c1d9d338d1 | 68 | Gyro.Amp = 10*65535; |
Kovalev_D | 88:b5c1d9d338d1 | 69 | Gyro.AmpMin =10;// минимальное значение AmpT; |
Kovalev_D | 88:b5c1d9d338d1 | 70 | Gyro.AmpTD =30;// максимальное значение AmpT; (AmpT частота ошумления) |
Kovalev_D | 88:b5c1d9d338d1 | 71 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 72 | CuruAngle = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 73 | Pulse_8Point = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 74 | Pulse_16Point = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 75 | Pulse_16PointD = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 76 | Pulse_32Point = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 77 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 78 | /////////////предварительное заполнение////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 79 | ////////////////буферов вибропривода///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 80 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 81 | for (int i = 0; i < 32; i++ ) { |
Kovalev_D | 88:b5c1d9d338d1 | 82 | Buff_16Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 83 | Buff_8Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 84 | Buff_32Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 85 | Buff_16PointD[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 86 | } |
Kovalev_D | 88:b5c1d9d338d1 | 87 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 88 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 89 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 90 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 91 | //////////////////переменных АЦП///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 92 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 93 | Temp_AMP=0; |
Kovalev_D | 96:1c8536458119 | 94 | Temp_AMP64P=0; |
Kovalev_D | 88:b5c1d9d338d1 | 95 | Temp_ADC_2=0; |
Kovalev_D | 88:b5c1d9d338d1 | 96 | Temp_ADC_3=0; |
Kovalev_D | 88:b5c1d9d338d1 | 97 | Temp_ADC_4=0; |
Kovalev_D | 88:b5c1d9d338d1 | 98 | Temp_ADC_5=0; |
Kovalev_D | 88:b5c1d9d338d1 | 99 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 100 | /////////////предварительное заполнение////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 101 | /////////////////////буферов АЦП///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 102 | ///////////////////////////////////////////////////// |
Kovalev_D | 95:dd51e577e114 | 103 | for (int i = 0; i < 32; i++ ) { |
Kovalev_D | 88:b5c1d9d338d1 | 104 | Buff_ADC_1[i] = 0; // ампл ацп. |
Kovalev_D | 88:b5c1d9d338d1 | 105 | Buff_ADC_2[i] = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 106 | Buff_ADC_3[i] = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 107 | Buff_ADC_4[i] = 0; |
Kovalev_D | 95:dd51e577e114 | 108 | } |
Kovalev_D | 95:dd51e577e114 | 109 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 95:dd51e577e114 | 110 | Buff_ADC_5[i]= 0; |
Kovalev_D | 88:b5c1d9d338d1 | 111 | } |
Kovalev_D | 96:1c8536458119 | 112 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 96:1c8536458119 | 113 | Buff_AMP64P[i]= 0; |
Kovalev_D | 96:1c8536458119 | 114 | } |
Kovalev_D | 96:1c8536458119 | 115 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 96:1c8536458119 | 116 | Buff_AMP[i]= 0; |
Kovalev_D | 96:1c8536458119 | 117 | } |
Kovalev_D | 88:b5c1d9d338d1 | 118 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 119 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 120 | |
Kovalev_D | 88:b5c1d9d338d1 | 121 | |
Kovalev_D | 88:b5c1d9d338d1 | 122 | |
Kovalev_D | 88:b5c1d9d338d1 | 123 | |
Kovalev_D | 88:b5c1d9d338d1 | 124 | |
Kovalev_D | 92:c892f0311aa7 | 125 | |
Kovalev_D | 88:b5c1d9d338d1 | 126 | Gyro.SOC_Out=0xDD; |
Kovalev_D | 86:398da56ef751 | 127 | Gyro.Firmware_Version =0x15; //версия программы |
Kovalev_D | 86:398da56ef751 | 128 | Gyro.GLD_Serial = 0x20; //серийный номер |
Kovalev_D | 86:398da56ef751 | 129 | Gyro.My_Addres = 0; //адрес глд |
Kovalev_D | 86:398da56ef751 | 130 | Gyro.Discharg = StartDischarg; |
Kovalev_D | 86:398da56ef751 | 131 | Gyro.BackLight = StartBackLight; |
Kovalev_D | 92:c892f0311aa7 | 132 | |
Kovalev_D | 88:b5c1d9d338d1 | 133 | |
Kovalev_D | 89:a0d344db227e | 134 | |
Kovalev_D | 89:a0d344db227e | 135 | |
Kovalev_D | 88:b5c1d9d338d1 | 136 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 137 | //////инициализация цап_LPC (р0.26 цап выход)//////// |
Kovalev_D | 88:b5c1d9d338d1 | 138 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 139 | LPC_PINCON->PINSEL1 = 0x00200000; |
Kovalev_D | 88:b5c1d9d338d1 | 140 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 141 | ////////////начальное значение для цап/////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 142 | //////////////////середина шкалы///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 143 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 144 | Spi.DAC_A = 0x7fff; |
Kovalev_D | 86:398da56ef751 | 145 | Spi.DAC_B = 0x7fff; |
Kovalev_D | 86:398da56ef751 | 146 | //////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 147 | /////////////поправочный коэффициент///////////////// |
Kovalev_D | 86:398da56ef751 | 148 | /////////для цапов (граници +-12.5 вольт)//////////// |
Kovalev_D | 86:398da56ef751 | 149 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 150 | K_DAC=65535.0/(65535.0+(deltaDAC+deltaDAC/2)); |
Kovalev_D | 86:398da56ef751 | 151 | K_DAC=0.8; |
Kovalev_D | 88:b5c1d9d338d1 | 152 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 153 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 154 | |
igor_v | 16:18e3fd7b92d0 | 155 | |
igor_v | 16:18e3fd7b92d0 | 156 | |
Kovalev_D | 86:398da56ef751 | 157 | secPuls =0;// переменная для конопки поджига аск глд(временная) |
Kovalev_D | 88:b5c1d9d338d1 | 158 | |
Kovalev_D | 86:398da56ef751 | 159 | |
Kovalev_D | 86:398da56ef751 | 160 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 161 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 86:398da56ef751 | 162 | ///////////////переменных энкодера/////////////////// |
Kovalev_D | 86:398da56ef751 | 163 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 164 | Cur_QEI=0; |
Kovalev_D | 86:398da56ef751 | 165 | Last_QEI=0; |
Kovalev_D | 86:398da56ef751 | 166 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 167 | /////////////инициализация энкодера////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 168 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 169 | LPC_SC->PCONP |= (1<<18);//0x00040000; включение квадратурного энкодера. |
Kovalev_D | 87:7e575d26d6d0 | 170 | LPC_SC->PCLKSEL1 |= 0x00000001; // выбор частоты для кв.э. CLK=100MHz |
Kovalev_D | 87:7e575d26d6d0 | 171 | LPC_PINCON->PINSEL3 &= ~0x4100; |
Kovalev_D | 87:7e575d26d6d0 | 172 | LPC_PINCON->PINSEL3 |= 0x4100; //P1.20, p1.23 установить как входы кв.э |
Kovalev_D | 89:a0d344db227e | 173 | LPC_PINCON->PINMODE3 |= 0x3C300; //P1.20, p1.23 |
Kovalev_D | 86:398da56ef751 | 174 | |
Kovalev_D | 98:95b8e79f13e1 | 175 | |
Kovalev_D | 87:7e575d26d6d0 | 176 | LPC_QEI->MAXPOS = MAX_QEI_CNT; //LPC_QEI->"регистор максимального положения" = 2147483646 |
Kovalev_D | 89:a0d344db227e | 177 | LPC_QEI->FILTER = 2; // фильтр( ?? ) |
Kovalev_D | 87:7e575d26d6d0 | 178 | LPC_QEI->CON = 0xF; //сбросить в ноль все счетчики кв.э. (скорость, направление, позицию и тд) |
Kovalev_D | 87:7e575d26d6d0 | 179 | LPC_QEI->CONF = (0<<2) |(0<<1); //Quadrature inputs, no inverting,only A pulses are counted |
Kovalev_D | 87:7e575d26d6d0 | 180 | |
Kovalev_D | 87:7e575d26d6d0 | 181 | LPC_QEI->CLR = 0x1fff; //r. сбросить все прерывания |
Kovalev_D | 87:7e575d26d6d0 | 182 | LPC_QEI->IEC = 0x1fff; //r. запретить прерывание при изменении направления |
Kovalev_D | 87:7e575d26d6d0 | 183 | |
Kovalev_D | 98:95b8e79f13e1 | 184 | /*NVIC_SetPriority(QEI_IRQn, 0); |
Kovalev_D | 98:95b8e79f13e1 | 185 | NVIC_EnableIRQ(QEI_IRQn);*/ |
Kovalev_D | 88:b5c1d9d338d1 | 186 | ////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 187 | ////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 188 | |
Kovalev_D | 88:b5c1d9d338d1 | 189 | |
Kovalev_D | 89:a0d344db227e | 190 | ////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 191 | ///////////////////////I2C//////////////////////////// |
Kovalev_D | 89:a0d344db227e | 192 | ////////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 193 | |
Kovalev_D | 89:a0d344db227e | 194 | LPC_SC->PCONP |= (1 << 19);//включение интерфейса I2C. |
Kovalev_D | 88:b5c1d9d338d1 | 195 | |
Kovalev_D | 89:a0d344db227e | 196 | /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */ |
Kovalev_D | 89:a0d344db227e | 197 | /* function to 01 on both SDA and SCK. */ |
Kovalev_D | 89:a0d344db227e | 198 | LPC_PINCON->PINSEL1 &= ~0x03C00000; //P0.27 - SDA. |
Kovalev_D | 89:a0d344db227e | 199 | LPC_PINCON->PINSEL1 |= 0x01400000; //P0.28 - SCK. |
Kovalev_D | 86:398da56ef751 | 200 | |
Kovalev_D | 89:a0d344db227e | 201 | // подтверждение Флаг флаг разрешения |
Kovalev_D | 89:a0d344db227e | 202 | /*сброс флагоф флага прерывания I2C старта интерфейса I2C */ |
Kovalev_D | 89:a0d344db227e | 203 | LPC_I2C0->CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC; // установка микроконтроллера в режим мастера |
Kovalev_D | 86:398da56ef751 | 204 | |
Kovalev_D | 89:a0d344db227e | 205 | /*--- Reset registers ---*/ |
Kovalev_D | 89:a0d344db227e | 206 | LPC_I2C0->SCLL = I2SCLL_SCLL; // - счетчик scl low time period |
Kovalev_D | 89:a0d344db227e | 207 | LPC_I2C0->SCLH = I2SCLH_SCLH; // - счетчик scl high time period |
Kovalev_D | 99:3d8f206ceac2 | 208 | |
Kovalev_D | 99:3d8f206ceac2 | 209 | I2CMasterBuffer[0] = A_ADDRESS; |
Kovalev_D | 99:3d8f206ceac2 | 210 | I2CMasterBuffer[1] = WRITE_CMD; |
Kovalev_D | 99:3d8f206ceac2 | 211 | I2CMasterBuffer[3] = B_ADDRESS; |
Kovalev_D | 99:3d8f206ceac2 | 212 | I2CMasterBuffer[4] = WRITE_CMD; |
Kovalev_D | 99:3d8f206ceac2 | 213 | |
Kovalev_D | 89:a0d344db227e | 214 | LPC_I2C0->CONSET = I2CONSET_I2EN; //включение интерфейса I2C. |
Kovalev_D | 89:a0d344db227e | 215 | ////////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 216 | ////////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 217 | |
Kovalev_D | 86:398da56ef751 | 218 | |
Kovalev_D | 86:398da56ef751 | 219 | |
Kovalev_D | 92:c892f0311aa7 | 220 | |
Kovalev_D | 92:c892f0311aa7 | 221 | |
Kovalev_D | 92:c892f0311aa7 | 222 | |
Kovalev_D | 92:c892f0311aa7 | 223 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 224 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 225 | //////////////////////////SPI////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 226 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 227 | Dummy = Dummy; |
Kovalev_D | 92:c892f0311aa7 | 228 | |
Kovalev_D | 92:c892f0311aa7 | 229 | /* Enable AHB clock to the SSP0, SSP1 */ |
Kovalev_D | 92:c892f0311aa7 | 230 | LPC_SC->PCONP |= (0x1<<21); // включение SSP0. |
Kovalev_D | 92:c892f0311aa7 | 231 | |
Kovalev_D | 92:c892f0311aa7 | 232 | /* выбор частоты для переферии используем по умолчания с делителем основной на 4 */ |
Kovalev_D | 92:c892f0311aa7 | 233 | LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D | 92:c892f0311aa7 | 234 | LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/ |
Kovalev_D | 92:c892f0311aa7 | 235 | |
Kovalev_D | 92:c892f0311aa7 | 236 | // P0.15~0.18 as SSP0 |
Kovalev_D | 92:c892f0311aa7 | 237 | LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //установит Р 0.15 |
Kovalev_D | 92:c892f0311aa7 | 238 | LPC_PINCON->PINSEL0 |= (0x2UL<<30); //частота для синхронизациии Master - slave |
Kovalev_D | 92:c892f0311aa7 | 239 | |
Kovalev_D | 92:c892f0311aa7 | 240 | LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // устанивоить Р 0.17 и Р 0.18 |
Kovalev_D | 92:c892f0311aa7 | 241 | LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // как MISO0 и MOSI0 |
Kovalev_D | 92:c892f0311aa7 | 242 | |
Kovalev_D | 92:c892f0311aa7 | 243 | LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 244 | LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 245 | |
Kovalev_D | 92:c892f0311aa7 | 246 | LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 247 | LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 248 | |
Kovalev_D | 92:c892f0311aa7 | 249 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-установление DSS(Data sise select) в 16-битный формат, (3<<8 scr - выбор частоты), |
Kovalev_D | 92:c892f0311aa7 | 250 | // низкий уровень линии тактирования между кадрами, прикрепление передачи к первому нарастанию тактового мигнала |
Kovalev_D | 92:c892f0311aa7 | 251 | // формат кадра TI. |
Kovalev_D | 92:c892f0311aa7 | 252 | |
Kovalev_D | 92:c892f0311aa7 | 253 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
Kovalev_D | 92:c892f0311aa7 | 254 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
Kovalev_D | 92:c892f0311aa7 | 255 | |
Kovalev_D | 92:c892f0311aa7 | 256 | /*SSP enable, master mode */ |
Kovalev_D | 92:c892f0311aa7 | 257 | LPC_SSP0->CR1 = SSPCR1_SSE; |
Kovalev_D | 92:c892f0311aa7 | 258 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
Kovalev_D | 92:c892f0311aa7 | 259 | while (LPC_SSP0->SR & SSP_BUSY); |
Kovalev_D | 92:c892f0311aa7 | 260 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
Kovalev_D | 92:c892f0311aa7 | 261 | Dummy = LPC_SSP0->DR; |
Kovalev_D | 92:c892f0311aa7 | 262 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
Kovalev_D | 92:c892f0311aa7 | 263 | LPC_GPIO0->FIODIR |= (1<<16); // P0.16 defined as CS for ADC |
Kovalev_D | 92:c892f0311aa7 | 264 | LPC_GPIO0->FIOSET |= (1<<16); // set CS for ADC |
Kovalev_D | 92:c892f0311aa7 | 265 | |
Kovalev_D | 92:c892f0311aa7 | 266 | LPC_GPIO0->FIODIR |= (1<<23); // P defined as CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 267 | LPC_GPIO0->FIOCLR |= (1<<23); // set CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 268 | while (LPC_SSP1->SR & RX_SSP_notEMPT) |
Kovalev_D | 92:c892f0311aa7 | 269 | Dummy = LPC_SSP1->DR; /* clear the RxFIFO */ |
Kovalev_D | 92:c892f0311aa7 | 270 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 271 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 272 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 273 | |
Kovalev_D | 92:c892f0311aa7 | 274 | |
Kovalev_D | 92:c892f0311aa7 | 275 | |
Kovalev_D | 92:c892f0311aa7 | 276 | |
Kovalev_D | 86:398da56ef751 | 277 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 278 | /////////////////инициализация ног/////////////////// |
Kovalev_D | 86:398da56ef751 | 279 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 280 | |
Kovalev_D | 89:a0d344db227e | 281 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 282 | Gyro.PinRegOld = 0xffffffff; |
Kovalev_D | 88:b5c1d9d338d1 | 283 | Gyro.PinReg = 0; // всЁ выключенно |
Kovalev_D | 88:b5c1d9d338d1 | 284 | PinCheng(); |
Kovalev_D | 89:a0d344db227e | 285 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 286 | |
Kovalev_D | 87:7e575d26d6d0 | 287 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 288 | //////////////отладочный светодиод/////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 289 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 290 | |
Kovalev_D | 98:95b8e79f13e1 | 291 | LPC_PINCON->PINSEL0 &= ~(0x00<<28); |
Kovalev_D | 98:95b8e79f13e1 | 292 | LPC_PINCON->PINSEL0 |= (0x00<<28); // а нужно, ведь по умолчаниб у них 0 функция. попробоввать без них потом убрать |
Kovalev_D | 98:95b8e79f13e1 | 293 | LPC_PINCON->PINMODE0 |= (0x3<<28); |
Kovalev_D | 87:7e575d26d6d0 | 294 | LPC_GPIO1->FIODIR |= (1<<30); |
Kovalev_D | 87:7e575d26d6d0 | 295 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 296 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 297 | |
Kovalev_D | 88:b5c1d9d338d1 | 298 | |
Kovalev_D | 87:7e575d26d6d0 | 299 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 300 | ////////////////управление уартом//////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 301 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 302 | LPC_GPIO2->FIODIR |= (1<<7);//направление ноги uart enable |
Kovalev_D | 87:7e575d26d6d0 | 303 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 304 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 305 | |
Kovalev_D | 88:b5c1d9d338d1 | 306 | |
Kovalev_D | 88:b5c1d9d338d1 | 307 | |
Kovalev_D | 87:7e575d26d6d0 | 308 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 309 | ///////////////////////поджиг//////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 310 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 311 | LPC_PINCON->PINSEL0 &= ~(3<<8); //e. P0.4 is GPIO pin (запись ( 00 ) в 9:8 бит PISEL0 выбор P0.4 как GPIO) |
Kovalev_D | 98:95b8e79f13e1 | 312 | LPC_PINCON->PINMODE0 |= (3<<8); //e. P0.4 is GPIO pin (запись ( 11 ) в 9:8 бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 313 | LPC_GPIO0->FIODIR |= (1<<4); //e. P0.4 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.4 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 314 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 315 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 316 | |
Kovalev_D | 88:b5c1d9d338d1 | 317 | |
Kovalev_D | 88:b5c1d9d338d1 | 318 | |
Kovalev_D | 87:7e575d26d6d0 | 319 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 320 | /////////////////////вибро 1///////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 321 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 322 | LPC_PINCON->PINSEL3 &= ~(0x00<<18); //e. P1.25 is GPIO pin |
Kovalev_D | 98:95b8e79f13e1 | 323 | LPC_PINCON->PINSEL3 |= (0x00<<18); //e. P1.25 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 324 | LPC_PINCON->PINMODE3 |= (3<<18); //e. P1.25 (включениe подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 325 | LPC_GPIO1->FIODIR |= (1<<25); //e. P0.5 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 326 | LPC_GPIO1->FIOCLR |= (1<<25); |
Kovalev_D | 88:b5c1d9d338d1 | 327 | ////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 328 | //////////////////////вибро 2///////////////////////// |
Kovalev_D | 89:a0d344db227e | 329 | ////////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 330 | LPC_PINCON->PINSEL3 &= ~(0x00<<24); //e. P1.28 is GPIO pin |
Kovalev_D | 98:95b8e79f13e1 | 331 | LPC_PINCON->PINSEL3 |= (0x00<<24); //e. P1.28 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 332 | LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (запись ( 11 ) в бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 333 | LPC_GPIO1->FIODIR |= (1<<28); //e. P1.28 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 334 | LPC_GPIO1->FIOCLR |= (1<<28); |
Kovalev_D | 87:7e575d26d6d0 | 335 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 336 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 337 | |
Kovalev_D | 88:b5c1d9d338d1 | 338 | |
Kovalev_D | 88:b5c1d9d338d1 | 339 | |
Kovalev_D | 87:7e575d26d6d0 | 340 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 341 | /////////////инициализация подсветки///////////////// |
Kovalev_D | 87:7e575d26d6d0 | 342 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 343 | LPC_PINCON->PINSEL2 &= ~(0x00<<24); |
Kovalev_D | 98:95b8e79f13e1 | 344 | LPC_PINCON->PINSEL2 |= (0x00<<24); //e. P2.12 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 345 | LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (запись ( 11 ) в бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 346 | LPC_GPIO2->FIODIR |= (1<<12); //e. P1.28 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 347 | LPC_GPIO2->FIOCLR |= (1<<12); |
Kovalev_D | 88:b5c1d9d338d1 | 348 | /////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 349 | /////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 350 | |
Kovalev_D | 88:b5c1d9d338d1 | 351 | |
Kovalev_D | 88:b5c1d9d338d1 | 352 | /////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 353 | /////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 354 | ///////////////////включение таймеров////////////////// |
Kovalev_D | 89:a0d344db227e | 355 | /////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 356 | enable_timer1(); |
Kovalev_D | 86:398da56ef751 | 357 | enable_timer2(); |
Kovalev_D | 89:a0d344db227e | 358 | /////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 359 | |
Kovalev_D | 89:a0d344db227e | 360 | ////////////////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 361 | // LPC_GPIO0->FIOCLR = (1<<5);/////////////отключение поджига |
Kovalev_D | 90:d9b6a4bc5065 | 362 | |
Kovalev_D | 90:d9b6a4bc5065 | 363 | |
Kovalev_D | 90:d9b6a4bc5065 | 364 | |
Kovalev_D | 90:d9b6a4bc5065 | 365 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 366 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 367 | //////////////////////////SPI////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 368 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 369 | Dummy = Dummy; |
Kovalev_D | 90:d9b6a4bc5065 | 370 | |
Kovalev_D | 90:d9b6a4bc5065 | 371 | /* Enable AHB clock to the SSP0, SSP1 */ |
Kovalev_D | 90:d9b6a4bc5065 | 372 | LPC_SC->PCONP |= (0x1<<21); // включение SSP0. |
Kovalev_D | 90:d9b6a4bc5065 | 373 | |
Kovalev_D | 90:d9b6a4bc5065 | 374 | /* выбор частоты для переферии используем по умолчания с делителем основной на 4 */ |
Kovalev_D | 90:d9b6a4bc5065 | 375 | LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D | 90:d9b6a4bc5065 | 376 | LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/ |
Kovalev_D | 90:d9b6a4bc5065 | 377 | |
Kovalev_D | 90:d9b6a4bc5065 | 378 | // P0.15~0.18 as SSP0 |
Kovalev_D | 90:d9b6a4bc5065 | 379 | LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //установит Р 0.15 |
Kovalev_D | 90:d9b6a4bc5065 | 380 | LPC_PINCON->PINSEL0 |= (0x2UL<<30); //частота для синхронизациии Master - slave |
Kovalev_D | 90:d9b6a4bc5065 | 381 | |
Kovalev_D | 90:d9b6a4bc5065 | 382 | LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // устанивоить Р 0.17 и Р 0.18 |
Kovalev_D | 90:d9b6a4bc5065 | 383 | LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // как MISO0 и MOSI0 |
Kovalev_D | 90:d9b6a4bc5065 | 384 | |
Kovalev_D | 90:d9b6a4bc5065 | 385 | LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 386 | LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 387 | |
Kovalev_D | 90:d9b6a4bc5065 | 388 | LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 389 | LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 390 | |
Kovalev_D | 90:d9b6a4bc5065 | 391 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-установление DSS(Data sise select) в 16-битный формат, (3<<8 scr - выбор частоты), |
Kovalev_D | 90:d9b6a4bc5065 | 392 | // низкий уровень линии тактирования между кадрами, прикрепление передачи к первому нарастанию тактового мигнала |
Kovalev_D | 90:d9b6a4bc5065 | 393 | // формат кадра TI. |
Kovalev_D | 90:d9b6a4bc5065 | 394 | |
Kovalev_D | 90:d9b6a4bc5065 | 395 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
Kovalev_D | 90:d9b6a4bc5065 | 396 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
Kovalev_D | 90:d9b6a4bc5065 | 397 | |
Kovalev_D | 90:d9b6a4bc5065 | 398 | /*SSP enable, master mode */ |
Kovalev_D | 90:d9b6a4bc5065 | 399 | LPC_SSP0->CR1 = SSPCR1_SSE; |
Kovalev_D | 90:d9b6a4bc5065 | 400 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
Kovalev_D | 90:d9b6a4bc5065 | 401 | while (LPC_SSP0->SR & SSP_BUSY); |
Kovalev_D | 90:d9b6a4bc5065 | 402 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
Kovalev_D | 90:d9b6a4bc5065 | 403 | Dummy = LPC_SSP0->DR; |
Kovalev_D | 90:d9b6a4bc5065 | 404 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
Kovalev_D | 90:d9b6a4bc5065 | 405 | LPC_GPIO0->FIODIR |= (1<<16); // P0.16 defined as CS for ADC |
Kovalev_D | 90:d9b6a4bc5065 | 406 | LPC_GPIO0->FIOSET |= (1<<16); // set CS for ADC |
Kovalev_D | 90:d9b6a4bc5065 | 407 | |
Kovalev_D | 92:c892f0311aa7 | 408 | LPC_GPIO0->FIODIR |= (1<<23); // P defined as CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 409 | LPC_GPIO0->FIOCLR |= (1<<23); // set CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 410 | while (LPC_SSP1->SR & RX_SSP_notEMPT) |
Kovalev_D | 92:c892f0311aa7 | 411 | Dummy = LPC_SSP1->DR; /* clear the RxFIFO */ |
Kovalev_D | 90:d9b6a4bc5065 | 412 | |
Kovalev_D | 86:398da56ef751 | 413 | } |
igor_v | 13:e2a1d18677b8 | 414 | |
igor_v | 0:8ad47e2b6f00 | 415 | |
igor_v | 0:8ad47e2b6f00 | 416 | |
igor_v | 0:8ad47e2b6f00 | 417 | |
igor_v | 0:8ad47e2b6f00 | 418 |