Example #1
0
int main(void) {

  WDTCTL = WDTPW + WDTHOLD;	// Stop WDT
  /*Halt the watchdog timer
      According to the datasheet the watchdog timer
      starts automatically after powerup. It must be
      configured or halted at the beginning of code
      execution to avoid a system reset. Furthermore,
      the watchdog timer register (WDTCTL) is
      password protected, and requires the upper byte
      during write operations to be 0x5A, which is the
      value associated with WDTPW.*/

  initLEDs();		//Setup LEDs

  BCSCTL3 |= LFXT1S_2;	//Set ACLK to use internal VLO (12 kHz clock)

  TACTL = TASSEL__ACLK | MC__UP;	//Set TimerA to use auxiliary clock in UP mode
  TACCTL0 = CCIE;	//Enable the interrupt for TACCR0 match
  TACCR0 = 11999;	/*Set TACCR0 which also starts the timer. At
				12 kHz, counting to 12000 should output
				an LED change every 1 second. Try this
				out and see how inaccurate the VLO can be */
			
  WRITE_SR(GIE);	//Enable global interrupts

  while(1) {
	//Loop forever, interrupts take care of the rest
  }
}
Example #2
0
int main(void)
{
    SYSTEMConfigPerformance(10000000);
    initTimer1();
    initSW2();
    initLEDs();
    enableInterrupts();
    state = led1;

    while(1)
    {
        //TODO: Using a finite-state machine, define the behavior of the LEDs
        //Debounce the switch
        switch(state) {
        case led1:
            turnOnLED(1);
            stateNext = led2;
            break;

        case led2:
            turnOnLED(2);
            stateNext = led1;
            break;

        case deBounce1:
            delayUs(10000);
            break;
        case deBounce2:
            delayUs(10000);
            break;
        }
    }

    return 0;
}
Example #3
0
int main(void) {
	initButton();
	initLEDs();
	init_USART1(54000); // initialize USART1 @ 9600 baud

	//USART_puts(USART1, "Init complete! Hello World!&"); // just send a message to indicate that it works
	byte bull[5];
	//Set lowest power parameter
	bull[0]=0x43;
	bull[1]=0x78;
	bull[2]=0x1E;
	bull[3]=0x09;
	bull[4]=7;

	USART_puts(USART1, bull);
	
	//Set 50000bps
	bull[0]=0x43;
	bull[1]=0x78;
	bull[2]=0x1E;
	bull[3]=0x08;
	bull[4]=50;
	USART_puts(USART1, bull);

	while (1){

		char buff[4]="*&*";

		USART_puts(USART1, buff);
	}
}
Example #4
0
/******************************************************************************
 * Function:        void UserInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This routine should take care of all of the demo code
 *                  initialization that is required.
 *
 * Note:            
 *
 *****************************************************************************/
