![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/main.c
- Committer:
- Kovalev_D
- Date:
- 2016-02-03
- Revision:
- 23:12e6183f04d4
File content as of revision 23:12e6183f04d4:
/****************************************Copyright (c)**************************************************** **--------------File Info--------------------------------------------------------------------------------- ** File name: main.c ** Last modified Date: 2011-10-24 ** Last Version: V1.00 ** Descriptions: The main() function ** **-------------------------------------------------------------------------------------------------------- ** Created by: Electrooptica Incorp. ** Created date: 2011-08-22 ** Version: V1.00 ** Descriptions: **-------------------------------------------------------------------------------------------------------- *********************************************************************************************************/ #include "SIP.h" #include "el_lin.h" #include "CyclesSync.h" #include "Parameters.h" #include "Dither_Reg.h" #include "commandset.h" #include "CntrlGLD.h" #include "InputOutput.h" #include <math.h> #include "stdlib.h" #include "console.h" #include "vibro.h" #include "QEI.h" #include "MTimer.h" #include "Global.h" #include "SPI.h" #include "uart_m.h" #include "command.h" #include "Global.h" ///ÕÅÐÍß /****************************************************************************** ** Main Function main() ******************************************************************************/ extern uint32_t CMD_Mode; ////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// int i1 =0; //extern unsigned int Buff_QEI[256]; volatile unsigned int IRQ_Counter=0; volatile uint32_t timer1_counter = 0; int temp111=0,temp=0; int y = 0; int CuruAngleOld=0; unsigned int LightUpCount,BackLightCount,secPuls,CountBI,CmmandIn,tt,th; unsigned int paramV; void Led_init() { LPC_PINCON->PINSEL0 = (0x00<<28); LPC_GPIO1->FIODIR = (0x1<<30); LPC_PINCON->PINMODE0 = (0x3<<28); // LPC_GPIO1->FIOSET = (0x0<<30); // LPC_GPIO0->FIOSET = (1<<4); } int flag=0, TIME=0,t=0, Sec=0,tmpSec=0,SEC=0, mSec=0; int tempsec=0; float DACF, K_DAC; void Led_Blink() { if (flag == 0) { LPC_GPIO1->FIOSET = (0x1<<30); flag=1; } else { flag =0; LPC_GPIO1->FIOCLR = (0x01<<30); } } long LED_TEMP=0; int main (void) { { K_DAC=65535.0/(65535.0+(deltaDAC+deltaDAC/2)); K_DAC=0.8; Main.Firmware_Version=0x15; Main.GLD_Serial = 0x20; Main.My_Addres=0; LightUpCount=1000; BackLightCount=5000; secPuls=0; Pulse_midl = 0; PulseHalf = 0; CuruAngle = 0; Spi.DAC_A=0x7fff; Spi.DAC_B=0x7fff; //èíèöèàëèçàöèÿ SystemInit(); // Èíèöèàëèçàöèÿ ñèñòåìû Led_init(); ///* //êîíôèãóðèðîâàíèå ñèãíàëà ïîäæèãà LPC_PINCON->PINSEL0 &= ~(3<<8); //e. P0.4 is GPIO pin (çàïèñü ( 00 ) â 9:8 áèò PISEL0 âûáîð P0.4 êàê GPIO) LPC_PINCON->PINMODE0 |= (3<<8); //e. P0.4 is GPIO pin (çàïèñü ( 11 ) â 9:8 áèò PINMODE0 "äëÿ âêëþ÷åíèÿ ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO0->FIODIR |= (1<<4); //e. P0.4 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.4 êàê âûõîä) LightUpON //e. P0.4 is output (çàïèñü ( 1 ) â 5 áèò CLR óñòàíàâëèâàåì íà P0.4 íèçêèé óðîâåíü ñèãíàëà) /* LPC_PINCON->PINSEL0 &= ~(3<<10); //e. P0.4 is GPIO pin (çàïèñü ( 00 ) â 9:8 áèò PISEL0 âûáîð P0.4 êàê GPIO) LPC_PINCON->PINMODE0 |= (3<<10); //e. P0.4 is GPIO pin (çàïèñü ( 11 ) â 9:8 áèò PINMODE0 "äëÿ âêëþ÷åíèÿ ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO0->FIODIR |= (1<<5); //e. P0.4 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.4 êàê âûõîä) LPC_GPIO0->FIOCLR |= (1<<5); //e. P0.4 is output (çàïèñü ( 1 ) â 5 áèò CLR óñòàíàâëèâàåì íà P0.4 íèçêèé óðîâåíü ñèãíàëà)*/ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// LPC_PINCON->PINSEL3 = (0x00<<18); //e. P1.25 is GPIO pin LPC_PINCON->PINMODE3 |= (3<<18); //e. P1.25 (âêëþ÷åíèe ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO1->FIODIR |= (1<<25); //e. P0.5 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.5 êàê âûõîä) LPC_GPIO1->FIOCLR |= (1<<25); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// LPC_PINCON->PINSEL3 = (0x00<<24); //e. P1.28 is GPIO pin LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (çàïèñü ( 11 ) â áèò PINMODE0 "äëÿ âêëþ÷åíèÿ ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO1->FIODIR |= (1<<28); //e. P1.28 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.5 êàê âûõîä) LPC_GPIO1->FIOCLR |= (1<<28); // init_timer(TIME_INTERVAL ); // 10ms // enable_timer1(); ///èÍÈöèàëèçàöèÿ ïîäñâåòêè LPC_PINCON->PINSEL2 = (0x00<<24); //e. P2.12 is GPIO pin LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (çàïèñü ( 11 ) â áèò PINMODE0 "äëÿ âêëþ÷åíèÿ ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO2->FIODIR |= (1<<12); //e. P1.28 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.5 êàê âûõîä) LPC_GPIO2->FIOCLR |= (1<<12); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* //êîíôèãóðèðîâàíèå ñèãíàëà ïîäæèãà îòîðâàíàÿ íîãà (ïîäæèã íà 80 íîãå âìåñòî 81) LPC_PINCON->PINSEL0 = (0x00<<10); //e. P0.5 is GPIO pin (çàïèñü ( 00 ) â 11:10 áèò PISEL0 âûáîð P0.5 êàê GPIO) LPC_PINCON->PINMODE0 |= (3<<10); //e. P0.5 is GPIO pin (çàïèñü ( 11 ) â 11:10 áèò PINMODE0 "äëÿ âêëþ÷åíèÿ ïîäòÿãèâàþùåãî ðåçèñòîðà") LPC_GPIO0->FIODIR |= (1<<5); //e. P0.5 is output (çàïèñü ( 1 ) â 5 áèò FIODIR âûáîð P0.5 êàê âûõîä) LPC_GPIO0->FIOCLR |= (1<<5); //e. P0.5 is output (çàïèñü ( 1 ) â 5 áèò CLR óñòàíàâëèâàåì íà P0.5 íèçêèé óðîâåíü ñèãíàëà) */ DMA_Init(); // Èíèöèàëèçàöèÿ DMA FlashDMA_Init(); // Çàãðóçêà ïàðàìåòðîâ ñ ôëýø SystemCoreClockUpdate(); // ðàñ÷åò ñèñòåìíîé ÷àñòîòû äëÿ UART. UARTInit(); // èíèöèàëèçàöèÿ UART0 íà ñêîðîñòü 38400. UART1_Init(); // èíèöèàëèçàöèÿ UART1 íà ñêîðîñòü 38400. DAC_ADC_Exchange_Init(); // èíèöèàëèçàöèÿ îáìåíà ÀÖÏ è ÖÀÏ. DACInit(); // èíèöèàëèçàöèÿ ÖÀÏ. SOI_Init(); // Èíèöèàëèçàöèÿ êâàäðàòóðíîãî ýíêîäåðà. IntLatch_Init(); // èíèöèàëèçàöèÿ âíóòðåííåé çàùåëêè. ExtLatch_Init(); // èíèöèàëèçàöèÿ âíåøíåé çàùåëêè. //----------------debug------------------------- //LPC_GPIO2->FIODIR = 0x5C; // P2.0...P2.7 defined as Outputs //LPC_GPIO2->FIOCLR = 0x5C; // turn off all the LEDs //----------------debug------------------------- LoadFlashParam(FromFLASH); //çàãðóçêà ïàðàìåòðîâ. UART_DMA_Init(); //èíèöèàëèçàöèÿ DMA äëÿ UART. G_Photo_Init(); //èíèöèàëèçàöèÿ èíòåðôåéñà I2C äëÿ ôîòîäåòåêòîðà. Out_G_photo(60, 60); //çàïèñü â áóôåð ìàñòåðà ïðèíÿòûå îò ôóíêöèè äàííûå (60,60) è óñòàíîâêà ôëàãà ñòàðòà ïåðåäà÷è è çàíÿòîé øèíû. // WDTInit(); open_all_loops(); //#define open_all_loops() RgConA = 0 (Îñíîâíîé ðåãèñòð óïðàâëåíèÿ óñòðîéñòâà (0 - âêëþ÷èòü, 1 - îòêëþ÷èòü)). Output.Str.HF_reg = Device_blk.Str.HF_min; //HFO output voltage = ìàêñèâàëüíîå íàïðÿæåíèå íà ÃÂ×. init_PLC(); //Èíèöèàëèçàöèÿ ÑÐÏ(ðåãóëèðîâêà ïåðèìåòðà) init_Dither_reg(); //èíèöèàëèçàöèÿ âèáðîïðèâîäà RgConB = RATE_VIBRO_1; // äîïîëíèòåëüíûé ðåãèñòð óïðàâëåíèÿ = ðàçíîñòü âèáðîñ÷åò÷èêîâ ïîñëå ôèëüòðà ñêîëüç.ñðåäíåãî(#define RATE_VIBRO_1 0x0001) init_Vibro(); init_timer(TIME_INTERVAL ); // 10ms enable_timer1(); Init_TIM2(); enable_timer2(); close_all_loops(); LPC_GPIO0->FIOCLR = (1<<5); } Pulse_8Point = 0; Pulse_16Point = 0; Pulse_32Point = 0; Temp_AMP=0; Temp_ADC_2=0; Temp_ADC_3=0; Temp_ADC_4=0; Temp_ADC_5=0; for (y = 0; y < 256; y++ ) { Buff_16Point [y] = 0xffff; Buff_8Point [y] = 0xffff; Buff_32Point [y] = 0xffff; Buff_ADC_1 [y] = 0;// àìïë àöï. Buff_ADC_2 [y] = 0; Buff_ADC_3 [y] = 0; Buff_ADC_4 [y] = 0; Buff_ADC_5 [y] = 0; } SendToBuffStr ("\n\r ....... "); OutBufConCount =0; WriteCon("\n\r ...WriteCon1.... "); do //îñíîâíîé öèêë. { if (OutBufConCount) OutBufConCount--; Concol (); // Concol1 (); Read_CMD(); // VibroOut(); if(Time_1kHz>100) { SEC++; if(Rate_Flag==1&&SEC>500) { SEC-=500; CMD_Rate(); } Time_1kHz-=100; if(LightUpCount){LightUpCount--;LightUpON} else { LightUpOFF; } if(BackLightCount){BackLightCount--;BackLightON} else { BackLightOFF; } } ButtonLightUP(); //Device_blk.Str. TakeFromBuff(); //îòêëþ÷åíèå ïîäæèãà. // paramV=TakeParam(1); if (LPC_PWM1->IR & 0x0001) // Åñëè â ðåãèñòðå ïðåðûâàíèé ØÈÌ1 (ðåãèñòð PWM1IR) åñòü âëàã ïðåðûâàíèÿ ñîâïàäåíèÿ ñ÷åò÷èêà ñ ÌÀÒÑÍ (lim0 ?) òî: { /* ResetCS(ADC); //prepare ADC for sampling SetDAC(DAC); LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED SetCS(ADC); //start ADC sampling ResetDAC(DAC); //start DAC prepearing for writing */ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// secPuls++; tmpSec++; mSec++; i1++; if(i1>10000) //if(CountV31>30) { i1=0; /* SendToBuffStr("\n\r"); // if (Buff_ADC_1 [y] > 65535)SendToBuffStr(" 0 "); else SendToBuffStr(" 1 "); sprintf (BuffTemp,"<%05d> <%05d> <%05d> <%05d> <%05d>", Temp_AMP>>5,Temp_ADC_2>>5,Temp_ADC_3>>5,Temp_ADC_4>>5,Temp_ADC_5>>5); // sprintf (BuffTemp,"<%07d> <%07d> <%07d> <%07d> <%07d>", Spi.ADC1,Spi.ADC2,Spi.ADC3,Spi.ADC4,Spi.ADC5); SendToBuffStr(BuffTemp); */ /* WriteConByte (Main.T_Vib&0xff00); WriteConByte (Main.T_Vib&0x00ff); WriteConByte (Main.T_Vib); */ /* for (y = 0; y < 32; y++ ) { WriteCon(BuffTemp); } WriteCon("\n\r"); */ /* Main.T_Vib=((7680000*16/Main.Frq)*4096); th= Main.T_Vib&0xff00; tt= Main.T_Vib&0x00ff; sprintf(BuffTemp,"<%07d >",( (Main.T_Vib&0xff00))); SendToBuffStr(BuffTemp); sprintf(BuffTemp,"<%07d >",( ( Main.T_Vib&0x00ff))); SendToBuffStr(BuffTemp); /* CuruAngleOld=CuruAngle;*/ // Spi.ADC1=Spi.ADC1*0.000061; /* sprintf(BuffTemp,"\n\r<%05d><%05d><%05d><%05d><%05d>",Spi.ADC1,Spi.ADC2,Spi.ADC3,Spi.ADC4,Spi.ADC5); SendToBuffStr(BuffTemp); */ /* sprintf(BuffTemp,"<%d>",(FrecTemp)); SendToBuffStr(BuffTemp); for (y = 0; y < 32; y++ ) { sprintf(BuffTemp," <%07d>", (Buff_16PointD [y]-65535)); SendToBuffStr(BuffTemp); } */ } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED Curr_Cnt_Vib = LPC_QEI->POS; // çàïèñàòü â ïåðåìåííóþ Curr_Cnt_Vib òåêóùåå ïîëîæåíèå Ýíêîäåðà. (òåêóùåå êîëè÷åñòâî èìïóëüñîâ) Latch_Event(); //îïðåäåëåíèå çàùåëêè clc_Pulses(); // ñ÷åò÷èê èìïóëüñîâ. RATE_REPER_OR_REFMEANDR èëè RATE_VIBRO_1 //ADC_Input(); // ïðîâåðêà ôëàãîâ çàïîëíåíèÿ áóôåðà è ÷åòåíèå Thermo1, Thermo2, HF_out â ìàñèâ Input.ArrayIn[n]. //DAC_ADC_Exchange();// ïðîâåðêà ôëàãîâ çàïîëíåíèÿ áóôåðà è çïèñü â ÖÀÏû. ServiceTime();//ñåêóíäíûé òàéìåð. clc_ThermoSensors();//ðàñ÷åò ñðåäíåé òåìïåðàòóðû çà ñåêóíäó clc_HFO(); //ðàñ÷åò çíà÷åíèÿ äëÿ ïåðåäà÷è â êîíòóð ÃÂ×(íà öàï). clc_PLC(); // clc_Dith_regulator(); clc_OutFreq_regulator(); Output.Str.WP_sin = clc_WP_sin(); contrl_GLD(); G_Photo_Exchange(); // Output.Str.T_Vibro = paramV*48; Line_1_Rcv(); decode_CMD(); transm_DAT(); // data_Rdy &= ~RESET_PERIOD; LPC_PWM1->IR = 0x0001; //e. clear interrupt flag LPC_GPIO2->FIOCLR |= 0x0000004; // turn off the LED // WDTFeed(); //SPI_Exchange(); } } while ( 1 ); // main infinie loop } /****************************************************************************** ** End Of File ******************************************************************************/