Esempio n. 1
0
int main(void)
{
	
	//Initial Serial, ADC & LCD Display:
	USARTInit(52);
	lcd_init();
	ADCinit();
	pwm_init();
	
	char adc_output[6][4];	
	int adc_value[6]; // Variable to hold ADC result
	
    while(1)
   {	
	   for(int i=0;i<6;i++){
		   adc_value[i] = ADCread(i);
		   itoa(adc_value[i],adc_output[i],10);
		   USARTWriteString(adc_output[i]);
		   if(i!=5){USARTWriteChar(';');}
	   }
	   
		//Sending a new line:
	   	USARTWriteChar('\r');
	   	USARTWriteChar('\n');
		
		//Set PWM:
		pwm(adc_value[5]);
		
		//Show data on the lcd display   
		show(adc_output);
		
		//Delay:
		_delay_ms(500);
   }
}
Esempio n. 2
0
void U_USART1::Init(uint32_t baud) {
	GPIOInit();
	USARTInit(baud);
	NVICInit();

	USART_Cmd(USART1, ENABLE);
}
Esempio n. 3
0
int main()
{
	// set a default image to the display
	char smiley[] = {0x00, 0x04, 0x42, 0x02, 0x02, 0x42, 0x04, 0x00};
	char full[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

	// initialize for shift registers
	initializeShift();

	// set the clock pre-scaler value to 1
	CLKPR = 0x80; 
	CLKPR = 0x00;

	USARTInit();

	// initialize interrupts and timer0
	sei();
	timer8_enable_int();
	timer8_init(REFRESH_CYCLE_COUNT, CLOCK_SCALE_1024);
	timer8_start();

	// so we can see what's happening
	setFrame(full);

	// wait for everything to initialize.
	// UART likes to tick a bit (4x) at first sometimes
	_delay_ms(1000);
	
	// reinitialize the starting point to 0
	line = 0;
	
	setFrame(smiley);

	while(1);
}
int main( void )
{   
	sei();
 	Timer1_Init();
	I2C_init(0x52);	 
    USARTInit(9600);
//	SERVO_Init();
	
		
//	SERVO_UpdateServo(0,1500);
//	SERVO_UpdateServo(1,1800);
//	SERVO_UpdateServo(2,2600);
//	SERVO_UpdateServo(3,2800);
	

	//Timer1_print_time(Timer1_get_time());
	
	USARTWriteString("\r\nReset\r\n");
	SERVO_Run();

	
	
	while(1)
	{
		//handleI2C();
		//I2C_isdataready();
		
	}
	
	return 0;
}
Esempio n. 5
0
void SetupHardware(void)
{
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	DDRB = (1 << PB5) | (1 << PB6) | (1 << PB4);
	DDRC = (1 << PC7);
	PORTC |= (1 << PC2);


	clock_prescale_set(0);

	USB_Init();
	USARTInit(25);

	TCCR0A |= (1 << WGM01);
	TCCR0B |= (1 << CS00) | (1 << CS02);
	TIMSK0 |= (1 << OCIE0A);
	OCR0A = 255;

	DDRD &= ~(1 << PD1);
	EICRA |= (1 << ISC11) | (1 << ISC10);
	EIMSK |= (1 << INT1);

	DDRC &= ~(1 << PC2);
	PORTC |= (1 << PC2);
}
Esempio n. 6
0
int main (void) 
{
  volatile uint32_t i;

SystemCoreClockUpdate();

  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( i & 0x01 )
	  UARTTxBuffer[i] = 0x55;
	else
	  UARTTxBuffer[i] = 0xAA;
	UARTTxDummyBuffer[i] = UARTRxBuffer[i] = 0x00;	
  }

  /* NVIC is installed inside UARTInit file. */
  USARTInit(9600, MASTER_MODE);

  /* To run USART test, reset at the slave side first, master will
  send a block of data first, if it's not in the continuous mode,
  master send a block of dummy data to clock in the data from the slave,
  on the slave side, it's ready to receive, once it's received a block
  of data, send the same data back to the master. Once the master receives
  the block of data from the slave. It verifies the result. */

  /* For Sync comminication with STARTSTOP disabled, the sync. is very important
  or received data will be one bit off. If SYNCCTRL_NOSS bit is set, the program
  should have a break point to stop below, then, reset the slave side. Without
  doing so, this program will fail. If SYNCCTRL_NOSS is not set, STARTSTOP bit
  is enabled, then break point is not necessary. */
  USARTSend( (uint8_t *)UARTTxBuffer, BUFSIZE );

  for ( i = 0; i < 0x4000; i++ );		/* Short delay and wait for slave to be ready. */
  UARTBlockReceived = 0;

  /* Send dummy block for read, one more than needed. It's not necessary 
  if continuous clock is turned on while STARTSTOP is enabled. */
  if ( LPC_USART->SYNCCTRL & SYNCCTRL_NOSS )
  {
	/* If StartStop is disabled, no continuous clock should be turned on. */
	USARTSend( (uint8_t *)UARTTxDummyBuffer, BUFSIZE );
  }
  else if ( !(LPC_USART->SYNCCTRL & SYNCCTRL_CSCEN) )
  {
	USARTSend( (uint8_t *)UARTTxDummyBuffer, BUFSIZE );
  }
	
  while ( !UARTBlockReceived );		/* Whole data block received from the slave. */

  /* Verifying buffer. */
  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( UARTTxBuffer[i] != UARTRxBuffer[i] )
	{
	  while ( 1 );
	}
  }
  UARTBlockReceived = 0;
  while ( 1 );	/* never exit from main for debugging. */
}
void main () {
	USARTInit();
	motion_pin_config();

	char data;
	
	while(1) {
		data = USARTReadChar();
		_delay_ms(100);

/*				
		if (data)
		{
		
			backward();
			_delay_ms(1000);
			stop();
			_delay_ms(500);
		}
	//	USARTWriteChar(data);
*/		

		if (data == 'F')	{
		
			forward();
			_delay_ms(200);
			stop();
			_delay_ms(100);
			
		}

		if (data == 'B') {
		
			backward();
			_delay_ms(200);
			stop();
			_delay_ms(100);
		}

		if (data == 'L') {
			
			left();
			_delay_ms(200);
			stop();
			_delay_ms(100);
		}

		if (data == 'R') {
		
			right();
			_delay_ms(200);
			stop();
			_delay_ms(100);
		}
		
	}
}
Esempio n. 8
0
void SystemInit(void) // Power on variable initialization 
{
	USARTInit(UBRRVAL);
	sensor_Data = 0; // 0 
	Change_Baudrate(51); // 19200
	Command_Display(Clear_Screen);
	Command_Display(Go_Home);
	//Change_Baudrate(83); // 1200
	
}
int main(void)
{
    //Code geoptimaliseerd voor bordje 3
    //###1###

    //Initialize subsystems
    ClockInit();			//Initialize system clock (16 MHz)
    USARTInit();			//Initialize USART and bind to stdout,stdin
    AnalogInit();			//Initialize ADC
    AccInit();			//Initialize accelerometer system
    LEDInit();			//Initialize LEDs
    SwitchInit();			//Initialize switches
    EncoderInit();			//Initialize encoder
    SpeakerInit();			//Initialize speaker system

    //Enable interrupts
    PMIC.CTRL|=0b00000111;  	//Enable low, medium, high priority interrupts
    SREG|=0b10000000;		//Globale interrupt enable

    //###2###

    //Print the digits 0 to 9 5x on terminal device
    //Reason this section didn't work: de variabelen 'a' is globaal gedefinieerd. In het subprogramma 'SimpleFunction()' wordt
    //de variabelen 'a' gebruikt. Na dit subprogramma is de waarde van 'a' gelijk aan 10 en zal de lus (a<5) onderbroken worden.

    for (a=0; a<5; a++)
    {
        SimpleFunction();
        printf ("\r\n");
    }

    //###3###

    //Main program loop
    a=0;
    ledOn=0b00001000;

    //Beeps();		//Genereer 3 beeps van 500hz, 1000hz, 1500hz (500 ms)
    setNotes();		//Stel een reeks van noten in
    playNextNote();		//Speel de eerste noot uit de reeks

    while(1)
    {
        LoopLicht();						//LoopLicht sequentie
        AccLezen();						//Accelerometer lezen
        printf("$SWITCH %d\r\n", SwitchGet());			//Switchwaarde over USARTD: 1: center, 2: rechts, 4: beneden, 8: links, 16: boven
        printf("$ACCRAW %d %d %d\r\n", RawAccX, RawAccY, RawAccZ);						//Ongecalibreerde waardes accelerometer x, y, z over USARTD
        printf("$ACC__ %d %d %d\r\n", AccGetXAxis(RawAccX), AccGetYAxis(RawAccY), AccGetZAxis(RawAccZ));	//Gecalibreerde waardes accelerometer x, y, z over USARTD
        printf("$ENC__ %d\r\n", EncoderGetPos());
        //printf ("Counter:%d\r\n",a);
        //printf("%c", 0x55);					//Stuur de waarde 0x55 uit (0b01010101)
        //a++;
        _delay_ms(20);
    }
}
Esempio n. 10
0
int main()
{
	//Initialize the USART with Baud rate = 2400bps
	USARTInit(416);

	//Enable Internal Pullups on PORTC
	PORTC=0xFF;
	/* 
	Keep transmitting the Value of Local PORTC
	to the Remote Station.

	On Remote RX station the Value of PORTC
	sent over AIR will be latched on its local PORTC
	*/
	
	uint8_t data;
	while(1)
	{
		data=PINC;

		/* 
		Now send a Packet
		Packet Format is AA<data><data inverse>Z
		total Packet size if 5 bytes.
		*/

		//Stabilize the Tx Module By Sending JUNK data
		UWriteData('J');	//J for junk

		//Send 'A'
		UWriteData('A');

		//Send Another 'A'
		UWriteData('A');

		//Send the data;
		UWriteData(data);

		//Send inverse of data for error detection purpose
		UWriteData(~data);

		//End the packet by writing 'Z'
		UWriteData('Z');

		//Wait for some time
		_delay_loop_2(0);
		_delay_loop_2(0);
		_delay_loop_2(0);
		_delay_loop_2(0);
		
		//indicate Button works 
	}
}
Esempio n. 11
0
void SystemInit(void) // Power on variable initialization 
{
	USARTInit(UBRRVAL);
	rotate_Servo_Clockwise = 650; // 650 
	rotate_Servo_Counter_Clockwise = 850; // 850
	stop_Servo = 768; // 770 = stop point 
	stop_Time = 500; // Time servo rest between rotations
	CCW_rotate_Time = 420; // how far each rotation is 1/4 knob
	CW_rotate_Time = 421; // how far each rotation is 1/4 knob
	rotation_Count = 0; // 65500 
	Change_Baudrate(51); // 19200
	Command_Display(Clear_Screen);
	Command_Display(Go_Home);
	//Change_Baudrate(83); // 1200
	
}
Esempio n. 12
0
/***********************************************************************************
 * @prototype       void SystemInit(void)
 * @description     Initializes the device
 * @param           None
 * @return          None
 ***********************************************************************************/