void UserInit(void)
{
	unsigned char i;
    
    initLEDs();

    // 	 Initialize the arrays
	for (i=0; i<sizeof(USB_Out_Buffer); i++)
    {
		USB_Out_Buffer[i] = 0;
    }
    
    ReadMessageFromEEPROM();

    testLEDs();
    
	NextUSBOut = 0;
	LastRS232Out = 0;
	lastTransmission = 0;
	nextProcessState = P_VERSION;
	RS232cp = 0;
	// POV
	space = 0;
	POV_curPos = 0;
	POV_curLetter = 0;
	
	OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_256);
    WriteTimer0(POV_TIMER);

}//end UserInit
Example #5
0
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initTimer1();



    while(1) {

        switch(state) {
        case led1:
            LATDbits.LATD0 = ON;
            LATDbits.LATD1 = OFF;
            LATDbits.LATD2 = OFF;
            break;
        case led2:
            LATDbits.LATD0 = OFF;
            LATDbits.LATD1 = ON;
            LATDbits.LATD2 = OFF;
            break;
        case led3:
            LATDbits.LATD0 = OFF;
            LATDbits.LATD1 = OFF;
            LATDbits.LATD2 = ON;
            break;
        }

    }

    return 0;
}
Example #6
0
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    initLEDs();
    initTimer1();
    
    while(1){
        switch(state) {
            case INIT:
                next_state = LED_0;
                break;
            case LED_0:
                turnOnLED(0);
                next_state = LED_1;
                break;
            case LED_1:
                turnOnLED(1);
                next_state = LED_2;                
                break;
            case LED_2:
                turnOnLED(2);
                next_state = LED_0;
                break;
        }
    }
    
    return 0;
}
Example #7
0
File: main.c Project: yali101/LAB0
int main() {
    //SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initTimer1();
    
    while(1){
        //TODO: Implement a state machine to create the desired functionality
        
        switch(state){
            case led1:  //LED1 is on
                LATDbits.LATD0 = ON;
                LATDbits.LATD1 = OFF;
                LATDbits.LATD2 = OFF;
                break;
            case led2:  //LED2 is on
                LATDbits.LATD0 = OFF;
                LATDbits.LATD1 = ON;
                LATDbits.LATD2 = OFF;
                break;
            case led3:  //LED3 is on
                LATDbits.LATD0 = OFF;
                LATDbits.LATD1 = OFF;
                LATDbits.LATD2 = ON;
                break;
        } 
    }
    return 0;
}
Example #8
0
int main() {
    
    //This function is necessary to use interrupts. 
    enableInterrupts();
    initSwitch1();
    initLEDs();
    
    while(1){
        switch (state){
            case led1:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=2;
                    wait2();
                    state = debounceRelease; 
                }
                break; 
            case led2:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=3;
                    wait2();
                    state = debounceRelease;
                }
                break; 
            case led3:
                if(PORTDbits.RD7 == 0){
                    delayMs();
                    i=1;
                    wait2();
                    state = debounceRelease;   
                }
                break; 
        }
        
        if(state == debounceRelease){
            if(PORTDbits.RD7 == 1){
                if(IFS0bits.T2IF == 1){ 
                i=i+1;
                if(i == 4) i=1; 
                turnOffTimer2();
                } 
                delayMs();
                if(i == 3){ 
                    turnOnLED(3);
                    state = led3;  
                }
                else if(i == 1){
                    turnOnLED(1);
                    state = led1;
                }
                else { 
                    turnOnLED(2);
                    state = led2; 
                }
            }       
        }
    }
    return 0;
}
Example #9
0
void pio_init()
{
	
	// Setup XT1 and XT2
	XT1_XT2_PORT_SEL |= XT1_ENABLE;

	// Init device clock
	initClk();
	
	//init Leds
	initLEDs();
	
	// P2.3 - WLAN enable
	WLAN_EN_OUT &= ~WLAN_EN_PIN;                 
	WLAN_EN_DIR |= WLAN_EN_PIN;

	// P2.3 - SPI IRQ enable
	SPI_IRQ_DIR &= ~SPI_IRQ_PIN;                 

	// Port initialization for SPI operation
	SPI_SEL |= SPI_CLK + SPI_SOMI + SPI_SIMO;
	SPI_DIR |= SPI_CLK + SPI_SIMO;
	SPI_REN |= SPI_SOMI;                                   // Pull-Ups on RF Interface SOMI
	SPI_OUT |= SPI_SOMI;                                   
	
	RF_CS_SEL &= ~RF_CS;
	RF_CS_OUT |= RF_CS;
	RF_CS_DIR |= RF_CS;
	
	// Globally enable interrupts
	__enable_interrupt();
}
void main(void) {

	WDTCTL = WDTPW + WDTHOLD;           // Stop watchdog timer

	// Set both clocks to 1MHZ
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL = CALDCO_1MHZ;

	// Initialize ports & hardware
	initLEDs();
	initKeypad();
	initPWM_TA0();
	initPWM_TA1();

	__bis_SR_register(GIE);				// Enable interrupts

	while(1){
		unsigned int i, j;
		for (i = 0; i < 4; i ++){
			// find row of pressed button
			P1OUT |= muxRow[i];		// set P1OUT to current test
			for (j = 0; j < 4; j ++) {
				// find column of pressed button
				if ((P2IN & 0xFF) == cols[j]){
					// yay! we found the button
					cmdVal = commands[j][i];
					moveServos(cmdVal);
				}
			}// end for(col)
			P1OUT &=~ muxRow[i];	// reset P1OUT for next test
		} // end for(row)
	} // end while(1)
} // end main()
Example #11
0
void main(void) {

	initClocks();
	initUARTSdCard();
	initUARTBot();

	initLEDs();
	//initLEDWait();	// Sleep for 5 sec: 5*8MHz.
	initUartBuffer();

	_EINT();

	/*initCorrect = checkSDCardStatus(); // Enables/Disables the main while loop

	if (initCorrect) {
		StartUpSequence();
	} else {
		blinkLED8(1);
	}*/
	initCorrect = 1;

	OperationMode = Listening;

	P1OUT &= ~BIT4;                           //
	P1IES &= ~BIT4;                           // P1.4 Lo/Hi edge
	P1IE |= BIT4;                              // P1.4 interrupt enabled
	P1IFG &= ~BIT4;                           // P1.4 IFG cleared


	while(initCorrect){

		switch (OperationMode) {

		case Broadcasting:
			broadCast();
			OperationMode = Listening;
			break;

		case Counting:
			break;

		case Listening:
			__bis_SR_register(LPM3_bits + GIE);     // Enter LPM4 w/interrupt
			PJOUT ^= BIT3;                          // P1.0 = toggle
			//P1IE |= BIT4;                         // P1.4 interrupt enabled
			timeKeeper();
			PJOUT ^= BIT3;
			break;

		case Saving:
			savingToSdCard();
			break;

		default:
			OperationMode = Listening;
			break;
		}
	}
}
Example #12
0
void main() {
  initLEDs(); // initialisation of strand, as defined in ws2812b.h --> port pin needs to be set there ! ! !
  setRGB(0,0,0xFF0000); // pixel 0,0 as red
  setRGB(1,0,0x00FF00); // pixel 1,0 as green 
  setRGB(2,0,0x0000FF); // pixel 2,0 as blue
  setMaxBrightness(5); // dim down to 5 = low brightness
  showLEDs(); // display all color values now
}
Example #13
0
void main() {
  initLEDs(); // initialisation of strand, as defined in ws2812b.h --> port pin needs to be set there ! ! !
  setMaxBrightness(10); // relatively low, good for the eyes
  // repeat endlessly for blinking:
  while (1) {				 
    setRGB(0,0,0xFF9922);showLEDs(); // "on" -  some color
    _delay_ms(200);									 // pause a little
    setRGB(0,0,0x000000);showLEDs(); // "off" - might as well use clearLEDs();
    _delay_ms(500);									 // pause a little more
  }
}
Example #14
0
File: board.c Project: Gabbeh/CHARM
void pio_init()
{
	// Init the device with 24MHz DCOCLCK.
	initClk();
	
	// Enable switches
	// P4.0 and P4.1 are configured as switches
	// Port 4 has only two pins    
	P4OUT |= BIT0;                      // Configure pullup resistor  
	P4DIR &= ~(BIT0);                  // Direction = input
	P4REN |= BIT0;                     // Enable pullup resistor
	P4IES |= (BIT0);                   // P4.0 Hi/Lo edge interrupt  
	P4IFG = 0;                         // P4 IFG cleared
	P4IE = BIT0;                       // P4.0 interrupt enabled
	
	// Enable First Time Config Prefix changing jumper
	// To detect if pulled high by VCC
	
	// P3.3 is our High signal
	P3DIR |= BIT3;
	P3OUT |= BIT3;
	
	// P3.2 Configure pulled low and will detect a hi/low transition
	
	P3DIR &= ~(BIT2);             // P3.2 As Input
	P3OUT &= ~(BIT2);             // P3.2 With Pulldown
	P3REN |= BIT2;                // P3.2 Enable Pulldown
	P3IES &= ~(BIT2);             // P3.2 Lo/Hi edge interrupt
	P3IFG &= ~(BIT2);             // P3.2 IFG cleared
	P3IE |= BIT2;                 // P3.2 interrupt enabled
	
	// P4.1 - WLAN enable full DS
 	WLAN_EN_PORT_OUT &= ~WLAN_EN_PIN;
	WLAN_EN_PORT_DIR |= WLAN_EN_PIN;
	WLAN_EN_PORT_SEL2 &= ~WLAN_EN_PIN; 
	WLAN_EN_PORT_SEL &= ~WLAN_EN_PIN;
	
	
	// Configure SPI IRQ line on P2.3
	SPI_IRQ_PORT_DIR  &= (~SPI_IRQ_PIN);	
	SPI_IRQ_PORT_SEL2 &= ~SPI_IRQ_PIN; 
	SPI_IRQ_PORT_SEL &= ~SPI_IRQ_PIN;
	
	
	// Configure the SPI CS to be on P1.3
	SPI_CS_PORT_OUT |= SPI_CS_PIN;
	SPI_CS_PORT_DIR |= SPI_CS_PIN;
	SPI_CS_PORT_SEL2 &= ~SPI_CS_PIN; 
	SPI_CS_PORT_SEL &= ~SPI_CS_PIN;
	
	__delay_cycles(12000000);
	
	initLEDs();
}
Example #15
0
int main(void)
{
    enableInterrupts();
    initLEDs();
    initSW2();
    initTimer2();
    updateLEDState();
    
    
    while(1)
    {
        switch (currentState)
        {
            case wait:
                if(buttonState==risingEdge)//button is pressed
                {
                    
                    currentState=debouncePress;
                    buttonState=Idle;
                }
//                if(IFS1bits.CNDIF==1)
//                //if(PORTDbits.RD6==0) //!!! use change notifications, not polling
//                {
//                    currentState=debouncePress;
//                }
                break;
            case debouncePress:
                delayUs(50);
                currentState=waitForRelease;
                break;
            case waitForRelease:
                //!!! use change notifications, not polling
                if(buttonState==fallingEdge)//button released
                {
                    currentState=debounceRelease;
                    buttonState=Idle;
                }
//                if(IFS1bits.CNDIF==1)
//                //if(PORTDbits.RD6==1)//released
//                {
//                    currentState=debounceRelease;
//                }
                break;
            case debounceRelease:
                delayUs(50);
                updateLEDState();
                currentState=wait;
                break;
        }
        
    }
    
    return 0;
}
Example #16
0
int main() {
    
    //This function is necessary to use interrupts. 
    enableInterrupts();
    
    //initialize the switch, all three LEDs, and the main timer
    initSwitch1();
    initLEDs();
    initTimer2();
    initTimer1();
    
    stateCurrent = wait; //set the starting state to no led's on
    
    while(1){
        if(PORTDbits.RD6 != 0){
            TMR1 = 0;
            T1CONbits.TON = 0;
            if(status == 1){
                status = 0;
                stateCurrent = stateNext;
            }
            switch(stateCurrent){
            case(wait):
                turnOnLED(0);
                stateNext = led1;
                break;
            case(led1):
                turnOnLED(1);
                stateNext = led2;
                break;
            case(led2):
                turnOnLED(2);
                stateNext = led3;
                break;
            case(led3):
                turnOnLED(3);
                stateNext = led1;
                break;
            default:
                stateCurrent = led1;
                break;
            }
        }
        else if(PORTDbits.RD6 == 0){
            if(status == 0){
                T1CONbits.TON = 1;
                status = PRESSED; //button was pressed
            }
        }
    }
    
    return 0;
}
Example #17
0
//*****************************************************************************
//
//! pio_init
//!
//! \param  none
//!
//! \return none
//!
//! \brief  Initialize the board's I/O
//
//*****************************************************************************    
void pio_init()
{
    initClk();
    // Enable switches
    // P4.0 and P4.1 are configured as switches
    // Port 4 has only two pins    
    P4OUT |= BIT0;                     // Configure pullup resistor
    P4DIR &= ~(BIT0);                  // Direction = input
    P4REN |= BIT0;                     // Enable pullup resistor
    P4IES |= (BIT0);                   // P4.0 Hi/Lo edge interrupt  
    P4IFG = 0;                         // P4 IFG cleared
    P4IE = BIT0;                       // P4.0 interrupt enabled
    
    // Enable Smart Config Prefix changing jumper
    // To detect if pulled high by VCC
    
    // P3.3 is our High signal
    P3DIR |= BIT3;
    P3OUT |= BIT3;
        
    // P3.2 Configure pulled low and will detect a hi/low transition
    P3DIR &= ~(BIT2);             // P3.2 As Input
    P3OUT &= ~(BIT2);             // P3.2 With Pulldown
    P3REN |= BIT2;                // P3.2 Enable Pulldown
    P3IES &= ~(BIT2);             // P3.2 Lo/Hi edge interrupt
    P3IFG &= ~(BIT2);             // P3.2 IFG cleared
    P3IE |= BIT2;                 // P3.2 interrupt enabled

    
    // P4.1 - WLAN enable full DS
    P4OUT &= ~BIT1;
    P4DIR |= BIT1;
    P4SEL1 &= ~BIT1; 
    P4SEL0 &= ~BIT1;
    
    // Configure SPI IRQ line on P2.3
    P2DIR  &= (~BIT3);	
    P2SEL1 &= ~BIT3; 
    P2SEL0 &= ~BIT3;
    
    // Configure the SPI CS to be on P1.3
    P1OUT |= BIT3;
    P1DIR |= BIT3;
    P1SEL1 &= ~BIT3; 
    P1SEL0 &= ~BIT3;
    
	busyWait(50);
    
    // Initialize LEDs
    initLEDs();
}
Example #18
0
int main(void) {
    hardwareInit();
    initLEDs();
    setOutputBit(&kOrangeLED, 1);

    sei();

    USB_Init();

    while (1) {
        HID_Device_USBTask(&mouseHIDInterface);
        USB_USBTask();
    }
}
Example #19
0
int main(void) {
    initLEDs();
    initButtons();

    while (1) {
        if (isButtonPressed(SB2)) {
            turnOffLEDs();
        } else {
            checkLEDsSettingButtons();
        }
        _delay_ms(50);
    }
    return 0;
}
Example #20
0
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initTimer1();
    
    while(1){

        //TODO: Implement a state machine to create the desired functionality
        
    }
    
    return 0;
}
Example #21
0
int main() {
    
    initLEDs();
    initSW1();
    
    enableInterrupts();
    
    while(1){
        switch(state){
            case waitPush:
                break;
            case waitRelease:
                break;
        }
    }
    
    return 0;
}
Example #22
0
int main() {
    
    //This function is necessary to use interrupts. 
    enableInterrupts();
    
    //TODO: Write each initialization function
    initSwitch1();
    initLEDs();
    initTimer2();
    initTimer1();
    
    while(1){

        //TODO: Implement a state machine to create the desired functionality
        
    }
    
    return 0;
}
Example #23
0
void initPIC() {
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);

    initLEDs();
    initSerialNU32v2();

    // Setup and turn off electromagnets
    EMAG1 = 0;
    EMAG2 = 0;
    TRISEbits.TRISE7 = 0;
    TRISCbits.TRISC1 = 0;

    // Direction Output
    DIR = 1;
    TRISAbits.TRISA9 = 0;

    setup_counters();

    CloseADC10();
