Пример #1
0
int main()
{


    /* Initializations and setup */

    init_platform();

    init_UART(&Uart1InstancePtr, UART1_DEVICE_ID);
    Set_DataFormat_UART(&Uart1InstancePtr, 115200, XUARTPS_FORMAT_8_BITS, XUARTPS_FORMAT_NO_PARITY, XUARTPS_FORMAT_1_STOP_BIT);

    init_UART(&Uart0InstancePtr, UART0_DEVICE_ID);
    Set_DataFormat_UART(&Uart0InstancePtr, 115200, XUARTPS_FORMAT_8_BITS, XUARTPS_FORMAT_NO_PARITY, XUARTPS_FORMAT_1_STOP_BIT);


    init_XADC_WIZ(CHANNEL_6,SINGLE_CHANNEL_MODE );


    init_GPIO_BUTTONS(&ButtonsInstancePtr, GPIO_BTNS_ID);
    init_GPIO_LEDS(&LedsInstancePtr, GPIO_LEDS_ID);

    init_GIC();



    xil_printf("Hello World\n\r");
    XGpio_DiscreteWrite(&LedsInstancePtr, 1, 0xA);


    while(1)
    {
    }
    return 0;
}
Пример #2
0
void main(void)
{	

  	WDTCTL = WDTPW+WDTHOLD;       	// Paramos el watchdog timer
  
  	init_botons();					// Iniciamos los botones y Leds.
    _enable_interrupt(); 			// Activamos las interrupciones a nivel global del chip
    init_LCD();						// Inicializamos la pantalla
    init_UCS();						//Inicialitzem UCS
    init_UART();					//Inicialitzem UART
  
  	halLcdPrintLine( saludo,linea,textstyle);
  	linea++;
  	sprintf(cadena,"bID = %d",bID); 
  	halLcdPrintLine( cadena,linea,textstyle);
  	
  	Encendre_LED();
  	TxPacket(0xFE, 2, 0x19);

  	do
   	{
    	P1OUT ^= 0x03; 
    	i = 25000;      
     		do 	{
    		i--;
    		}   	
    	while (i != 0);
   	}

  	while(1);
}
Пример #3
0
int main(void)
{
	DDRA = 0xFF;  //set port A as output
	DDRC = 0x00;  //set port C as input
	PORTA = 0x00; //clear output
	PORTC = 0xFF; //turn on pull-up resistors
	
	init_UART();  //initialize serial connections
	
	uint8_t value = 0; //set counter value to 0. number will be output in binary on 8 LEDs, so 8 bit unsigned integer is enough
	uint8_t DelayTime_ms = 2;  //set delay time to satisfy debounce need

	printf("ECET179_Lab6_Step7 DeBouncing with Software by setting delay time - Yizhou Zhang \n\r");
	printf("The delay time should be at least %d ms \n\r", DelayTime_ms);
	
	
	while(1)
	{
		//TODO:: Please write your application code
		PORTA = value;  //output counter value to LEDs
		
		while (PINC == 0)  //wait for a push button to be pressed
		{
		}
		printf("%d - 1\n\r", value); //delay to debounce, by printing current counter value. -1 represents contacting debounce
		
		value = value + 1;  //increment counter value
		
		while (PINC != 0)  //wait for the push button to be released
		{
		}
		printf("%d - 2\n\r",value); //delay to debounce, by printing current counter value. -2 represents releasing debounce
	}
}
Пример #4
0
/*---------------------------------------------------------------------------*/
void init(void) {
    init_PORT();
    init_TRIS();
    init_ANSEL();
    init_UART();
    init_SPI();
    init_TMR();
    init_OSC();
}
Пример #5
0
/* Functions */
int main(void) { 
	u32 OutputEnableTimeout;  

	init_SystemClock();	   //RCC config
	init_Discovery();	   //leds & user button
	init_TimeBase();	   //timebase & clock
	init_LCD();			   //HD44780 based display
	init_UART(&urt2,2);
	init_IO();

	
    /* program loop */		  //******************************************* main loop
	time.fast = actualTime() + FASTINTERVAL;
	time.slow = actualTime() + SLOWINTERVAL;

	while (1) {

	//realtick:
	if(gValues.filter.output){
		//output enable, timeout restart
		OutputEnableTimeout = actualTime() + OUTPUT_TIMEOUT;
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, (BitAction)1);
	}else if (timeElapsed(OutputEnableTimeout)){
		//output disable after timeout
		GPIO_WriteBit(GPIOC, GPIO_Pin_9, (BitAction)0);
	}

	
	if(timeElapsed(time.fast)){
		time.fast += FASTINTERVAL;
		//fasttick
		fast_Tick();
	
	}


	if(timeElapsed(time.slow)){
		time.slow += SLOWINTERVAL;
		//slowtick
		LCD_periodic_update();
		slow_Tick();

	}



	//COMM_DESC * PC_com = &urt2.parent;


	
	/*Ticks*/
	//PC_com->Tick(PC_com);
	//urt2.Tick(&urt2.parent);

	}  //end while
}  //end main()
Пример #6
0
void main() {
    TRISC = 0b00000000; // portC : output
    LATC = 0b00000000; // portC = 0
    init_UART();
    init_I2C();
    //init_GYRO();
    init_ACC();
    LED_RED_On();
    LED_GREEN_On();

    while (1) {
    };

}
Пример #7
0
/*! \brief	Initializes all configuration variables.
*/
void Configuration::init() {
	// MISC
	Oscillator_Freq = 16000000;		//Oscillator frequency in Hz
	CPUCLK = Oscillator_Freq;
	PBACLK = Oscillator_Freq;
	PWMCLK = Oscillator_Freq;
	ADCCLK = Oscillator_Freq;
	
	init_Timer();
	init_PWM();
	init_Motor();
	init_Sensors();
	init_UART();
	init_StatusLEDs();
}
Пример #8
0
int main()
{
	init_UART();
	while(1)
	{
		if(flag==1)
		{
			ES=0;
			flag=0;
			SBUF=i;
			while(!TI);
			TI=0;
			ES=1;
		}
	}
	return 0;
}
Пример #9
0
int main() {
    char c;
    int count;
    init_clock_and_pins();
    AD1PCFGL = 0xFFFF; // turn off ADC
    init_UART();
    QEI_enable(1, 0xFFFF);
    QEI_enable(2, 0xFFFF);
    QEI_reset(1);
    QEI_reset(2);

    while (1) {
        // wait for data to be received.
        while (!U1STAbits.URXDA);
        c = U1RXREG;
        switch (c) {
            case RESET:
                QEI_reset(1); // reset QEI 1
                QEI_reset(2); // reset QEI 2
                break;
            case ENABLE:
                QEI_enable(1, 0xFFFF); // enable QEI 1, threshold=65,535
                QEI_enable(2, 0xFFFF); // enable QEI 2, threshold=65,535
                break;
            case DISABLE:
                QEI_disable(1); // disable QEI 1
                QEI_disable(2); // disable QEI 2
                break;
            case READ:
                //printf("%u\n", QEI_read(1)); // print QEI 1 value to UART
                //printf("%u\n", QEI_read(2)); // print QEI 2 value to UART
                count=QEI_read(1);
                U1TXREG=count>>8;
                U1TXREG=MASK&&count;
                break;
            case TEST:
                printf("%c", 'y'); // Send 'y' over UART
                //IFS3bits.QEI1IF = 1; // Set interrupt flag to 1
                break;
        }
    }
}
Пример #10
0
int main(void)
{
	init_UART();  //initialize serial communication to CoolTerm
	init_ADC();  //initialize ADC
	
	uint8_t ADC_0;  //reading from ADC0
	uint8_t ADC_1;  //reading from ADC1
	uint8_t ADC_2;  //reading from ADC2
	
	uint8_t i;
	uint8_t j;
	uint8_t k;
	
	DDRB = 0b11110000;  //T0A T1B T1A T2A
	DDRG = 0b00100000;  //T0B
	//DDRC = 0x00;  //configure PortC as input
	//PORTC = 0xFF;  //turn on pull-up resisotrs of PortC
	//DDRE = DDRE | 0b00111000;  //T3C T3B T3A
	
	//channel0
	//TCCR0A = 0x00;  //clear registers
	//TCCR0B = 0x00;  //clear registers
	TCCR0A = TCCR0A | 0b11110000;  //clear OC0A on compare match
	TCCR0A = TCCR0A | 0b00000011;  //set WGM01& WGM00 to configure FAST PWM
	TCCR0B = TCCR0B & 0x11110111;  //clear WGM02 to configure FAST PWM
	TCCR0B = TCCR0B | 0x00000001;  //no prescaling
	
	//channel2
	//TCCR2A = 0x00;  //clear registers
	//TCCR2B = 0x00;  //clear registers
	TCCR2A = TCCR2A | 0b11110000;  //clear OC0A on compare match
	TCCR2A = TCCR2A | 0b00000011;  //set WGM01& WGM00 to configure FAST PWM
	TCCR2B = TCCR2B & 0x11110111;  //clear WGM02 to configure FAST PWM
	TCCR2B = TCCR2B | 0x00000001;  //no prescaling
	
	
	while(1)
	{
		//TODO:: Please write your application code
		do 
		{
			do 
			{
				do 
				{
					OCR0A = i;
					i++;
					//printf("i = %d\n\r",i);
				} while (i < 255);
				OCR0B = j;
				j++;
				//printf("j = %d\r\n",j);
			} while (j < 254);
			OCR2A = k;
			k++;
			//printf("k = %d\n\r",k);
		} while (k<254);
		k = 0;
		j = 0;
		i = 0;
	}
}
Пример #11
0
int main(void)
{
    /* Initialize Interfaces */
    if(PINB & (1<<SEL2)){   //SEL2 not installed, modeA
        init_StepDir();
        //init_pwm();
    } else {                //SEL2 installed, modeB
        init_SPI();
        init_UART(12,1);    //For 1MHz testing, change to 14.7456Mhz
        init_I2C();
    }
    //init_I2C();
    //init_SPI();
    //init_UART(95,0);    /* Run UART at 9600 baud */
    //init_StepDir();
    init_stepper();
    init_chopper();
    sei();
    int8_t motor_state = 0;
    motor_enable = WAVE;
    while(1)
    {
        if(motor_enable == FULL){
            if(desired_step_cnt < 0){   //backwards
                if(motor_state == 0) normstep4();
                if(motor_state == 2) normstep1();
                if(motor_state == 4) normstep2();
                if(motor_state == 6) normstep3();
                motor_state -= 2;
                if(motor_state < 0) motor_state = 6;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 0) normstep2();
                if(motor_state == 2) normstep3();
                if(motor_state == 4) normstep4();
                if(motor_state == 6) normstep1();
                motor_state += 2;
                if(motor_state > 6) motor_state = 0;
                desired_step_cnt--;
            }
        } else if(motor_enable == HALF){
            if(desired_step_cnt < 0){
                if(motor_state == 0) halfstep8();
                if(motor_state == 1) halfstep1();
                if(motor_state == 2) halfstep2();
                if(motor_state == 3) halfstep3();
                if(motor_state == 4) halfstep4();
                if(motor_state == 5) halfstep5();
                if(motor_state == 6) halfstep6();
                if(motor_state == 7) halfstep7();
                motor_state--;
                if(motor_state < 0) motor_state = 7;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 0) halfstep2();
                if(motor_state == 1) halfstep3();
                if(motor_state == 2) halfstep4();
                if(motor_state == 3) halfstep5();
                if(motor_state == 4) halfstep6();
                if(motor_state == 5) halfstep7();
                if(motor_state == 6) halfstep8();
                if(motor_state == 7) halfstep1();
                motor_state++;
                if(motor_state > 7) motor_state = 0;
                desired_step_cnt--;
            }            
        } else if(motor_enable == WAVE){
            if(desired_step_cnt < 0){
                if(motor_state == 1) wavestep4();
                if(motor_state == 3) wavestep1();
                if(motor_state == 5) wavestep2();
                if(motor_state == 7) wavestep3();
                motor_state -= 2;
                if(motor_state < 1) motor_state = 7;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 1) wavestep2();
                if(motor_state == 3) wavestep3();
                if(motor_state == 5) wavestep4();
                if(motor_state == 7) wavestep1();
                motor_state += 2;
                if(motor_state > 7) motor_state = 1;
                desired_step_cnt--;
            }
        }
        _delay_ms(100);//Change according to speed input
