// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz EnableInterrupts(); /*Initialize ports , ADC and timers*/ ADC0_InitSWTriggerSeq3_Ch1(); PortA_Init(); //SysLoad(T); SysFun(); while(1){ /*Your code goes here*/ value=ADC0_InSeq3(); //PWMindex=(ADCvalue); p=((value+1)*390)+800000; //for(i=0;i<4;i++){ GPIO_PORTA_DATA_R|=0x20; SysLoad(p); GPIO_PORTA_DATA_R&=~0x20 ; SysLoad(T-p); //} } }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz Port_Init(); ADC0_InitSWTriggerSeq3_Ch1(); EnableInterrupts(); SysFun(); /*Initialize ports , ADC and timers*/ while(1){ /*Your code goes here*/ a= ADC0_InSeq3(); t1=a+(10000/4096)+10000; in1=50; while(in1) { GPIO_PORTA_DATA_R |= (0x20); SysLoad(t1); GPIO_PORTA_DATA_R &= ~(0x20); SysLoad(t-t1); in1=in1-1; } } }
int main0(void){ // "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.2 UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 15 ADC0_InitSWTriggerSeq3(7); // Ain7 is on PD0 16 sl_Start(0, 0, 0); // Initializing the CC3100 device 17 WlanConnect(); // connect to AP 18 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 19 (unsigned char *)&ipV4); // 20 Addr.sin_family = SL_AF_INET; // 21 Addr.sin_port = sl_Htons((UINT16)PORT_NUM); // 22 Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); // 23 AddrSize = sizeof(SlSockAddrIn_t); // 24 SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 25 while(1){ uBuf[0] = ATYPE; // analog data type 26 uBuf[1] = '='; // 27 data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0 28 Int2Str(data,(char*)&uBuf[2]); // 6 digit number 29 sl_SendTo(SockID, uBuf, BUF_SIZE, 0, // 30 (SlSockAddr_t *)&Addr, AddrSize); // 31 ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 40ms 32 } }
void Timer0A_Handler(void){ TIMER0_ICR_R = TIMER_ICR_TATOCINT; // acknowledge timer0A timeout PF2 ^= 0x04; // profile PF2 ^= 0x04; // profile ADCvalue = ADC0_InSeq3(); PF2 ^= 0x04; // profile if (i <= 999){ int a = TIMER1_TAR_R; int b = oldtime - a; array1[i] = a; array2[i] = b; array3[i] = ADC0_InSeq3(); oldtime = a; i++; } }
/**************************************************************************** Function randomizePasswords Parameters void Returns void Description Randomly generates four passwords and assigns one of the four passwords to be the correct password Notes ****************************************************************************/ void randomizePasswords(void) { srand(ADC0_InSeq3()); generateRandomPassword(password1); generateRandomPassword(password2); generateRandomPassword(password3); generateRandomPassword(password4); // randomly selects which of the passwords is the correct one correctPassword = rand() % NUM_PASSWORDS + 1; }
uint8_t ADCRectState(uint8_t numRect){ if(numRect==1){ return 1; } else if(numRect==2){ uint32_t ADCsample = ADC0_InSeq3(); uint16_t stateNumber = (ADCsample/(2048)); return stateNumber+1; } else if(numRect==3){ uint32_t ADCsample = ADC0_InSeq3(); uint16_t stateNumber = (ADCsample/(1366)); return stateNumber+1; } else if(numRect==4){ uint32_t ADCsample = ADC0_InSeq3(); uint16_t stateNumber = (ADCsample/(1024)); return stateNumber+1; } else{ return 0; } }
void Timer0A_Handler(void){ int interval = 512; TIMER0_ICR_R = TIMER_ICR_TATOCINT; // acknowledge timer0A timeout //GPIO_PORTF2 = 0x04; // profile audioInput = (int) ADC0_InSeq3(); // if(audioInput[i] < 2000 && i < 50){ // GPIO_PORTF_DATA_R ^= 0x02; //} // i += 1; // if(i == 1024){i = 0;} // GPIO_PORTF2 = 0x00; if (audioInput >= 0 && audioInput <= interval) { SysTick_Reload (1908); } else if (audioInput > interval && audioInput <= interval*2) { SysTick_Reload (1700); } else if (audioInput > interval*2 && audioInput <= interval*3) { SysTick_Reload (1515); } else if (audioInput > interval*3 && audioInput <= interval*4) { SysTick_Reload (1432); } else if (audioInput > interval*4 && audioInput <= interval*5) { SysTick_Reload (1275); } else if (audioInput > interval*5 && audioInput <= interval*6) { SysTick_Reload (1136); } else if (audioInput > interval*6 && audioInput <= interval*7) { SysTick_Reload (1012); } else { SysTick_Reload (956); } }
void Timer0A_Handler(void){ TIMER0_ICR_R = TIMER_ICR_TATOCINT; // acknowledge timer0A timeout Current_Time = TIMER1_TAILR_R; GPIO_PORTF2 = 0x04; // profile //Elapsed_Time = TIMER1_TAILR_R; ADCvalue = ADC0_InSeq3(); Elapsed_Time = Prev_Time - Current_Time; //Elapsed_Time = Elapsed_Time - TIMER1_TAILR_R; Prev_Time = Current_Time; GPIO_PORTF2 = 0x00; if(Buffer_Counter <= 1000){ if(Buffer_Counter == 1000){ Buffer_Counter += 1; return; } ADC_Data[Buffer_Counter] = ADCvalue; ADC_Elapsed_Time[Buffer_Counter] = Elapsed_Time; Buffer_Counter += 1; } }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); Port_Init(); ADC0_InitSWTriggerSeq3_Ch1(); SysFun(); EnableInterrupts(); /*Initialize ports , ADC and timers*/ while(1){ SW = GPIO_PORTA_DATA_R&0x04; // read PA2 into SW1 if(SW){ GPIO_PORTA_DATA_R |=0x01; //PA0 HIGH GPIO_PORTA_DATA_R&=~0x02; //PA1 LOW } else { GPIO_PORTA_DATA_R |=0x02; //PA1 HIGH GPIO_PORTA_DATA_R&=~0x01; //PA0 LOW } ADCvalue=ADC0_InSeq3(); T1=TON+(ADCvalue *175); if (ADCvalue==0){ GPIO_PORTA_DATA_R |=0x20; SysLoad(TON); GPIO_PORTA_DATA_R =~0x20; SysLoad(TON); } else{ GPIO_PORTA_DATA_R |=0x20; SysLoad(T1); GPIO_PORTA_DATA_R =~0x20; SysLoad(T-T1); } } }
void Timer0A_Handler(void){ TIMER0_ICR_R = TIMER_ICR_TATOCINT; // acknowledge timer0A timeout ADCvalue = ADC0_InSeq3(); }
int main1(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; 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"); #if ADC ADC0_InitSWTriggerSeq3(7); // Ain7 is on PD0 UARTprintf("This node is configured to measure signals from Ain7=PD0\n"); #endif #if EKG UARTprintf("This node is configured to generate simulated EKG data\n"); #endif UARTprintf(" and send UDP packets to 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); 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){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons((UINT16)PORT_NUM); Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if( SockID < 0 ){ UARTprintf("SockIDerror "); Status = -1; // error }else{ while(Status>0){ UARTprintf("\nSending a UDP packet ..."); uBuf[0] = ATYPE; // defines this as an analog data type uBuf[1] = '='; #if ADC data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0 #endif #if EKG data = EKGbuf[EKGindex]; EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz #endif Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number UARTprintf(" %s ",uBuf); LED_Toggle(); Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, AddrSize); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms if( Status <= 0 ){ UARTprintf("SockIDerror %d ",Status); }else{ UARTprintf("ok"); } } sl_Close(SockID); } } } }
int main(void){int32_t retVal; SlSecParams_t secParams; char *pConfig = NULL; INT32 ASize = 0; SlSockAddrIn_t Addr; ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating initClk(); // PLL 50 MHz Output_On(); UART_Init(); // Send data to PC, 115200 bps Timer1_Init(); LED_Init(); // initialize LaunchPad I/O UARTprintf("Weather App\n"); retVal = configureSimpleLinkToDefaultState(pConfig); // set policies if(retVal < 0)Crash(4000000); retVal = sl_Start(0, pConfig, 0); if((retVal < 0) || (ROLE_STA != retVal) ) Crash(8000000); secParams.Key = PASSKEY; secParams.KeyLen = strlen(PASSKEY); secParams.Type = SEC_TYPE; // OPEN, WPA, or WEP sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); while((0 == (g_Status&CONNECTED)) || (0 == (g_Status&IP_AQUIRED))){ _SlNonOsMainLoopTask(); } UARTprintf("Connected\n"); while(1){ int i = 0; while(i < 10){ int sendc = 0; strcpy(HostName,"openweathermap.org"); retVal = sl_NetAppDnsGetHostByName(HostName, strlen(HostName),&DestinationIP, SL_AF_INET); if(retVal == 0){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(80); Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian ASize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( SockID >= 0 ){ retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize); } if((SockID >= 0)&&(retVal >= 0)){ strcpy(SendBuff,REQUEST); sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response sl_Close(SockID); LED_GreenOn(); UARTprintf("\r\n\r\n"); UARTprintf(Recvbuff); UARTprintf("\r\n"); } } ST7735_OutUDec(sendc); ST7735_OutString("\n"); i++; } //while(Board_Input()==0){}; // wait for touch LED_GreenOff(); //Temp Part e getTemp(Recvbuff); ST7735_OutChar('T'); ST7735_OutChar('e'); ST7735_OutChar('m'); ST7735_OutChar('p'); ST7735_OutChar(' '); ST7735_OutChar('='); ST7735_OutChar(' '); for(int i = 0; i < 5; i++){ ST7735_OutChar(myArray[i]); } ST7735_OutChar('\n'); //ADC Part f ADC0_SAC_R = ADC_SAC_AVG_64X; //enable 64 times average before obtaining result int voltage = ADC0_InSeq3(); ST7735_OutString("Voltage~"); ST7735_sDecOut3(voltage); char* voltageString; char voltageStringNum[5]; sprintf(voltageStringNum, "%.1d.%.3d", voltage/1000, voltage%1000); //ST7735_OutString(voltageStringNum); char* sendString; char str1[173] = "GET /query?city=Austin%20Texas&id=Ty%20Winkler%20Jeremiah%20Bartlett&greet=Voltage%3D"; strcat(str1, voltageStringNum); strcat(str1, "V&edxcode=8086 HTTP/1.1\r\nUser-Agent: Keil\r\nHost: embsysmooc.appspot.com\r\n\r\n"); strcpy(HostName,"embsysmooc.appspot.com"); retVal = sl_NetAppDnsGetHostByName(HostName, strlen(HostName),&DestinationIP, SL_AF_INET); if(retVal == 0){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(80); Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian ASize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( SockID >= 0 ){ retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize); } if((SockID >= 0)&&(retVal >= 0)){ strcpy(SendBuff, str1); count = 0; sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response sl_Close(SockID); LED_GreenOn(); UARTprintf("\r\n\r\n"); //ST7735_OutString(Recvbuff); UARTprintf("\r\n"); } } while(1); } }
uint8_t ADCPinState(){ uint32_t ADCsample = ADC0_InSeq3(); uint16_t stateNumber = (ADCsample/456); return stateNumber+1; }
/* * 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 } }