#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
    OpenADC10(PARAM1, PARAM2, PARAM3, PARAM4, 0);
    EnableADC10();

    // 20kHz PWM signal, duty from 0-1000, pin D3
    OpenTimer2(T2_ON | T2_PS_1_4, MAX_DUTY);
    OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
    SetDCOC4PWM(0);

    // 200 Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, (6250/4 - 1));
    //OpenTimer3(T3_ON | T3_PS_1_256, (62500 - 1));
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);

    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableSystemMultiVectoredInt();
}
int main() {
    SYSTEMConfigPerformance(10000000);    //Configures low-level system parameters for 10 MHz clock
    enableInterrupts();                   //This function is necessary to use interrupts.

    //TODO: Write each initialization function
    initLEDs();
    initSwitch1();
    
    
    state = red;
    
    while(1){
        
        //TODO: Implement a state machine to create the desired functionality
       switch (state){
       
        case red:
            LATDbits.LATD0=ON;
            LATDbits.LATD1=OFF;
            LATDbits.LATD2=OFF;
            
            break;
        
        case yellow:
            LATDbits.LATD0=OFF;
            LATDbits.LATD1=ON;
            LATDbits.LATD2=OFF;
            break;
            
        case green:
            LATDbits.LATD0=OFF;
            LATDbits.LATD1=OFF;
            LATDbits.LATD2=ON;
         break;
    } 
        
        
    }
    
    return 0;
}
Example #25
0
void main() {
  initLEDs();         // initialisation of strand, as defined in ws2812b.h --> port pin needs to be set there ! ! !
  setR(0,0,0xFF);		  // only setting red channel (will leave other colors unset)
  unsigned int x;			// used for counting loops
  // do this repeatedly:
  while (1) {
    // change brightness ("pulse"):
    // 1st up:
    for (x=0;x<20;x++) {
      setMaxBrightness(x); // change brightness (color will remain red, because no new set command is being applied)
      showLEDs();          // show LED color with updated brightness
      _delay_ms(PAUSE);    // little pause for our lazy eyes
    }
    // 2nd down:
    for (x=20;x>0;x--) {
      setMaxBrightness(x);
      showLEDs();
      _delay_ms(PAUSE);
    } 
  }
}
Example #26
0
File: main.c Project: smk12/lab1p1
/* Please note that the configuration file has changed from lab 0.
 * the oscillator is now of a different frequency.
 */