void SystemInit(void)
{
    // Initialize GPIO and peripheral
    GPIOInit();

    // Initialize Timers
    Timer0Init();
	Timer1Init();

    // Initialize UART
    USARTInit(_BAUDRATE);
	
	// Initialize ADC
	ADC_Init();

	// Enable interrupts
    sei();
}
Esempio n. 13
0
void main()
{
  //Initialize USART with baud rate 9600
  USARTInit(9600);

  //Write intro text
  USARTWriteLine("***********************************************");
  USARTWriteLine("USART Test");
  USARTWriteLine("----------");
  USARTWriteLine("Type a character on keyboard");
  USARTWriteLine("it will reach the PIC MCU via the serial line");
  USARTWriteLine("PIC MCU will return the same character but ");
  USARTWriteLine("enclosed in a <>");
  USARTWriteLine("--");
  USARTWriteLine("For example if you type 'a' you will see <a>");
  USARTWriteLine("appear on serial terminal.");
  USARTWriteLine(" ");
  USARTWriteLine("This checks both way serial transfers.");
  USARTWriteLine("");
  USARTWriteLine("Copyright (C) 2008-2013");
  USARTWriteLine("www.eXtremeElectronics.co.in");
  USARTWriteLine("***********************************************");
  USARTGotoNewLine();
  USARTGotoNewLine();

  while(1)
  {
      //Get the amount of data waiting in USART queue
      uint8_t n= USARTDataAvailable();

      //If we have some data
      if(n!=0)
      {
          //Read it
          char data=USARTReadData();

          //And send back
          USARTWriteChar('<');
          USARTWriteChar(data);
          USARTWriteChar('>');
      }

  }
}
Esempio n. 14
0
int main (void) 
{
  uint32_t i;

SystemCoreClockUpdate();

  for ( i = 0; i < BUFSIZE; i++ )
  {
	UARTTxBuffer[i] = UARTRxBuffer[i] = 0x00;
  }

  /* To run USART test, reset at the slave side first, master will
  send a block of data first, if it's not in the continuous mode,
  master send a block of dummy data to clock in the data from the slave,
  on the slave side, it's ready to receive, once it's received a block
  of data, send the same data back to the master. Once the master receives
  the block of data from the slave. It verifies the result. */

  /* NVIC is installed inside USARTInit file. */
  USARTInit(9600, SLAVE_MODE);

  while ( !UARTBlockReceived );

  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( (UARTRxBuffer[i] != 0xAA) && ((i&0x1)==0x0) )
	{
	  while ( 1 );
	}
	if ( (UARTRxBuffer[i] != 0x55) && ((i&0x1)==0x1) )
	{
	  while ( 1 );
	}
	UARTTxBuffer[i] = UARTRxBuffer[i];			/* Copy to the transmit buffer. */
	UARTRxBuffer[i] = 0;	/* Clear the Rx buffer for next block if necessary. */
  }
  USARTSend( (uint8_t *)UARTTxBuffer, BUFSIZE );
  UARTBlockReceived = 0;
  
  while ( 1 );	/* Never exit from main for debugging purpose. */

}
Esempio n. 15
0
int main(void)
{
	uint8_t i, j;
	SysTick_Config(SystemCoreClock/1000); //1ms tick
	RCC_Init();
	USARTInit();
	LCD_Init();
	LED_Init();
	LED_On();
	LCD_Clear();

	//LCD_char(0, 0, 0);
	LCD_String("abcdefg",0,0);
	LCD_String("6543210",0,3);
	while(1){
		delay_ms(100);
		printf("done!\n\r");
		LED_Toogle();
	}
}
Esempio n. 16
0
int main(){

	DDRC|=(1<<EmissorFrontBig)|(1<<EmissorFrontSmall);
	DDRB&=~((1<<SensorFrontLeft)|(1<<SensorFrontRight));

	PORTC|=(1<<EmissorFrontBig)|(1<<EmissorFrontSmall);

	unsigned volatile short valueL,valueR;
	ADCInit();
	TIMER_init();
	USARTInit(51); //Just for testing
	
	while(1){
		distanceOpponentLeft=DistancePTLeft();
		USARTWriteChar(distanceOpponentLeft); //Just for testing
		distanceOpponentRight=DistanceRight();
		USARTWriteChar(distanceOpponentRight); // Just for testing
	}

	return 0;
}
Esempio n. 17
0
/**
 * Main.
 */ 
