void Init() { PWR_Init(); CLOCK_Init(); UART_Initialize(); printf("Start\n"); Initialize_ButtonMatrix(); SPIFlash_Init(); //This must come before LCD_Init() for 7e LCD_Init(); CHAN_Init(); SPITouch_Init(); SOUND_Init(); BACKLIGHT_Init(); BACKLIGHT_Brightness(1); AUTODIMMER_Init(); SPI_FlashBlockWriteEnable(1); //Enable writing to all banks of SPIFlash PPMin_TIM_Init(); #ifdef MODULAR //Force protocol to none to initialize RAM Model.protocol = PROTOCOL_NONE; PROTOCOL_Init(1); #endif #if HAS_RTC RTC_Init(); // Watchdog must be running in case something goes wrong (e.g no crystal) #endif }
int main() { PWR_Init(); CLOCK_Init(); UART_Initialize(); if(PWR_CheckPowerSwitch()) PWR_Shutdown(); dump_bootloader(); }
//////////////////////////////////////////////////////////////// // MAIN // //////////////////////////////////////////////////////////////// void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer UART_Initialize(); //Initialize UART /* Initialize Timer A to measure 1/10 sec */ TACTL = TASSEL_2 + MC_1+ ID_3; // Select smclk/8 and up mode TACCR0 = 13107; // 100ms interval TACCTL0 = CCIE; // Capture/compare interrupt enable P5DIR |= 0x02; while(1) // Infinite loop { _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupts SendTime(); // Send Time to HyperTerminal } }
void main(void) { WDTCTL = WDTPW + WDTHOLD; sDCO(); UART_Initialize(); LM_Initialize(); while(1) LM_SendQueuedBytes(); }
int main() { PWR_Init(); CLOCK_Init(); UART_Initialize(); if(PWR_CheckPowerSwitch()) PWR_Shutdown(); #if SPI_BOOTLOADER Initialize_ButtonMatrix(); SPIFlash_Init(); //This must come before LCD_Init() for 7e SPI_FlashBlockWriteEnable(1); //Enable writing to all banks of SPIFlash LCD_Init(); LCD_Clear(0x0000); BACKLIGHT_Init(); BACKLIGHT_Brightness(5); LCD_SetFont(0); LCD_SetFontColor(0xffff); dump_bootloader(0); #else dump_bootloader(1); #endif }
void main(void) { WDTCTL = (WDTPW|WDTHOLD); UART_Initialize(); // Setup input pins P6DIR &= ~0xF0; // Configure P6.4,5,6,7 as input pins P6SEL |= 0xF0; // Configure P6.4,5,6,7 as analogue pins // Setup Timer_A TACCR0 = 3277; // 3277 / 32768 Hz = 0.1s TACTL = TASSEL_1 + MC_1; // ACLK, up mode TACCTL0 = CCIE; // enabled interrupt // Setup ADC 12 ADC12CTL0 = ADC12ON + SHT0_8 + MSC; // configure ADC converter ADC12CTL1 = SHP + CONSEQ_1; // Use sample timer, single sequence ADC12MCTL0 = INCH_0 + SREF_2; // ADC channel 0 is A0 pin - Left-Stick X-axis ADC12MCTL1 = INCH_3 + SREF_2; // ADC channel 1 is A3 pin - Left-Stick Y-axis ADC12MCTL2 = INCH_4 + SREF_2; // ADC channel 2 is A4 pin - Right-Stick X-axis ADC12MCTL3 = INCH_7 + SREF_2 + EOS; // ADC channel 3 is A7 pin - Right-Stick Y-axis // EOS - End of Sequence for Conversions ADC12IE |= 0x0008; // Enable ADC12 Interrupts Delay_Debounce(); // Delay for reference start-up ADC12CTL0 |= ENC; // Enable conversions _EINT(); // Enable interrupts _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt while (1) { } }
/********************************************************************* * Function: void APP_DeviceCDCEmulatorInitialize(void); * * Overview: Initializes the demo code * * PreCondition: None * * Input: None * * Output: None * ********************************************************************/ void APP_DeviceCDCEmulatorInitialize() { CDCInitEP(); line_coding.bCharFormat = 0; line_coding.bDataBits = 8; line_coding.bParityType = 0; line_coding.dwDTERate = 19200; unsigned char i; UART_Initialize(); // Initialize the arrays for (i=0; i<sizeof(USB_Out_Buffer); i++) { USB_Out_Buffer[i] = 0; } NextUSBOut = 0; LastRS232Out = 0; lastTransmission = 0; }
void SYS_Initialize ( void* data ) { /* Core Processor Initialization */ SYS_CLK_Initialize( NULL ); sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit); SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet()); SYS_DEVCON_JTAGDisable(); SYS_PORTS_Initialize(); /* Initialize Drivers */ /* Initialize ADC */ DRV_ADC_Initialize(); sysObj.drvUsart0 = DRV_USART_Initialize(DRV_USART_INDEX_0, (SYS_MODULE_INIT *)&drvUsart0InitData); SYS_INT_VectorPrioritySet(INT_VECTOR_UART1, INT_PRIORITY_LEVEL1); SYS_INT_VectorSubprioritySet(INT_VECTOR_UART1, INT_SUBPRIORITY_LEVEL0); /* Initialize System Services */ SYS_INT_Initialize(); /* Initialize Middleware */ /* Initialize the Application */ UART_Initialize(); }
int main ( void ) { //TRISA = 0b0010000000000000; TRISA = 0b00001111; TRISAbits.TRISA12 = 0; TRISCbits.TRISC1 = 0; TRISCbits.TRISC2 = 0; TRISCbits.TRISC3 = 0; TRISCbits.TRISC4 = 0; //TRISD = 0; TRISD = 0b0000000000010000; // RD11: DIR2; RD8: PWM2 //TRISE = 0b00001000; TRISE = 0b00001000; // RE6: DIR1; RE0: PWM1 TRISEbits.TRISE7 = 0; //LCD an _PCFG16 = 1; // AN16 is digital _PCFG17 = 1; // AN17 is digital _PCFG18 = 1; // AN18 is digital _PCFG19 = 1; // AN19 is digital _PCFG20 =1; _PCFG31=1; //pwm analog select _PCFG24=1; _PCFG30=1; //RE4 for lcd r/s _PCFG28=1; TRISEbits.TRISE4 = 0; AD1PCFGHbits.PCFG28 = 1; AD1PCFGHbits.PCFG27 = 1; AD1PCFGHbits.PCFG30 = 1; AD1PCFGHbits.PCFG24 = 1; AD1PCFGH = 0x0020; TRISAbits.TRISA13 = 1; //set pwm low PWM1=0; PWM2=0; SYS_Initialize ( ) ; CLKDIVbits.FRCDIV = 0; CLKDIVbits.PLLPOST = 0; // N2 = 2 CLKDIVbits.PLLPRE = 0; // N1 = 2 PLLFBD = (Fosc*N1_default*N2_default/Ffrc) - M_default; // M = 8 -> Fosc = 7.3728 MHz * 8 / 2 / 2 = 16 MHz while(!OSCCONbits.LOCK); // Wait for PLL to lock RCONbits.SWDTEN = 0; // Disable Watch Dog Timer //TRISF = 0; gpsLock = 0; lcd_init(); print_lcd("Initializing"); //delay_ms(500); //lcd_clear(); /*lcd test char line1[] = " On Route "; char line2[] = " Arrived "; //send_command_byte(0xFF); //while(1){send_command_byte(0xFF);send_data_byte(0);} // delay_ms(2); //send_command_byte(0x02); // Go to start of line 1 //send_command_byte(0b00001111); // Display: display on, cursor on, blink on //send_command_byte(0b00000110); // Set entry mode: ID=1, S=0 //send_command_byte(0b00000001); // Clear display print_lcd(line1); delay_ms(5000); lcd_clear(); print_lcd(line2); //send_command_byte(0xC0); // Go to start of line 1 //while(1){send_command_byte(0b00000001);} while(1);*/ /*int a; long long int ct; int i; int j=0;*/ //i2c init //uart init UART_Initialize(); delayMs(100); /* while(1){//test for delay ms configuration //PORTDbits.RD1 = 1; //delayUs(10); //for(i = 0;i <7;i++); delayMs(10); PORTDbits.RD12 = 1; //for (i = 0; i < 1000; i++); //PORTDbits.RD1 = 0; //for(i = 0;i <7;i++); delayMs(10); PORTDbits.RD12 = 0; //for (i = 0; i < 1000; i++); }*/ //ultrasonic test /* while(1){ long double x; delayMs(500); PORTEbits.RE4 = 1; //TRIGGER HIGH PORTDbits.RD5 = 1; delay_us(10); //10uS Delay lcd_clear(); ultraSonicEn = 1; ultraSonicCount = 0; PORTEbits.RE4 = 0; //TRIGGER LOW PORTDbits.RD5 = 0; while (!PORTDbits.RD4); //Waiting for Echo IEC0bits.T2IE = 1; //enable timer while(PORTDbits.RD4);// IEC0bits.T2IE = 0; //disable timer x = ultraSonicCount/TICKS_PER_METER; sprintf(outputBuf,"%lf",x); print_lcd(outputBuf); }*/ //TX_str(endGPS); //delayMs(3000); //TX_str(startGPS); /*TX_str(startGPShot); delayMs(2000); while ( !gpsLock ) { TX_str(getGPS); delayMs(500); }*/ //TCP code TX_str(openNet); delayMs(5000); TX_str(openConnection); delayMs(5000); // while(!BUTTON_IsPressed ( BUTTON_S3 )); //TX_str(sprintf("%s%d\r",sendTCP, strlen("10"))); sprintf(outputBuf2,"2\n%lf,%lf\n\r",roverLog,roverLat ); sprintf(cmdBuf,"%s%d\r", sendTCP,strlen(outputBuf2)); TX_str(cmdBuf); delayMs(3000); TX_str(outputBuf2); while(!waypointsReady || !gpsLock); //while(1); delayMs(7000); lcd_clear(); print_lcd("waypoints locked"); i2c_init(); //i2c_write3(0x3c, 0x00, 0x70); i2c_write3(0x3c, 0x00, 0b00011000); //i2c_write3(0x3c, 0x01, 0b11000000); i2c_write3(0x3c, 0x01, 0xA0); i2c_write3(0x3c, 0x02, 0x00); //timer init, do this after other initializations motorDuty=0; tim1_init(); tim2_init(); /* double angleTolerance = 8.0; motorDuty=2; while (1){ //adjust double angleDiff = headingDiff(0,roverHeading ); if (angleDiff > 0 ||abs(angleDiff) > 175 ){ //turn left PWM1_DIR = 0; //left NOTE: 0 is forward, 1 is reverse PWM2_DIR = 1; //right } else{ // turn right PWM1_DIR = 1; PWM2_DIR = 0; } if (abs(angleDiff) < angleTolerance){ motorDuty = 0; //break; }else{ //motorDuty =4; motorDuty =2; } delayMs(13); updateHeading(); }*/ //hardcoded gps for tcpip test /*while(1){ // PORTDbits.RD5 = 1; // for (a = 0; a < (100/33); a++) {} // PORTDbits.RD5 = 0; // for (a = 0; a < (100/33); a++) {} ct = 0; //TMR2 = 0;//Timer Starts delayMs(60); PORTEbits.RE4 = 1; //TRIGGER HIGH PORTDbits.RD5 = 1; delay_us(15); //10uS Delay PORTEbits.RE4 = 0; //TRIGGER LOW PORTDbits.RD5 = 0; while (!PORTDbits.RD4){ //Waiting for Echo ct++; } //T2CONbits.TON = 1; while(PORTDbits.RD4) { ct++; }// { //T2CONbits.TON = 0; sprintf(outputBuf,"%lld", ct); //a = TMR2; //a = a / 58.82; //long int p; //for(p = 0; p <100000; p++); }*/ //tim1_init(); //while ( 1 ); //UART_Initialize(); /* Infinite Loop */ /* long int i; while ( 1 ) {//test for delay ms configuration //PORTDbits.RD1 = 1; delayMs(10); PORTDbits.RD12 = 1; //for (i = 0; i < 1000; i++); //PORTDbits.RD1 = 0; delayMs(10); PORTDbits.RD12 = 0; //for (i = 0; i < 1000; i++); }*/ //IEC0bits.T1IE = 0; //IEC0bits.T1IE = 1; //motorDuty =2; motorStopFlag = 0; //ready to go char tempBuf1[50]; int wapointsVisited; double desiredHeading = 0; double dToWaypoint = 99999.9; double angleTolerance = 6.0; for (wapointsVisited =0; wapointsVisited<numGPSpoints;wapointsVisited++ ) { dToWaypoint = 99999.9; while (1) { int f; roverLog = 0; roverLat = 0; for(f = 0; f < ROVER_LEN; f++){ roverLog+=roverlog[f]/ROVER_LEN_D; roverLat+=roverlat[f]/ROVER_LEN_D; } dToWaypoint = dist(convertGPSToDeg(roverLat),convertGPSToDeg(roverLog),convertGPSToDeg(gpsLat[wapointsVisited]),convertGPSToDeg(gpsLonge[wapointsVisited])); if(dToWaypoint <= 3.0){break;} //go to next waypoint desiredHeading = 330.0; desiredHeading = bearing(convertGPSToDeg(roverLat),convertGPSToDeg(roverLog),convertGPSToDeg(gpsLat[wapointsVisited]),convertGPSToDeg(gpsLonge[wapointsVisited])); updateHeading(); if (!(abs(headingDiff(desiredHeading,roverHeading )) < angleTolerance)) { motorDuty = 0; //stop delayMs(300); while (1) //ADJUSTMENT LOOP { double angleDiff = headingDiff(desiredHeading,roverHeading ); //double dist = ultraSonicPing(); /*sprintf(tempBuf1,"%f",dist); lcd_clear(); print_lcd(tempBuf1);*/ if (abs(angleDiff) < angleTolerance){ motorDuty = 0; /*sprintf(tempBuf1,"%f",roverHeading); IEC0bits.T1IE = 0; print_lcd(tempBuf1); IEC0bits.T1IE = 1;*/ break; } if (angleDiff > 0 || abs(angleDiff) > 175 ){ //turn right /*PORTDbits.RD4 = 1; //right 0 is forwards, 1 i backwards PORTDbits.RD2 = 1; PORTDbits.RD8 = 0; //left*/ PWM1_DIR = 0; //left NOTE: 0 is forward, 1 is reverse PWM2_DIR = 1; //right } else{ // turn left /*PORTDbits.RD4 = 0; //right 0 is forwards, 1 i backwards PORTDbits.RD2 = 0; PORTDbits.RD8 = 1; //left*/ PWM1_DIR = 1; PWM2_DIR = 0; } motorDuty =3; delayMs(15); updateHeading(); // sprintf(tempBuf1,"%f",roverHeading); // IEC0bits.T1IE = 0; // lcd_clear(); // print_lcd(tempBuf1); // IEC0bits.T1IE = 1; //delayMs(1000); //for(p = 0; p <100000; p++); } } PWM1_DIR = 0; //left NOTE: 0 is forward, 1 is reverse PWM2_DIR = 0; motorDuty = 5; ultraSonicDelayEnable = 1; //frequency is around 20kHz while (ultraSonicDelayCount < 60000){ //for 4 seconds poll ultrasonic and check for obsticles long double x; //PORTEbits.RE4 = 1; //TRIGGER HIGH PORTDbits.RD5 = 1; delay_us(10); //10uS Delay lcd_clear(); ultraSonicEn = 1; ultraSonicCount = 0; //PORTEbits.RE4 = 0; //TRIGGER LOW PORTDbits.RD5 = 0; while (!PORTDbits.RD4); //Waiting for Echo IEC0bits.T2IE = 1; //enable timer while(PORTDbits.RD4);// IEC0bits.T2IE = 0; //disable timer ultraSonicEn = 0; x = ultraSonicCount/TICKS_PER_METER; if (x <= 1.4){ motorDuty = 0; }else{ motorDuty = 5; } delayMs(200); } ultraSonicDelayEnable = 0; ultraSonicDelayCount = 0; } motorDuty = 0; delayMs(1000); //IEC0bits.T1IE = 0; lcd_clear(); char buf3[40]; sprintf(buf3, "reached %d", wapointsVisited); print_lcd(buf3); delayMs(3000); //IEC0bits.T1IE = 1; } //IEC0bits.T1IE = 0; lcd_clear(); print_lcd("ARRIVED!!!"); //IEC0bits.T1IE = 1; while (1); }
void main(void) { int i = 0; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer UART_Initialize(); ADC12CTL0 = SHT0_8 + REFON + ADC12ON; ADC12CTL1 = SHP; // enable sample timer ADC12MCTL0 = 0x01A; ADC12IE = 0x001; rx_flag = 0; // rx default state "empty" _EINT(); // enable global interrupts Wait: //send a greeting message for(i = 0; i < 67; i++) { thr_char = gm1[i]; UART_putchar(thr_char); } while(!(rx_flag&0x01)); // wait until receive the character from HyperTerminal rx_flag = 0; // clear rx_flag UART_putchar(thr_char); UART_putchar('\n'); // newline UART_putchar('\r'); // carriage return // character input validation if ((thr_char != 'y') && (thr_char != 'n') && (thr_char !='Y') && (thr_char !='N')) { for(i = 0; i < 15; i++) { thr_char = gm3[i]; UART_putchar(thr_char); } UART_putchar('\n'); // newline UART_putchar('\r'); // carriage return goto Wait; } if ((thr_char == 'y') || (thr_char == 'Y')) { ADC12CTL0 |= ENC + ADC12SC; // Sampling and conversion start _BIS_SR(CPUOFF + GIE); // LPM0 with interrupts enabled // oF = ((x/4096)*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468 // IntDegF = (ADC12MEM0 - 2519)* 761/4096 IntDegF = (temp - 2519) * 761; IntDegF = IntDegF / 4096; // oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278 // IntDegC = (ADC12MEM0 - 2692)* 423/4096 IntDegC = (temp - 2692) * 423; IntDegC = IntDegC / 4096; //printing the temperature on hyperterminal sprintf(NewKey, "T(F)=%ld\tT(C)=%ld\n", IntDegF, IntDegC); for(i = 0; i < 25; i++) { thr_char = NewKey[i]; UART_putchar(thr_char); } UART_putchar('\n'); // newline UART_putchar('\r'); // carriage return goto Wait; } if ((thr_char == 'n') || (thr_char == 'N')) { for(i = 0; i < 9; i++) { thr_char = gm2[i]; UART_putchar(thr_char); } UART_putchar('\n'); // newline UART_putchar('\r'); // carriage return } }