#include #include "lpc17xx_gpio.h" #include "lpc17xx_adc.h" #include "lpc17xx_pinsel.h" #include "lpc17xx_uart.h" #include "hardware.h" #include "Delay_RIT.h" #define N 4 #define M 10 #define I 2 uint16_t volatile data[N]; uint32_t volatile Index=0; uint32_t volatile Index2=0; uint16_t volatile Power=0; uint16_t volatile dataPower[M]; void UART_IntReceive(void) { // //// data[Index]=UART_ReceiveByte(LPC_UART3); //// Index++; dataPower[Index2]=UART_ReceiveByte((LPC_UART_TypeDef *)LPC_UART1); Index2++; //// // UART_SendByte(LPC_UART3,Power); if (Index2>=M) { Index2=0; } // // // //UART_SendByte(LPC_UART3,data); // } void UART_IntReceive3(void) { data[Index]=UART_ReceiveByte(LPC_UART3); Index++; if (Index>=N) { Index=0; } } int main() { uint8_t buffStr[50]; uint16_t Energy=0; uint8_t EnIndex=0; uint8_t led=0; GPIO_SetDir(2,(1<<4),1); GPIO_SetDir(2,(1<<5),1); GPIO_SetDir(2,(1<<6),1); GPIO_SetDir(2,(1<<7),1); HW_Init(); while(1) { uint16_t data4=(data[0]-'0')*10+(data[1]-'0'); uint16_t powerdata= (dataPower[1]-'0')*100+(dataPower[2]-'0')*10+(dataPower[3]-'0'); uint16_t EnergyArr [I]; EnergyArr [EnIndex]=powerdata; EnIndex++; if (EnIndex>=I) { EnIndex=0; Energy=(EnergyArr[0]+EnergyArr[1])/2; } if(data[0]!=0&&(Index==1||Index==3)) { data4=0; Index=0; data[0]=0; data[1]=0; } if(data[0]==NULL&&data[1]==NULL) data4=0; uint16_t temp1=HW_ADC_Read(0); uint16_t temp2=HW_ADC_Read(1); uint16_t temp3=HW_ADC_Read(2); uint16_t temp4=HW_ADC_Read(3); // uint16_t temp5=HW_ADC_Read(4); // uint16_t temp6=HW_ADC_Read(5); // uint16_t temp7=HW_ADC_Read(6); // uint16_t temp8=HW_ADC_Read(7); // uint16_t mid = (temp1+temp2)/2; // UART_Receive((LPC_UART_TypeDef *)LPC_UART1,power, 5,BLOCKING); // if ( power[0]=='D' && power[4]=='W') // { // // uint16_t Power= power[1]; // UART_SendByte(LPC_UART3, Power); // } //uint8_t len=sprintf((char*)buffStr,"%f\n %f\n %d\n",temp1,temp2,Energy); // uint8_t len=sprintf((char*)buffStr,"%u\n %u\n %u\n %u\n ",temp1, temp2,Energy,led); UART_Send(LPC_UART3,buffStr,len, BLOCKING); // if(mid>(data4*10+2)) { GPIO_ClearValue(2,(1<<5)) ; led=0; } else if ( mid<=(data4*10-2)) { GPIO_SetValue(2,(1<<5)); led=1; } Delay_RIT_ms(500 ); } }