//*******************final user main DEMONTRATE THIS TO TA********** int main(void){ OS_Init(); // initialize, disable interrupts PortE_Init(); DataLost = 0; // lost data between producer and consumer NumSamples = 0; MaxJitter = 0; // in 1us units //********initialize communication channels OS_MailBox_Init(); OS_Fifo_Init(128); // ***note*** 4 is not big enough***** ST7735_InitR(INITR_REDTAB); // initialize LCD UART_Init(); // initialize UART //*******attach background tasks*********** OS_AddSW1Task(&SW1Push,2); // OS_AddSW2Task(&SW2Push,2); // add this line in Lab 3 ADC_Init(4); // sequencer 3, channel 4, PD3, sampling in DAS() OS_AddPeriodicThread(&DAS,PERIOD,1); // 2 kHz real time sampling of PD3 NumCreated = 0 ; // create initial foreground threads NumCreated += OS_AddThread(&Interpreter,128,2); NumCreated += OS_AddThread(&Consumer,128,1); NumCreated += OS_AddThread(&PID,128,3); // Lab 3, make this lowest priority OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here return 0; // this never executes }
int main(void){uint32_t i; PLL_Init(Bus80MHz); PortF_Init(); ST7735_InitR(INITR_REDTAB); while(1){ ST7735_FillScreen(0); // set screen to black ST7735_SetCursor(0,0); printf("Lab 1\rST7735_sDecOut3\r"); for(i=0; i<13; i++){ ST7735_sDecOut3(outTests1[i].InNumber); // your solution ST7735_OutString((char*)outTests1[i].OutBuffer); // expected solution } //Pause(); ST7735_FillScreen(0); // set screen to black ST7735_SetCursor(0,0); printf("ST7735_uBinOut8\r"); for(i=0; i<14; i++){ ST7735_uBinOut8(outTests2[i].InNumber); // your solution ST7735_OutString((char*)outTests2[i].OutBuffer); // expected solution } //Pause(); ST7735_XYplotInit("Circle",-2500, 2500, -2500, 2500); ST7735_XYplot(180,(int32_t *)CircleXbuf,(int32_t *)CircleYbuf); //Pause(); ST7735_XYplotInit("Star- upper right",-450, 150, -400, 200); ST7735_XYplot(50,(int32_t *)StarXbuf,(int32_t *)StarYbuf); Pause(); } }
int main1(void){ PLL_Init(); ST7735_InitR(INITR_REDTAB); while(1){ plotImage(); } }
int main(void){ //Initialize all below: TExaS_Init(); // Bus clock is 80 MHz ADC_Init(); // initialize to sample ADC1 ST7735_InitR(INITR_REDTAB); SysTick_Init(); UART_Init(); FiFo_Init(); PortF_Init(); EnableInterrupts(); while(1){ while(ADCStatus == 0){}; //Poll ADCStatus flag ADCStatus = 0; //clear flag //Prints from a full FIFO --> BUT must know when //we get to the end --> uses while loop to check this condition, //and a for loop to print 5 times ST7735_SetCursor(6,5); //Infinite loop if the fifo is empty / if returns fail while (FiFo_Get(&data) == 0) {}; FiFo_Get(&data); for(int i = 1; i <= 5; i++){ ST7735_OutChar(data); FiFo_Get(&data); } FiFo_Get(&data); FiFo_Get(&data); ST7735_SetCursor(12,5); ST7735_OutString(" cm"); // print " cm" } }
//----------------------------------------------------------------------- int DisplayInit (void) { int err = 0; //Set the names of the months for when editing the date strcpy(months[0], "JAN"); strcpy(months[1], "FEB"); strcpy(months[2], "MAR"); strcpy(months[3], "APR"); strcpy(months[4], "MAY"); strcpy(months[5], "JUN"); strcpy(months[6], "JUL"); strcpy(months[7], "AUG"); strcpy(months[8], "SEP"); strcpy(months[9], "OCT"); strcpy(months[10], "NOV"); strcpy(months[11], "DEC"); //reset variables used fro editing memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); //initialize the screen Clock_Init48MHz(); // set system clock to 48 MHz ST7735_InitR(INITR_GREENTAB); return err; }
int main(void){ DisableInterrupts(); PLL_Init(Bus80MHz); // bus clock at 80 MHz UART_Init(); ST7735_InitR(INITR_REDTAB); ADC0_InitTimerTriggerSeq3_Ch0(); EnableInterrupts(); /* UART_OutString("Points: \r\n"); while(currentIndex < 100); for(int i = 0; i < 100; i += 1) { UART_OutUDec(data[i]); UART_OutString("\r\n"); } */ while(1) { ST7735_SetCursor(0, 0); int32_t currentTemperature = Temperature_Convert(ADC_FIFO_CurrentValue()); printf("Temperature %5d.%02d\n", currentTemperature / 100, currentTemperature % 100); ST7735_PlotClear(32, 159); //TODO change color? for(int i = 0; i < FIFO_SIZE; i += 1) { int32_t point = 128 - Temperature_Convert(ADC_FIFO_Get()[i]) * 2 / 100; ST7735_DrawPixel(i+1, point+1, ST7735_RED); ST7735_DrawPixel(i+1, point, ST7735_RED); ST7735_DrawPixel(i, point+1, ST7735_RED); ST7735_DrawPixel(i, point, ST7735_RED); } WaitForInterrupt(); } }
int main(void){ TExaS_Init(); // Bus clock is 80 MHz ST7735_InitR(INITR_REDTAB); PortF_Init(); ADC_Init(); // turn on ADC, set channel to 1 SysTick_Init(); //Initialize SysTick for(;;){ while(ADCStatus == 0){} //Poll ADCStatus flag uint32_t x = ADCMail; //read ADCMail (input) ADCStatus = 0; //clear flag x = Convert(x); //convert the input ST7735_SetCursor(1,7); ST7735_OutString("D = "); //print "D = " ST7735_SetCursor(5,7); LCD_OutFix(x); // print the fixed point value ST7735_SetCursor(10,7); ST7735_OutString(" cm"); // print " cm" ///////////////////// ST7735_SetCursor(1,2); ST7735_OutString("Lab 8:"); ST7735_SetCursor(1,3); ST7735_OutString("Measurment of"); ST7735_SetCursor(1,4); ST7735_OutString("Distance :)"); } }
int main1(void){ TExaS_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); PortF_Init(); SysTick_Init(); // This makes things work UART1_Init(); while(1){} // do-nothing loop }
/**************ST7735_XYplotInit*************** Specify the X and Y axes for an x-y scatter plot Draw the title and clear the plot area Inputs: title ASCII string to label the plot, null-termination minX smallest X data value allowed, resolution= 0.001 maxX largest X data value allowed, resolution= 0.001 minY smallest Y data value allowed, resolution= 0.001 maxY largest Y data value allowed, resolution= 0.001 Outputs: none assumes minX < maxX, and miny < maxY */ void ST7735_XYplotInit(char *title, int32_t minX, int32_t maxX, int32_t minY, int32_t maxY) { ST7735_InitR(INITR_GREENTAB); ST7735_PlotClear(minY, maxY); //ST7735_DrawString(0, 0, title, ST7735_YELLOW); printf("%s", title); MinXplot=minX; MinYplot=minY+MinYplot; MaxXplot=maxX; MaxYplot=maxY+MinYplot; }
// "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.3 int main3(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr, LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 16 ST7735_InitR(INITR_REDTAB); // Initialize 17 ST7735_OutString("Internet of Things\n"); // 18 ST7735_OutString("Embedded Systems\n"); // 19 ST7735_OutString("Vol. 2, Valvano"); // 20 ST7735_PlotClear(0,4095); // range from 0 to 4095 21 sl_Start(0, 0, 0); // Initializing the CC3100 device 22 WlanConnect(); // connect to AP 23 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 24 (unsigned char *)&ipV4); // 25 LocalAddr.sin_family = SL_AF_INET; // 26 LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); // 27 LocalAddr.sin_addr.s_addr = 0; // 28 AddrSize = sizeof(SlSockAddrIn_t); // 29 while(1){ SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 31 Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, // 32 AddrSize); // 33 Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, // 34 (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );// 35 if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ // 36 int i,bOk; uint32_t place; // 37 data = 0; bOk = 1; // 38 i=4; // ignore possible negative sign 39 for(place = 1000; place; place = place/10){ // 40 if((uBuf[i]&0xF0)==0x30){ // ignore spaces 41 data += place*(uBuf[i]-0x30); // 42 }else{ // 43 if((uBuf[i]&0xF0)!= ' '){ // 44 bOk = 0; // 45 } // 46 } // 47 i++; // 48 } // 49 if(bOk){ // 50 ST7735_PlotLine(data); // 51 ST7735_PlotNextErase(); // 51 } } } }
int main(void) { DisableInterrupts(); PLL_Init(Bus80MHz); // bus clock at 50 MHz Tach_Init(); // initialize the Tach measureing input capture PWM0B_Init(40000, 30000); // 1000 Hz Buttons_Init(); ST7735_InitR(INITR_REDTAB); SysTick_Init(); EnableInterrupts(); int32_t x = 0; ST7735_SetCursor(0,0); printf("Speed:\nTarget:"); while(1) { ST7735_SetCursor(8, 0); int32_t speed = Tach_GetSpeed(); int32_t speedY = ST7735_TFTHEIGHT - 20 - speed / 4; printf("%5d.%01d rps", speed / 10, speed % 10); ST7735_SetCursor(8, 1); printf("%5d.%01d rps", Target_Speed / 10, Target_Speed % 10); if(x == 0) ST7735_PlotClear(32, 159); /* Speed = 200000000/Period; // 0.1 rps if(PID_delay == 0){ E = Target_Speed-Speed; // 0.1 rps U += (40*E)/64; // discrete integral if(U < 100) U=100; // Constrain output if(U>39900) U=39900; // 100 to 39900 PWM0B_Duty(U); // output PID_delay = 4; } else { PID_delay -= 1; }*/ while(! SysTick_ShouldDraw()); ST7735_DrawPixel(x+1, speedY+1, ST7735_RED); ST7735_DrawPixel(x+1, speedY, ST7735_RED); ST7735_DrawPixel(x, speedY+1, ST7735_RED); ST7735_DrawPixel(x, speedY, ST7735_RED); x = (x + 1) % ST7735_TFTWIDTH; WaitForInterrupt(); } }
int main2(void){ TExaS_Init(); // Bus clock is 80 MHz ADC_Init(); // turn on ADC, set channel to 1 PortF_Init(); ST7735_InitR(INITR_REDTAB); while(1){ // use scope to measure execution time for ADC_In and LCD_OutDec PF2 = 0x04; // Profile ADC Data = ADC_In(); // sample 12-bit channel 1 PF2 = 0x00; // end of ADC Profile ST7735_SetCursor(0,0); PF1 = 0x02; // Profile LCD LCD_OutDec(Data); ST7735_OutString(" "); // these spaces are used to coverup characters from last output PF1 = 0; // end of LCD Profile } }
int main(void){ PLL_Init(Bus80MHz); // 80 MHz UART_Init(); // initialize UART device //initialize ADC, hardware timer trigger, 100Hz sampling ADC0_InitTimer0ATriggerSeq3PD3(f100HZ); TxFifo_Init(); // initialize FIFO ST7735_InitR(INITR_REDTAB); // initialize LCD ST7735_InitTemperatureGraph(); // initialize graph area EnableInterrupts(); while(1){ TxFifo_Get(&adcValue); // get most recent ADC value from FIFO ST7735_UpdateTemperatureGraph(numSamples, adcValue); // plot new point and display ADC and temperature values numSamples++; // counts the number of samples } }
int main(void){ TExaS_Init(); ST7735_InitR(INITR_REDTAB); PortF_Init(); ADC_Init(); // turn on ADC, set channel to 1 SysTick_Init(); // This makes things work // your Lab 8 while(1){ while(ADCStatus == 0){} Data = ADCMail; Position = Convert(Data); ST7735_SetCursor(0,0); LCD_OutDec(Data); ST7735_OutString(" "); ST7735_SetCursor(6,0); LCD_OutFix(Position); ADCStatus = 0; } }
int main3(void){ TExaS_Init(); // Bus clock is 80 MHz PortF_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); while(1){ PF2 ^= 0x04; // Heartbeat Data = ADC_In(); // sample 12-bit channel 1 PF3 = 0x08; // Profile Convert Position = Convert(Data); PF3 = 0; // end of Convert Profile PF1 = 0x02; // Profile LCD ST7735_SetCursor(0,0); LCD_OutDec(Data); ST7735_OutString(" "); ST7735_SetCursor(6,0); LCD_OutFix(Position); PF1 = 0; // end of LCD Profile } }
int main(void){ // possible main program that tests your functions PLL_Init(); ST7735_InitR(INITR_REDTAB); uint32_t uDecOut2[8] = { 0, 12, 345, 678, 910, 99999, 100000, 1000000 }; for(int i=0; i<8; i++) { printf("%d gives:\n", uDecOut2[i]); Fixed_uDecOut2(uDecOut2[i]); } /* for(int i=0; i<110000; i=i+902) { printf("%d gives: ", i); Fixed_uDecOut2(i); } for(int i=-11000; i<11000; i=i+71) { printf("%d gives: ", i); Fixed_sDecOut3s(i); } for(int i=0x00000000; i<257000; i=i+0xA21) { printf("Binary %d gives \n", i); int decimal_int = ((i * 100 + 128) / 256); printf("decimal %d, which\n", decimal_int); printf("gives: "); Fixed_uBinOut8(i); printf("\n"); } */ }
int main(void){ TExaS_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); PortF_Init(); SysTick_Init(); // This makes things work UART1_Init(); FIFO_Init(); unsigned char data; while(1){ while(data != 0x02){ FIFO_Get(&data); // Look for new data byte } ST7735_SetCursor(0,0); for(int i = 0; i<5; i++){ // Print next 5 elements FIFO_Get(&data); ST7735_OutChar(data); } ST7735_OutString(" cm"); // Print units } }
int main(void){ uint32_t DataTaken; uint32_t ConvData; TExaS_Init(); // Bus clock is 80 MHz PortF_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); SysTick_Init(); while(1){ if (ADCStatus == 1){ DataTaken = ADCMail; ADCStatus = 0; ConvData = Convert(DataTaken); ST7735_SetCursor(0,0); LCD_OutDec(DataTaken); ST7735_OutString(" "); ST7735_SetCursor(6,0); LCD_OutFix(ConvData); ST7735_OutString(" cm"); } } }
int main(void){ PLL_Init(Bus80MHz); // 80 MHz SYSCTL_RCGCGPIO_R |= 0x20; // activate port F //ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating GPIO_PORTF_DIR_R |= 0x06; // make PF2, PF1 out (built-in LED) GPIO_PORTF_AFSEL_R &= ~0x06; // disable alt funct on PF2, PF1 GPIO_PORTF_DEN_R |= 0x06; // enable digital I/O on PF2, PF1 // configure PF2 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF PF2 = 0; // turn off LED DisableInterrupts(); Timer0A_Init60HzInt(); //updates time every second Timer1_Init(); //sound Timer2_Init(); //Switch_Init(); //interrupts on switch press ST7735_InitR(INITR_REDTAB); ST7735_PlotClear(0,160); play = 0; TIMER1_CTL_R = 0x00000000; EnableInterrupts(); ST7735_Circle(ST7735_BLACK); //drawClockHands(hour, minute, 1); drawDigTime(hour, minute, AMPM); ST7735_SetCursor(2, 14); printf("<"); ST7735_SetCursor(18, 14); printf(">"); drawClockHands(2,30,1); play = 1; TIMER1_CTL_R = 0x00000001; while(1){ } }
int main(void){ PLL_Init(); // 25 MHz SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F ADC0_InitSWTriggerSeq3(0); // allow time to finish activating // ADC0_InitAllTriggerSeq3(0); // allow time to finish activating Timer0A_Init10HzInt(); // set up Timer0A for 10 Hz interrupts Timer1_Init(); // Intitalize timer1 count down GPIO_PORTF_DIR_R |= 0x04; // make PF2 out (built-in LED) GPIO_PORTF_AFSEL_R &= ~0x04; // disable alt funct on PF2 GPIO_PORTF_DEN_R |= 0x04; // enable digital I/O on PF2 // configure PF2 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF GPIO_PORTF2 = 0; // turn off LED EnableInterrupts(); ST7735_InitR(INITR_REDTAB); ST7735_FillScreen(0); // set screen to black ST7735_SetCursor(0,0); ST7735_XYplotInit("Lab 2 PMF Averaging \n", 0, 4096, 0, 50); ST7735_OutString("1 point \n"); while(1){ WaitForInterrupt(); // GPIO_PORTF2 = 0x04; // profile // ADCvalue = ADC0_InSeq3(); // GPIO_PORTF2 = 0x00; if(Buffer_Counter == 1000){ break; } } uint32_t Jitter; // DisableInterrupts(); // TIMER1_CTL_R = 0x00000000; // 10) enable TIMER1A GPIO_PORTF2 = 0x04; // profile Jitter = Calc_Jitter(); uint32_t n = ADCvalue; // ST7735_OutUDec(n); Calc_PMF(); // will populate the frequency table ADC_Data = x-axis ADC_Freq = y-axis // Next line is call to the plot point function we created in lab1 // ST7735_XYplotInit("PMF", 0, 4096, 0, 50); // ST7735_XYplot(1000, ADC_Data, ADC_Freq); int j = 0; uint32_t x = 0; uint32_t y = 0; int i = 0; //ST7735_PlotClear(32, 159); // for(j = 0; j < 1000; j+=1){ ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000); ST7735_XYplot(1000, ADC_Data, ADC_Freq); // ST7735_PlotBar(ADC_Freq[j]); // ST7735_PlotBar(ADC_Freq[j]); //ST7735_PlotBar(30); //ST7735_PlotNext(); // y = 32+(127*(400-ADC_Freq[j]))/400; // x = 127-(127*(4095 - ADC_Data[j])/4095); // if(x<0)x = 0; // if(x>127)x=127; // if(y<32) y = 32; // ST7735_PlotBar(y); // if(y>159) y = 159; // if(x > i){ // ST7735_PlotNext(); // i += 1; // } /* if(j < 14){ ST7735_OutUDec(ADC_Data[j]); ST7735_OutString(" "); ST7735_OutUDec(ADC_Freq[j]); ST7735_OutString("\n"); } */ // } GPIO_PORTF2 = 0x00; // EnableInterrupts(); }
/****** public utility functions ******/ void LCD_Init(void){ ST7735_InitR(INITR_REDTAB); return; }
int main(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; SlSockAddrIn_t LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); stopWDT(); // Stop WDT initClk(); // PLL 50 MHz, ADC needs PPL active Board_Init(); // initialize LaunchPad I/O ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This node is configured to receive UDP packets\n"); UARTprintf("This node should be at IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); ST7735_InitR(INITR_REDTAB); ST7735_OutString("Internet of Things\n"); ST7735_OutString("Embedded Systems\n"); ST7735_OutString("Vol. 2, Valvano"); ST7735_PlotClear(0,4095); // range from 0 to 4095 while(1){ sl_Start(0, 0, 0); /* Initializing the CC3100 device */ /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); // connect to AP /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); while(Status > 0){ UARTprintf("\nReceiving a UDP packet ..."); LocalAddr.sin_family = SL_AF_INET; LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); LocalAddr.sin_addr.s_addr = 0; AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if( SockID < 0 ){ UARTprintf("SockIDerror\n"); Status = -1; // error }else{ Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); if( Status < 0 ){ sl_Close(SockID); UARTprintf("Sock Bind error\n"); }else{ Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize ); if( Status <= 0 ){ sl_Close(SockID); UARTprintf("Receive error %d ",Status); }else{ LED_Toggle(); sl_Close(SockID); UARTprintf("ok %s ",uBuf); if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ int i,bOk; uint32_t place; data = 0; bOk = 1; i=4; // ignore possible negative sign for(place = 1000; place; place = place/10){ if((uBuf[i]&0xF0)==0x30){ // ignore spaces data += place*(uBuf[i]-0x30); }else{ if((uBuf[i]&0xF0)!= ' '){ bOk = 0; } } i++; } if(bOk){ ST7735_PlotLine(data); ST7735_PlotNextErase(); } } } } } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 120ms } } }
/* * Application's entry point */ int main(void){ SlSecParams_t secParams; char *pConfig = NULL; uint32_t timeElapsed; initClk(); // PLL 50 MHz UART_Init(); // Send data to PC, 115200 bps LED_Init(); // initialize LaunchPad I/O Timer1_Init(); ADC0_InitSWTriggerSeq3_Ch9(); //initialize ADC sampler ST7735_InitR(INITR_REDTAB); ST7735_SetCursor(1,1); printf("Lab4C\n"); Wifi_Connect(pConfig, &secParams); UARTprintf("Weather App\n"); while(1){ // clear the data output ST7735_SetCursor(0,4); for(uint16_t i = 0; i < 6; i += 1) { printf(" \n"); } ST7735_SetCursor(0,4); LED_GreenOn(); Timer1_StartWatch(); char *weather_data = HTTP_Request( "api.openweathermap.org", 80, "GET", "/data/2.5/weather?q=Austin%20Texas&units=metric&APPID=d6e361f259c47a6ea9837d41b1856b03", NULL, NULL ); timeElapsed = Timer1_StopWatch(); LED_GreenOff(); UARTprintf("\r\n\r\n"); UARTprintf(weather_data); UARTprintf("\r\n"); printf("Temp = %6s C\n", Extract_Temperature(weather_data)); printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 ); uint32_t sample = ADC0_InSeq3(); LED_GreenOn(); Timer1_StartWatch(); char *send_data = HTTP_Request( // embsysmooc or embedded-systems-server? "embsysmooc.appspot.com", 80, "GET", "/query?city=Austin%20Texas&id=John%20Starich%20and%20Jon%20Ambrose&edxcode=8086&greet=Voltage~", VoltageToString(sample), "V" ); timeElapsed = Timer1_StopWatch(); LED_GreenOff(); UARTprintf("\r\n\r\n"); UARTprintf(send_data); UARTprintf("\r\n"); printf("Voltage~%luV\n", sample); printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 ); LED_GreenOn(); Timer1_StartWatch(); char *custom = HTTP_Request( "tomcat.johnstarich.com", 80, "GET", "/%22temp%22:1000,", NULL, NULL ); timeElapsed = Timer1_StopWatch(); LED_GreenOff(); UARTprintf("\r\n\r\n"); UARTprintf(send_data); UARTprintf("\r\n"); UARTprintf("Custom temp: %s", custom); UARTprintf("\r\n"); printf("Custom temp: %s\n", Extract_Temperature(custom)); printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 ); while(Board_Input()==0){}; // wait for touch } }
int main(void){ DisableInterrupts(); PLL_Init(Bus10MHz); // bus clock at 10 MHz Buttons_Init(); SysTick_Init(); ST7735_InitR(INITR_REDTAB); TEC_Init(); ADC0_InitSWTriggerSeq3_Ch0(); printf("Critical Can Cooler\nV1.0\n\nCurrent Temp: \nDesired Temp: \nTEC Status: "); EnableInterrupts(); while(1) { /* convert ADC_sample to Current_Temp Get TEC_Temp Compare TEC_Temp with Current_Temp Turn off if less than/equal to Display "Critical Can Cooler V1.0" Display Current_Temp Display TEC_temp Display TEC_Status */ /* Temp scale: MAX 1740 mV or 2160 ADC measure = 25 C MIN 960 mV or 1192 ADC measure = 0 C 2160* .806mV/adctic = temp in mV vo -480/15.6 adc tics * .806mV/tic = sample in mV (mV - 960) /31.2 = T ((adc *806) - 960000) / 31200 = T */ Current_Temp = (((int32_t)ADC_Sample * 806) - 960000) / 31200; //if(TEC_Get() > Current_Temp) { // TEC_Stop(); //} ST7735_SetCursor(14,3); printf("%-3d",Current_Temp); ST7735_SetCursor(14,4); printf("%d",TEC_Get()); ST7735_SetCursor(14,5); if(TEC_Status()) { printf("ON \n"); } else { printf("OFF\n"); } WaitForInterrupt(); } }