int main( void )
{
    prvSetupHardware();// set up peripherals etc 

    brewbotOutput(STIRRER, OFF);
    brewbotOutput(PUMP, OFF);

    USARTInit(USART_PARAMS1);

    printf("Hello!\r\n");

    lcd_init();

	menu_set_root(main_menu);

	pwm_init();

	heat_start_task();
	hops_start_task();
	brew_start_task();
    level_probe_init();

    xTaskCreate( vTouchTask, 
                 ( signed portCHAR * ) "touch", 
                 configMINIMAL_STACK_SIZE +1000, 
                 NULL, 
                 tskIDLE_PRIORITY+2,
                 &xTouchTaskHandle );
       
    hops_reset();

    /* Start the scheduler. */
    vTaskStartScheduler();
    
    printf("FAIL\r\n");

    /* Will only get here if there was insufficient memory to create the idle
       task. */
    return 0;
}
Esempio n. 18
0
void board_init(void)
{
	/* This function is meant to contain board-specific initialization code
	 * for, e.g., the I/O pins. The initialization can rely on application-
	 * specific board configuration, found in conf_board.h.
	 */
	scif_start_rc120M();
	scif_start_rc8M();
	
	//enable brownout detection
	scif_bod50_enable_irq(); //4.something volts
	
	//set cpu divide by 2^(1+1) = 4
	pm_set_clk_domain_div(AVR32_PM_CLK_GRP_CPU,1);
	//switch main clock source
	pm_set_mclk_source(PM_CLK_SRC_RC120M);
	//cpu frequency is now 30 MHz

	//set up pba, pbb, pbc. must be less than fcpu/4
	//cpu is divide by 4 --> need divide by 16.   2^(3+1) = 16
	pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBA,3);
	pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBB,3);
	pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBB,3);
	//120MHz / 16 = 7.5MHz

	//setup adc
	ADCInit();
	
	//setup millis()
	millis_init();
	
	//set up pwm 
	PWMInit();
	
	//setup usart
	USARTInit();
	