int main(void)
{
    SYSTEMConfigPerformance(40000000);
    enableInterrupts();
    initLEDs();
    initSW2();
    state = RUN;
    
    while(1)
    {
        switch(state)
        {
            case RUN:
                led1 = ON;
                led2 = OFF;
                lastState = RUN;
                break;
            case STOP:
                led1 = OFF;
                led2 = ON;
                lastState = STOP;
                break;
            case debouncePress:
                delayMs(5);
                if(lastState==RUN)
                    state = STOP;
                else if(lastState==STOP)
                    state = RUN;
                else
                    state = RUN;
                break;
            case debounceRelease:
                delayMs(5);
                state = lastState;
                break;
        }
    }
    
    return 0;
}
void setupHardware()
{
    SYSTEMConfig(SYS_CLOCK, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    mPORTDSetPinsDigitalOut(BIT_1); //yellow LED
    mPORTGSetPinsDigitalOut(BIT_6); //green LED

    //A1 PIR Input (CN4 module, RB2)
    //A2 STB current consumption (AN3)
    //D0 IR Output
    mPORTDSetPinsDigitalOut(BIT_3); //D1 STB IRF control
    mPORTDSetPinsDigitalIn(BIT_4); //D2 BUT OTG
    mPORTDSetPinsDigitalOut(BIT_5); //D3 SHD RED LED Command OFF acqusition notificaiton
    mPORTDSetPinsDigitalOut(BIT_6); //D4 SHD GREEN LED Command ON acqusition notificaiton
    //D5 IR input (RD7)
    //D6 SHD BUT1
    //D7 SHD BUT2
    mPORTBSetPinsDigitalOut(BIT_14); //D9 monitor relay control

    DDPCONbits.JTAGEN = 0;

    initLEDs();
    initUART();

    initADC();
    setupCNModuleAnd_IR_PIR_Input();
    //setupCNModuleAndPIRInput();
    configureRTC();
    setupIRTransmit();

    switchMonitorOff();
    switchSTBOff();

    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();

    T2CONbits.ON = 1;
}
int main(void) {
    const int LED_HZ = 10;

    WDTCTL = WDTPW + WDTHOLD;	// Stop WDT

    initLEDs();		//Setup LEDs

    BCSCTL3 |= LFXT1S_2;	//Set ACLK to use internal VLO (12 kHz clock)

    TACTL = TASSEL__ACLK | MC__UP;	//Set TimerA to use auxiliary clock in UP mode
    TACCTL0 = CCIE;	//Enable the interrupt for TACCR0 match
    TACCR0 = 12*1024 / LED_HZ;
    /*Set TACCR0 which also starts the timer. At
    			12 kHz, counting to 12000 should output
    			an LED change every 1 second. Try this
    			out and see how inaccurate the VLO can be */

    WRITE_SR(GIE);	//Enable global interrupts

    while(1) {
        //Loop forever, interrupts take care of the rest
    }
}
Example #29
0
int main(void) {
	timesec=0;
	// set PIC32 to max computing power
	SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);
	INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
	INTEnableSystemMultiVectoredInt();   
    initLEDs(); 	
    LED0 = 1;
    LED1 = 1;
    initSerialNU32v2();
	setup_counters();

  	CloseADC10();
  	#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
  	#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
  	#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
  	#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
  	OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4,0);
  	EnableADC10();


    // Setup and turn off electromagnets
    EMAG1 = 0; EMAG2 = 0; 
    TRISEbits.TRISE7 = 0; TRISCbits.TRISC1 = 0;
	//Direction Output
	DIR = 1;
  	TRISAbits.TRISA9 = 0;
	//g-select Outputs
	GSEL1 = 0; GSEL2 = 0;
  	TRISEbits.TRISE2 = 0; TRISCbits.TRISC13= 0;
  	//0g Inputs
  	TRISAbits.TRISA0 = 1;
  	TRISAbits.TRISA4 = 1;

  	// 20kHz PWM signal, duty from 0-1000, pin D3
  	OpenTimer2(T2_ON | T2_PS_1_4, 1000);
  	OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
  	HBridgeDuty = 0;
  	SetDCOC4PWM(HBridgeDuty);

    // 20Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, 15625);
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);


	while(1) {
		if(start){
			EMAG2=0;
			SetDCOC4PWM(100);
			delaysec(delay1);
			SetDCOC4PWM(1000);		
			delaysec(delay2);
			SetDCOC4PWM(500);
			delaysec(delay3);
			EMAG2=1;
			SetDCOC4PWM(0);	

//			EMAG1=0;
//			SetDCOC4PWM(900);
//			DIR = 0;
//			delaysec(delay1);
//			SetDCOC4PWM(0);
//			delaysec(delay2);
//			SetDCOC4PWM(700);
//			delaysec(delay1);
//			SetDCOC4PWM(1000);
//			EMAG1=1;

			start=0;
		}
	}
}
Example #30
0
// Perform initial initialization
void initalizePIC(void)
{
    initLEDs();
    initSerialPort();
}