Exemple #1
0
int main2(void){
  TExaS_Init();       // Bus clock is 80 MHz 
  ADC_Init();         // turn on ADC, set channel to 1
  ST7735_InitR(INITR_REDTAB); 
  PortF_Init();
  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_OutFix(Data); 
    ST7735_OutString("    ");  // these spaces are used to coverup characters from last output
    PF1 = 0;          // end of LCD Profile
  }
}
Exemple #2
0
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
  }
}
Exemple #4
0
void ST7735_UpdateTemperatureGraph(uint32_t numSamples, uint16_t adcValue)
{
    uint16_t temperature = getTemp(adcValue);
    
    // DEBUG
    // Magnify the plot to see the noise distribution better
    // ST7735_PlotPoint((temperature - 2200)*15);
    ST7735_PlotPoint(temperature);  // Measured temperature
    if((numSamples&(N-1))==0){          // fs sampling, fs/N samples plotted per second
        ST7735_PlotNextErase();  // overwrites N points on same line
    }
    if((numSamples%FS)==0){    // fs sampling, 1 Hz display of numerical data
        ST7735_SetCursor(3,1); 
        ST7735_OutUDec(adcValue);            // 0 to 4095
        ST7735_OutString(" "); // clear previous number
        ST7735_SetCursor(3,2); 
        ST7735_sDecOut2(temperature); // 0.01 C 
    }
}
Exemple #5
0
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
	}
}
Exemple #6
0
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();
}
Exemple #7
0
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
    }
  }
}
Exemple #8
0
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);
	}
}
Exemple #9
0
//------------Character_CollisionStatus------------
// Print the collision status for the selected character in the top left of the screen
// Input: Character status to be evaluated
// Output: none
void Character_CollisionStatus(short data){
		switch(data){												// print collision status
		case 0: 		ST7735_SetCursor(1, 1);
								ST7735_OutString("No ouch...");
								break;
		case 1: 		ST7735_SetCursor(1, 1);
								ST7735_OutString("Bottom Left");
								break;
		case 2: 		ST7735_SetCursor(1, 1);
								ST7735_OutString("mid LEft yo");
								break;
		case 3:			ST7735_SetCursor(1, 1);
								ST7735_OutString("top-left");
								break;
		case 4: 		ST7735_SetCursor(1, 1);
								ST7735_OutString("top-mid");
								break;
		case 5: 		ST7735_SetCursor(1, 1);
								ST7735_OutString("Top right yo");
								break;
		case 6:			ST7735_SetCursor(1, 1);
								ST7735_OutString("right Mido");
								break;
		case 7:			ST7735_SetCursor(1, 1);
								ST7735_OutString("Bottomz-right");
								break;
		case 8:			ST7735_SetCursor(1, 1);
								ST7735_OutString("bottom-Mido");
								break;
		case 9:			ST7735_SetCursor(1, 1);
								ST7735_OutString("!?WHY YOU INSIDE");
								ST7735_SetCursor(1, 2);								
								ST7735_OutString("ME BRAH?!");
								break;
	}
}
Exemple #10
0
int main(void){
	volatile uint32_t delay;
	int i;
	
	PLL_Init();
	Output_Init();
//	CAN0_Open();
	
	DisableInterrupts();
	
	SYSCTL_RCGCGPIO_R |= 0x20;
  while((SYSCTL_PRGPIO_R&0x0020) == 0){};// ready?
  Count = 0;                       // allow time to finish activating
//  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_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F
	GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
	GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog on
    
	GPIO_PORTF_DIR_R &= ~0x03;       // make PB6 in
  GPIO_PORTF_AFSEL_R |= 0x03;      // enable alt funct on PB6
  GPIO_PORTF_DEN_R |= 0x03;        // enable digital I/O on PB6
                                   // configure PB6 as T0CCP0
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFFF00)+0x00000077;
  GPIO_PORTF_AMSEL_R &= ~0xFF;     // disable analog functionality on PB6
		
	SYSCTL_RCGCGPIO_R  |= 0x01;
	delay = SYSCTL_RCGCGPIO_R;      // 2) allow time for clock to stabilize
  delay = SYSCTL_RCGCGPIO_R;
	GPIO_PORTA_DIR_R |= 0x01;  			// 3.11) make PA6 output
  GPIO_PORTA_AFSEL_R &= ~0x01; 		// 4.11) disable alternate function on PA6
  GPIO_PORTA_DEN_R |= 0x01;  			// 5.11) enable digital I/O on PA6
  GPIO_PORTA_AMSEL_R = 0; 				// 6.11) disable analog functionality on PA6	
	Switch_Init();
	
	Init_Timer4A();
	Timer4A_Wait(80000000); //wait 1 sec
	Init_Timer5A(80000);
	ADC0_InitTimer3ATriggerSeq3PD3(6000);
	ADC0_InitTimer3BTriggerSeq2PD2(5500);
	
	TimerCapture_Init(UserTask2);
	InitMotors();
	
	EnableInterrupts();
	
	
	while(1) {
		getSensorValues();
		printSensorValues(0);
		if(buttonL) {
			printSensorValues(6);
			ControlMotors(35000,35000);
			ST7735_SetCursor(0,8);ST7735_OutString("Buttonback");
			buttonL = 0;
			for(i = 0; i < 1440000; i++);
		}
		if(buttonR) {
			printSensorValues(6);
			ControlMotors(35000,35000);
			ST7735_SetCursor(0,1);ST7735_OutString("ButtonR");
			buttonR = 0;
			for(i = 0; i < 1440000; i++);
		}
		
		if (Ping1 < 18) {
			//ControlMotors(40000, 40000);
			ST7735_SetCursor(0,1);
			ST7735_OutString("Stopped");
			printSensorValues(3);
//			while(1) {
				ST7735_SetCursor(0,1);ST7735_OutString("Stopped");
				getSensorValues();
				printSensorValues(0);
//			}
			if(IR_L > IR_R) {
				ControlMotors(35000,35000);
				ST7735_SetCursor(0,8);ST7735_OutString("BL");
			}
			else {
				ControlMotors(35000,35000);
				ST7735_SetCursor(0,8);ST7735_OutString("BR");
			}
			for(i = 0; i < 1440000; i++);
		}
		else if (((Ping2 > 80) != (Ping3 > 80)) && (Ping1 < 40)) {
			if (Ping2>80) {
				//spot turn right
				ControlMotors(20000, 60000);
			}
			if (Ping3>80) {
				//spot turn left
				ControlMotors(60000, 20000); 
			}
		//	ControlMotors(40000,40000);
		}
		else if(IR_L < 1500 && IR_R < 1500) {
			ControlMotors(70000,65000);
			ST7735_SetCursor(0,8);ST7735_OutString("FO");
		}
		else if(IR_L < IR_R) {
			ControlMotors(70000,50000);
			ST7735_SetCursor(0,8);ST7735_OutString("LE");
		}
		else if(IR_R < IR_L) {
			ControlMotors(70000,72000);
			ST7735_SetCursor(0,8);ST7735_OutString("RI");
		}
	}
}