//	CANInit();
}
Esempio n. 19
0
void main()
{

	uint8_t i; //Clasical loop varriable
	
	uint8_t packet[5],data=0;

	//Initialize the USART with Baud rate = 2400bps
	USARTInit(UBRRVAL);   //USARTInit(416);

	//Enable Internal Pullups on PORTC
	DDRD = (1<<PIND7);
	cbi(PORTD,PD7); //LED OFF;
	DDRB = (1<<PINB0);
	
	//DDRC|=0xFF;	//All Output

	//Initialize the USART with Baud rate = 2400bps
//	USARTInit(416);

	/*
	Get data from the remote Tx Station
	The data is the value of PORTC on Remote Tx Board
	So we will copy it to the PORTC of this board.
	*/

	while(1)
	{
		//Wait for a packet
		while(!UDataAvailable());
		if(UReadData()!='A') continue;
		while(!UDataAvailable());
		if(UReadData()!='A') continue;
		
		while(UDataAvailable()!=3);

		//Get the packet
		for(i=2;i<5;i++)
		{
			packet[i]=UReadData();
		}

		//Is it ok?
		if(packet[2]!=((uint8_t)~packet[3])) continue;

		if(packet[4]!='Z') continue;

		//The packet is ok
		data=packet[2];

		//Now we have data put it to PORTC
		//PORTC=data;
        if(data == LEDON)
		{
			//Send_Packet(RADDR, LEDON);
			sbi(PORTD,PD7); //LED ON;
			cbi(PORTB,PB0); //LED OFF;
			delayms(100);
		}
		else
		{
			//send command to switch led OFF
			//Send_Packet(RADDR, LEDOFF);
			cbi(PORTD,PD7); //LED OFF;
			sbi(PORTB,PB0); //LED ON;
			delayms(100);
		}

	}
		

}
Esempio n. 20
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	int i = 0, j = 0;
	int addr;

	//usb atjungimo kintamasis
	bool usbDisabled = true;

	//adc variables
	float *result;
	char mockResult[600];
	char UARTTxPacket[100];
	static short ultrasoundPacketTxMultiplier = 0;
    static int ULTRASOUND_PACKET_COUNT = 100;

	//usart state machine switch
	uartSwitch = 'r';

	//USB buffer variables
    uint8_t buf[255],outstrg[100],inchar;
    uint8_t len;

    //dac variables
    uint16_t waveform[32];
    uint8_t continueReading = 1;
    uint8_t intCount = 0;
    uint8_t charCount = 0;
    bool bufferReadSuccessful = false;
	char tempString[4];

    int cs;
    volatile float a,b,elapsedtime,angle,radius,angleinc;

    RCC_ClocksTypeDef RCC_Clocks;

	// Initialize System and Setup clocks.
	SystemInit();
	SystemCoreClockUpdate();

	//ini ADC
	adcConfigure();

	//init USART
	USARTInit();

	USART_puts(USART2, "P_Cmd\n\n");
	//USARTSendByte();
	//USARTReadByte();

	/* SysTick end of count event each 40ms */
	RCC_GetClocksFreq(&RCC_Clocks);
	//SysTick_Config(RCC_Clocks.HCLK_Frequency /100);

	// Initialize FPU
	*((volatile unsigned long*)0xE000ED88) = 0xF << 20;

	// Initialize LEDs and User_Button on STM32F4-Discovery
    STM_EVAL_LEDInit(LED4);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED5);
    STM_EVAL_LEDInit(LED6);

    if(!usbDisabled){
		// USB Device Initialize
		USBD_Init(&USB_OTG_dev,
				USB_OTG_FS_CORE_ID,
				&USR_desc,
				&USBD_CDC_cb,
				&USR_cb);

		// Wait for USB connection goes live
		while (!gbUsbDeviceReady);

		// Clean USB RX buffer
		while(VCP_get_string(&buf[0]) == 0);

		// Output signon
		printf("USB serial DEMO\r\n");
		printf("test\n\r>");
    }
    //  Main loop
    while(1) {
    	//SPI (WITH MSP) STATE MACHINE
    	if(uartSwitchGet() != 'r')
    		switch(uartSwitchGet()){
    		case 't': //cmd tx packet
    			for (i=0;i<600;i++)
    				mockResult[i] = i;
    			for(i=0;i<100;i++)
    				UARTTxPacket[i] = mockResult[i+ultrasoundPacketTxMultiplier];
    			txDataArrayToMsp(UARTTxPacket);
    			uartSwitchSet('r');
    			break;
    		case 'e':
    			//Delay(1000);
    			USART_puts(USART2, "P_End\n\n");
    			ultrasoundPacketTxMultiplier = 0;
    			uartSwitchSet('r');
    			break;
    		case 'c': //cmd_packet_received_msg.
    			ultrasoundPacketTxMultiplier++;
    			if (ultrasoundPacketTxMultiplier >= 10)
    				uartSwitchSet('e'); //finish transmission, or...
    			else
    				uartSwitchSet('r'); // prepare for the next packet
    			break;
    		default:
    			break;
    		}
    	if(!usbDisabled){
			//USB COMM STATE MACHINE
			inchar = GetCharnw();

			if(inchar) {
				switch (inchar){
					case 'a':
						result = adcConvert();
						float* k;
						uint16_t j;
						//for (j=0;j<250;j++){
							for(k=result;k<result+10/*28000*/;k++){
								printf("%f \n",*k);
							}
					//	}
						break;
					case 'd':
						  intCount = charCount = bufferReadSuccessful = 0;
						  while(continueReading){
							for(i=0;i<rxbuflen;i++){
							  if(inbuf[i]!='d' && inbuf[i]!='e' && inbuf[i]!=' ' && continueReading == true){
								tempString[charCount]=inbuf[i];
								charCount++;
								if(charCount==4){
								  waveform[intCount] = 0;
								  for(j=0;j<4;j++)
								  waveform[intCount] += (int)(tempString[j]-'0')*pow(10,3-j);
								  intCount++;
								  charCount = 0;
								}
							  }
							  if(inbuf[i]=='e'||intCount == 32) { continueReading = 0; bufferReadSuccessful = true;}
							}
						  rxbuflen = 0;
						  char inchar = GetCharnw();
						  }
						if(bufferReadSuccessful)DAC_SignalsGenerate(&waveform);
						break;

					case 's':
						printf("\n\rF4 Discovery Test V0.55\n\r>");
						break;
					case 't':
						printf("\n\rDo 10000 circular interpolation calculations\n\r");
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						for(i=0; i<100000; i++) {
							a = radius * sinf(angle);
							b = radius * cosf(angle);
							angle += angleinc;
							}
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("timing delay=%d\n\r",TimingDelay4);
						printf("Single precision finished in %f seconds or %f usec/loop\n\r",elapsedtime,elapsedtime*10.0);
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						for(i=0; i<100000; i++) {
							a = radius * sinfp(angle);
							b = radius * cosfp(angle);
							angle += angleinc;
							}
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("timing delay=%d\n\r",TimingDelay4);
						printf("Single prec fp finished in %f seconds or %f usec/loop\n\r",elapsedtime,elapsedtime*10.0);
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						printf("angle=%f radius=%f angleinc=%f\n\r",angle,radius,angleinc);
						for(i=0; i<100000; i++) {
							a = radius * sin(angle);
							b = radius * cos(angle);
							angle += angleinc;
							}
						printf("timing delay=%d\n\r",TimingDelay4);
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("Double precision finished in %f seconds or %f usec/loop\n\r>",elapsedtime,elapsedtime*10.0);
						break;
					case 'f':
						printf("f\n\rTry float output: 1.234\n\r");
						a = 1.234;
						printf("a = %f\n\r",a);
						i = 35;
						printf("i = %d\n\r",i);
						a = 35.45;
						printf("a = %f\n\r",a);
						printf("a = %f\n\r",12.345);
						printf("a = %f\n\r",-12.345);
						printf("i = %d\n\r",i);
						break;
					case 'g':
						printf("d\n\rRCC_Clocks.HCLK_Frequency=%ld",RCC_Clocks.HCLK_Frequency);
						printf("\n\rDelay 2 second\n\r");
						Delay(200);
						printf("finished\n\r>");
						break;
					case CR:
						printf("\n\r>");
						break;
					default:
						printf("%c\n\r>",inchar);
						break;
					}
				}
    	}

        if (i == 0x100000) {
            STM_EVAL_LEDOff(LED4);
            STM_EVAL_LEDOff(LED3);
            STM_EVAL_LEDOff(LED5);
            STM_EVAL_LEDOff(LED6);
        	}
        if (i++ == 0x200000) {
        	i = 0;
            STM_EVAL_LEDOn(LED4);
            STM_EVAL_LEDOn(LED3);
            STM_EVAL_LEDOn(LED5);
            STM_EVAL_LEDOn(LED6);
        	}
    	}
}
Esempio n. 21
0
/**
 * Main.
 */ 
