コード例 #1
0
ファイル: main.c プロジェクト: lunakid/msp-exp
void main(void) {

	WDTCTL = WDTPW + WDTHOLD; // disable WDT

	initMSP430();

	blip();

	_delay_cycles(160000); // wait

	initLCD();

	while (1) {

		_delay_cycles(1600000);
		blip();
		clearScreen(1);

		set_font(&font_5x7); // FONT_SM
		setColor(COLOR_16_RED);
		draw_string(5, 5, "Texas Instruments");

		set_font(&font_8x12); // FONT_MD
		setColor(COLOR_16_WHITE);
		draw_string(5, 20, "2.2\" 320x240 BoosterPack");
		setColor(COLOR_16_BLUE);
		draw_string(5, 40, "& MSP430F5529 LaunchPad");
		setColor(COLOR_16_ORANGE);
		draw_string(5, 60, "RobG's graphics library");
		setColor(COLOR_16_PURPLE);
		draw_string(5, 80, "Works with:");
		setColor(COLOR_16_YELLOW);
/*
		set_font(&font_11x16); // FONT_LG
		draw_string(5, 100, "F5172 F5510 F5529");
		setColor(COLOR_16_GREEN_YELLOW);
		draw_string(5, 120, "G2553 G2955 & more");
*/
		set_font(&font_Dyson_8x9);
		draw_string(5, 120, "DYSON FONT ABC...");

		blip();
		_delay_cycles(40000000);
		clearScreen(1);

		drawTILogo(56, 56, COLOR_16_RED);
		drawTILogo(55, 56, COLOR_16_RED);
		drawTILogo(56, 55, COLOR_16_RED);
		drawTILogo(55, 55, COLOR_16_RED);
		drawTILogo(50, 50, COLOR_16_WHITE);

		_delay_cycles(32000000);
		blip();

		shesGotColors(100);

		_delay_cycles(12000000);
		blip();

		clearScreen(1);

		drawLogicLines(8);

		_delay_cycles(16000000);
		blip();

/*!!sz:
		drawSpirograph(40, 20, 15);
		_delay_cycles(16000000);
!!*/
		setOrientation(++orientation & 0x03);
	}
}
コード例 #2
0
void main()
{
    volatile int status = 0;
    uint16_t i;
    volatile FILE *fid;
    
    // If running from flash copy RAM only functions to RAM   
#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif      

    // Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
       InitSysCtrl();



    // For this example, only init the pins for the SCI-A port.
    EALLOW;
    GpioCtrlRegs.GPCMUX2.bit.GPIO84 = 1;
    GpioCtrlRegs.GPCMUX2.bit.GPIO85 = 1;
    GpioCtrlRegs.GPCGMUX2.bit.GPIO84 = 1;
    GpioCtrlRegs.GPCGMUX2.bit.GPIO85 = 1;
    EDIS;


    //  Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;

    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2806x_PieCtrl.c file.
       InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;

    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
       InitPieVectTable();


    // Initialize SCIA
    scia_init();

    //Initialize GPIOs for the LEDs and turn them off
    EALLOW;
    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO13 = 1;
    GpioDataRegs.GPADAT.bit.GPIO12 = 1;
    GpioDataRegs.GPADAT.bit.GPIO13 = 1;
    EDIS;


    // Enable global Interrupts and higher priority real-time debug events:
    EINT;   // Enable Global interrupt INTM
    ERTM;   // Enable Global realtime interrupt DBGM

    
    // Configure the ADC:
    // Initialize the ADC
	EALLOW;

	//write configurations
	AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
	AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

	//Set pulse positions to late
	AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
	AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;

	//power up the ADCs
	AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
	AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;

	//delay for 1ms to allow ADC time to power up
	DELAY_US(1000);


   //ADCA
   EALLOW;
   AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0x0E;  //SOC0 will convert pin ADCIN14
   AdcaRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles
   AdcaRegs.ADCSOC1CTL.bit.CHSEL = 0x0E;  //SOC1 will convert pin ADCIN14
   AdcaRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles
   AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag
   AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag
   AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared



    
    //Redirect STDOUT to SCI
    status = add_device("scia", _SSA, SCI_open, SCI_close, SCI_read, SCI_write, SCI_lseek, SCI_unlink, SCI_rename);
    fid = fopen("scia","w");
    freopen("scia:", "w", stdout);
    setvbuf(stdout, NULL, _IONBF, 0);
    
    //Print a TI Logo to STDOUT
    drawTILogo();

    //Twiddle LEDs
    GpioDataRegs.GPADAT.bit.GPIO12 = 0;
    GpioDataRegs.GPADAT.bit.GPIO13 = 1;


    for(i = 0; i < 50; i++){

        GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1;
        GpioDataRegs.GPATOGGLE.bit.GPIO13 = 1;
        DELAY_US(50000);


    }

    //LEDs off
    GpioDataRegs.GPADAT.bit.GPIO12 = 1;
    GpioDataRegs.GPADAT.bit.GPIO13 = 1;
        
    
    //Clear out one of the text boxes so we can write more info to it
    clearTextBox();
    
    currentSample = sampleADC();
    

    //Main program loop - continually sample temperature
    for(;;) {
        

        //Sample ADCIN14
        currentSample = sampleADC();
        
        //Update the serial terminal output
        updateDisplay();
        
        //If the sample is above midscale light one LED
        if(currentSample > 2048){
    	    GpioDataRegs.GPADAT.all = 0x2000;
        }else{
            //Otherwise light the other
    	    GpioDataRegs.GPADAT.all = 0x1000;
        }

        DELAY_US(1000000);
        
    }
}