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