int main( void )
{
  prvSetupHardware();// set up peripherals etc

  USARTInit(USART_PARAMS1);

  xPrintQueue = xQueueCreate(150, sizeof(char *));
  if (xPrintQueue == NULL)
    {
      printf("Failed to make print queue\r\n");
      for (;;);
    }

  vParametersInit();
  lcd_init();
  menu_set_root(main_menu);

  vLEDInit();

  vI2C_Init();

  vMillInit();

  vMashPumpInit();

  vValvesInit();

  vDiagTempsInit();

  vHopsInit();

  vBoilInit();

  vStirInit();

  vCraneInit();

  hlt_init();

  vFlow1Init();

  vDiagPWMInit();

  vChillerPumpInit();

  vBoilValveInit();

  xTaskCreate( vSerialHandlerTask,
      ( signed portCHAR * ) "SerialTask",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY +4,
      &xSerialHandlerTaskHandle );


  xTaskCreate( vSerialControlCentreTask,
      ( signed portCHAR * ) "SerialctrlTask",
      configMINIMAL_STACK_SIZE + 100,
      NULL,
      tskIDLE_PRIORITY +2,
      &xSerialControlTaskHandle );

  xTaskCreate( vConsolePrintTask,
      ( signed portCHAR * ) "PrintTask",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY,
      &xPrintTaskHandle );

  xTaskCreate( vTouchTask,
      ( signed portCHAR * ) "touch    ",
      configMINIMAL_STACK_SIZE +400,
      NULL,
      tskIDLE_PRIORITY,
      &xTouchTaskHandle );

  // Create your application tasks if needed here
  xTaskCreate( vTaskDS1820Convert,
      ( signed portCHAR * ) "TempSensors",
      configMINIMAL_STACK_SIZE + 100,
      NULL,
      tskIDLE_PRIORITY,
      &xDS1820TaskHandle );

  xTaskCreate( vTaskLitresToBoil,
      ( signed portCHAR * ) "boil_litres",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY ,
      &xLitresToBoilHandle );

  xTaskCreate( vTaskLitresToMash,
      ( signed portCHAR * ) "mash_litres",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY ,
      &xLitresToMashHandle );

  xTaskCreate( vTaskHops,
      ( signed portCHAR * ) "hops    ",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY,
      &xHopsTaskHandle );

  xTaskCreate( vCheckTask,
      ( signed portCHAR * ) "check     ",
      configMINIMAL_STACK_SIZE +400,
      NULL,
      tskIDLE_PRIORITY,
      &xCheckTaskHandle );

  xTaskCreate( vTaskCrane,
      ( signed portCHAR * ) "Crane    ",
      configMINIMAL_STACK_SIZE + 200 ,
      NULL,
      tskIDLE_PRIORITY+1,
      &xCraneTaskHandle );

  xTaskCreate( vTaskBoilValve,
      ( signed portCHAR * ) "boilvalve",
      configMINIMAL_STACK_SIZE +200,
      NULL,
      tskIDLE_PRIORITY+1,
      &xBoilValveTaskHandle );


  //      xTaskCreate( vI2C_TestTask,
  //          ( signed portCHAR * ) "i2c_test",
  //          configMINIMAL_STACK_SIZE +400,
  //          NULL,
  //          tskIDLE_PRIORITY,
  //          &xI2C_TestHandle );

  xTaskCreate(  vTaskHLTLevelChecker,
      ( signed portCHAR * ) "hlt_level",
      configMINIMAL_STACK_SIZE +100,
      NULL,
      tskIDLE_PRIORITY,
      & xTaskHLTLevelCheckerTaskHandle );



  xTaskCreate(  vI2C_SendTask,
      ( signed portCHAR * ) "i2c_send",
      configMINIMAL_STACK_SIZE +500,
      NULL,
      tskIDLE_PRIORITY+2,
      & xI2C_SendHandle );


  /* Start the scheduler. */
  vTaskStartScheduler();



  printf("FAIL\r\n");

  /* Will only get here if there was insufficient memory to create the idle
       task. */
  return 0;
}