//        normstep1();
//        _delay_ms(100);
//        normstep2();
//        _delay_ms(100);
//        normstep3();
//        _delay_ms(100);
//        normstep4(); 
//        _delay_ms(100);          
//        halfstep1();
//        _delay_ms(100);
//        halfstep2();
//        _delay_ms(100);
//        halfstep3();
//        _delay_ms(100);
//        halfstep4();
//        _delay_ms(100);
//        halfstep5();
//        _delay_ms(100);
//        halfstep6();
//        _delay_ms(100);
//        halfstep7();
//        _delay_ms(100);
//        halfstep8();
//        _delay_ms(100);
//        wavestep1();
//        _delay_ms(100);
//        wavestep2();
//        _delay_ms(100);
//        wavestep3();
//        _delay_ms(100);
//        wavestep4();
//        _delay_ms(100);
    }
    return 0;
}
Пример #12
0
int main (void){
	//Start UART
	init_UART();
	stdout = &uart_tx;
	stdin = &uart_rx;
	
	//Start ADC
	init_ADC();

	//Set pins for display as output
	//Digit 1
	DDRD |= (1 << PD5); //A
	DDRD |= (1 << PD6); //B
	DDRD |= (1 << PD7); //C
	DDRB |= (1 << PB0); //D
	
	//Digit 2
	DDRC |= (1 << PC1); //A
	DDRC |= (1 << PC2); //B
	DDRC |= (1 << PC3); //C
	DDRC |= (1 << PC4); //D

	//Lights Pin Output
	DDRC |= (1 << PC5); 
 
	//Start/Stop Button
	DDRB &= ~(1 << PB1); //Start button input	
	DDRB &= ~(1 << PB2); //Stop button input

	//Buzzer Pin
	DDRD |= (1 << PD2); //Output

   	int first_digit = 9;
	int second_digit = 10;    
    	static long reading;
	static bool btnStart;

	//Blink display to let me know everything is good!
	displayBlink(5);
	while(1) {
		printf("Raw Reading: %d\t",read_ADC(0,&reading));
		long mapped_reading = mapRange(0,1023,0,99,reading);
		printf("Mapped Reading: %d\n",mapped_reading);
		display_Selection(mapped_reading);
		if(PINB & (1 << PB1) && mapped_reading > 0 ){ //If the Start button gets pressed then
			displayBlink(2);
			int count = 0;
			_delay_ms(1000);
			PORTC |= (1 << PC5);
			for(count = mapped_reading;count >= 0;count--){
				//Count Backwards from that number	
				//Check for stop button quit if set
				if(PINB & (1 << PB2))
					break;

				uint8_t fdigitm = count / 10;
				uint8_t sdigitm = count % 10;
				firstDisplay(fdigitm);
				secondDisplay(sdigitm);
				printf("UV Lights on for: %d more secs...\n",count);
				_delay_ms(1000);
			}	
			PORTC &= ~(1 << PC5);
			//displayBlink(5);
			alarmSound(2);
			displayBlink(2);
		}
	}
}
Пример #13
0
int main(void)
{
  //! set the power reduction register to minimize current consumption
  init_power_reduction();
  //! set CPU clock to 32MHz and enables the DFLL32MHz
  clock_init();           
  //! initialize the LCD module
  init_lcd();
  //! display all the segments in LCD
  lcd_show_all();        
  //! initialize the GPIO pins
  init_ioport();
  //! initializes the UART
  init_UART();
  //! load the calibration data from flash
  ADC_CalibrationValues_Load(&ADCA);
  //! get the ADC offset value
  get_offset();
  //! initialize the ADC
  init_ADC();
  //! load the calibration value from eeprom
  init_eeprom();
  //! initilize RTC to external clock and 1 sec interrupt
  rtc_init();
  //! initilize the timer
  init_timer();  

  while(1)
    {
      //! rtc_flag is set
      if (rtc_flag == 1)
      {
        //! perform the calculation of metering paramters
        calculate();
        //for debugging
        if(cover_open_flag ==1)
        PORTD.OUTTGL = PIN3_bm;
        //TCC1.CTRLA = ( TCC1.CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_DIV64_gc;
        TCC1.INTCTRLA = (TCC1.INTCTRLA & ~(TC1_OVFINTLVL_gm | TC1_ERRINTLVL_gm))|TC1_OVFINTLVL0_bm;
        //! if power on detected
        if(power_status_flag == POWER_ON_DETECTED) 
        {
          //! change the clock frequency to 32MHz
          CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );
          //! switch off the battery
          PORTD.PIN4CTRL	= PORT_OPC_WIREDANDPULL_gc;
          //PORTD.OUTSET	= PIN4_bm;
          //! initialize gpio pins
          init_ioport();
          //! change the sleep mode to ideal sleep
          SLEEP.CTRL = (SLEEP.CTRL & ~SLEEP_SMODE_gm)| SLEEP_SMODE_IDLE_gc;
          //! enable ADC & Timer
          ADC_Enable(&ADCA);
          TCC1.CTRLA = ( TCC1.CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_DIV64_gc;
          //! initialize lcd module
          init_lcd();
          //! update power status flag
          power_status_flag = POWERED_UP;
        }
        //! update the LCD display
        lcd_disp_key();
        tamper_check();
        if( active_power[0] > max_demand )
        {
          max_demand = active_power[0];
        }
        //! check for calibration flag and proceed and call the appropriate calibration funtion
        if(calibration_flag != 0)
        {
          //! checking the calibration flag for calibrating the date & time
          if (calibration_flag == 1)
          { calibrate_time_date();  }
          //! checking the calibration flag for calibrating the voltage
          else if (calibration_flag == 2)
          { calibrate_voltage();    }
          //! checking the calibration flag for calculating the offset value
          else if (calibration_flag == 3)
          { calibrate_no_load();    }
          //! checking the calibration flag for calculating the phase angle variation
          else if (calibration_flag == 4)
          { calibrate_phase();	    }
          //! checking the calibration flag for calculating watt varition
          else if (calibration_flag == 5)
          { calibrate_watt();       }
          else if (calibration_flag == 6)
          //! checking the calibration flag for calibrating the current            
          { calibrate_current();    }
        }
        rtc_flag = 0;
        __watchdog_reset();
      }
      //! checking the power_status, if power off is detected
      else if(power_status_flag == POWER_OFF_DETECTED)
      {
        //! switch on the battery
        PORTD.PIN4CTRL	= PORT_OPC_WIREDAND_gc;
        //PORTD.OUTCLR  = PIN4_bm;
        //! change the sleep mode to power save mode
        SLEEP.CTRL = (SLEEP.CTRL & ~SLEEP_SMODE_gm)| SLEEP_SMODE_PSAVE_gc;  
        //! switch off the LCD
        lcd_command(LCD_COMMAND,0x02);
        //! change reset the gpio pin
        facilitatePowersaving();
        //! disable the ADC
        ADC_Disable(&ADCA);
        //! disable the timer
        TCC1.CTRLA = ( TCC1.CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
        //! clear all the varilable used in for energy calculation
        meter_flush();
        //! reduce the cpu clock frequency to minimize power consumption
        CLKSYS_Prescalers_Config( CLK_PSADIV_64_gc, CLK_PSBCDIV_1_1_gc );
        //! update power status flag
        power_status_flag = POWER_OFF;
        __watchdog_reset();
      }
      //! goes to sleep
      SLEEP.CTRL |=  SLEEP_SEN_bm;
      asm("sleep");
    }
}