Пример #1
0
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();
	}
}
Пример #2
0
void Init_Plot(void){
ST7735_SetCursor(0,0); ST7735_OutString("Lab 9");
 ST7735_PlotClear(1000,4000);  // range from 0 to 4095
 ST7735_SetCursor(0,1); ST7735_OutString("N=");
 ST7735_SetCursor(0,2); ST7735_OutString("T="); ST7735_DecOut2(2500);
                        ST7735_OutString(" C");

}
Пример #3
0
int main(void){  
	char* lab9greeting = "Welcome to Lab 9!";
	int temp;
//	int Temperature = 100;
//  DisableInterrupts();
//  PLL_Init(Bus80MHz);
//	//ST7735_InitR(INITR_REDTAB);
//  Output_Init();       // UART0 only used for debugging
//	ST7735_Output_Init(); 
//	ADC0_InitSWTriggerSeq3_Ch9(); //initialize the ADC
//	Timer0A_Init20HzInt(); //initialize the timer
//	ST7735_DrawString(0,0, lab9greeting, ST7735_WHITE);
//	EnableInterrupts();
	
	PLL_Init(Bus80MHz);                   // 80 MHz
  SYSCTL_RCGCGPIO_R |= 0x20;            // activate port F
  ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  Timer0A_Init20HzInt();               // set up Timer0A for 100 Hz interrupts
  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
	ST7735_Output_Init();
	ST7735_DrawString(0,0, lab9greeting, ST7735_WHITE);
	//Init_Plot();
	
	//ST7735_SetCursor(0,0); ST7735_OutString("Lab 9");
 ST7735_PlotClear(1000,4000);  // range from 0 to 4095
 ST7735_SetCursor(0,1); ST7735_OutString("N=");
 ST7735_SetCursor(0,2); ST7735_OutString("T="); //ST7735_DecOut2(2500);
                        ST7735_OutString(" C");
  EnableInterrupts();
	
  while(1){
						ST7735_SetCursor(3,1); ST7735_OutUDec(ADCvalue);            // 0 to 4095

		if(refresh){
				refresh = 0;
				samples++;
		    ST7735_PlotPoint(ADCvalue);  // Measured temperature
				if((samples&(N-1))==0){          // fs sampling, fs/N samples plotted per second
					ST7735_PlotNextErase();  // overwrites N points on same line
				}
				if((samples%fs)==0){    // fs sampling, 1 Hz display of numerical data
				//do conversion here, set it equal to temp.
				temp = get_temp(ADCvalue);
				ST7735_SetCursor(3,1); ST7735_OutUDec(ADCvalue);            // 0 to 4095
				ST7735_SetCursor(3,2);ST7735_DecOut2(temp); // 0.01 C 
			}

		}
	}

  
}
Пример #4
0
/**************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;
}
Пример #5
0
void plotInit(void){
	ST7735_SetCursor(0,0); 
	ST7735_OutString("Temp");
	ST7735_PlotClear(1000,4000);  // range from 0 to 4095
	ST7735_SetCursor(0,1); 
	ST7735_OutString("N=");
	ST7735_SetCursor(0,2); 
	ST7735_OutString("T="); 
	ST7735_sDecOut2(0000);
	ST7735_SetCursor(7,2); 
  ST7735_OutString("C");
}
Пример #6
0
void ST7735_InitTemperatureGraph()
{
    ST7735_SetCursor(0,0); 
    ST7735_OutString("Temperature Data");
    ST7735_PlotClear(1000,4000);  // range from 0 to 4095
    ST7735_SetCursor(0,1); 
    ST7735_OutString("N=");
    ST7735_SetCursor(0,2); 
    ST7735_OutString("T= "); 
    ST7735_sDecOut2(2500);
    ST7735_OutString(" C");
}
Пример #7
0
  // "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
      }
    }
  }
}
Пример #8
0
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();
	}
}
Пример #9
0
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){
		
	}
}
Пример #10
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
    }
  }
}