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