/******************************************************************************* * FUNCTION NAME: main * PURPOSE: Main program function. * CALLED FROM: ifi_startup.c * ARGUMENTS: none * RETURNS: void * DO NOT DELETE THIS FUNCTION *******************************************************************************/ void main (void) { #ifdef UNCHANGEABLE_DEFINITION_AREA IFI_Initialization (); /* DO NOT CHANGE! */ #endif statusflag.NEW_SPI_DATA = 0; /* DO NOT CHANGE! */ User_Initialization(); /* You edit this in user_routines.c */ #if ENABLE_AUTONOMOUS_MODE txdata.user_cmd = 0x02; /* Tell master you want to be in auton mode. */ #endif while (1) /* This loop will repeat indefinitely. */ { #ifdef _SIMULATOR statusflag.NEW_SPI_DATA = 1; #endif if (statusflag.NEW_SPI_DATA) /* 18.5ms loop area */ { /* I'm slow! I only execute every 18.5ms because */ /* that's how fast the Master uP gives me data. */ Process_Data_From_Master_uP(); /* You edit this in user_routines.c */ // Haha I changed it. // Pressing 5 up on the OI makes this happen. This is not desired. // if (autonomous_mode) /* DO NOT CHANGE! */ // { // User_Autonomous_Code(); /* You edit this in user_routines_fast.c */ // } } Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */ /* I'm fast! I execute during every loop.*/ } /* while (1) */ } /* END of Main */
/* * INITIALIZATION AND MISC */ void setup_1(void) { uint8_t i; IFI_Initialization(); /* Initialize serial port communication. */ statusflag.b.NEW_SPI_DATA = 0; usart1_open(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, kBaud115); delay1ktcy(50); /* Make the master control all PWMs (for now) */ txdata.pwm_mask.a = 0xFF; for (i = IX_DIGITAL(1); i <= IX_DIGITAL(CT_DIGITAL); ++i) { digital_setup(i, false); } /* Init ADC */ /* Setup the number of analog sensors. The PIC defines a series of 15 * ADC constants in mcc18/h/adc.h that are all of the form 0b1111xxxx, * where x counts the number of DIGITAL ports. In total, there are * sixteen ports numbered from 0ANA to 15ANA. */ if (NUM_ANALOG_VALID(USER_CT_ANALOG) && USER_CT_ANALOG > 0) { /* ADC_FOSC: Based on a baud_115 value of 21, given the formula * FOSC/(16(X + 1)) in table 18-1 of the PIC18F8520 doc the * FOSC is 40Mhz. * Also according to the doc, section 19.2, the * ADC Freq needs to be at least 1.6us or 0.625MHz. 40/0.625=64 * (Also, see table 19-1 in the chip doc) */ #if defined(MCC18) OpenADC( ADC_FOSC_64 & ADC_RIGHT_JUST & ( 0xF0 | (16 - USER_CT_ANALOG) ) , ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ); #elif defined(SDCC) adc_open( ADC_CHN_0, ADC_FOSC_64, ADC_CFG_16A, ADC_FRM_RJUST | ADC_INT_OFF | ADC_VCFG_VDD_VSS ); #else #error "Bad Comp" #endif } else { /* TODO: Handle the error. */ puts("ADC is disabled"); } }
/* * INITIALIZATION AND MISC */ void setup_1(void) { uint8_t i; IFI_Initialization(); /* Prevent the "slow loop" from executing until data has been received * from the master processor. */ statusflag.NEW_SPI_DATA = 0; /* Enable autonomous mode. FIXME: Magic Number (we need an enum of valid "user_cmd"s) */ /* txdata.user_cmd = 0x02; */ /* Make the master control all PWMs (for now) */ txdata.pwm_mask.a = 0xFF; /* Initialize all pins as inputs unless overridden. */ for (i = 0; i < 16; ++i) { pin_set_io( i, kInput); } /* Initialize Serial */ Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, kBaud115); Delay1KTCYx( 50 ); /* Settling time (5K Clock ticks) */ /* Init ADC */ /* Setup the number of analog sensors. The PIC defines a series of 15 * ADC constants in mcc18/h/adc.h that are all of the form 0b1111xxxx, * where x counts the number of DIGITAL ports. In total, there are * sixteen ports numbered from 0ANA to 15ANA. */ if ( NUM_ANALOG_VALID(kNumAnalogInputs) && kNumAnalogInputs > 0 ) { /* ADC_FOSC: Based on a baud_115 value of 21, given the formula * FOSC/(16(X + 1)) in table 18-1 of the PIC18F8520 doc the FOSC * is 40Mhz. * Also according to the doc, section 19.2, the * ADC Freq needs to be at least 1.6us or 0.625MHz. 40/0.625=64 * (Also, see table 19-1 in the chip doc) */ OpenADC( ADC_FOSC_64 & ADC_RIGHT_JUST & ( 0xF0 | (16 - kNumAnalogInputs) ) , ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ); } }