/* -------------------------------------------------------------------------------- [NAME] : ConfigPins_PWM [TYPE] : Internal Function & accessible publically through structure [INPUT] : PWMs use status, eg. pass parameters as (USE1| USE2| USE3) [RETURN] : None [DESCRIPTION]: This function configures the PWM pins. -------------------------------------------------------------------------------- */ void ConfigPins_PWM(U8 v_PWMUse_U8) { /*** Configure PWM1 ***/ if((v_PWMUse_U8&0x01) == 0x01) { PWM1_DIR = DIR_OUT; // Set PWM1 as Output PWM1 = C_OFF; // Set state to OFF iPPSOutput(OUT_PIN_PPS_RP12, OUT_FN_PPS_OC1); //Assing OC1 to pin PWM1 } /*** Configure PWM2 ***/ if((v_PWMUse_U8&0x02) == 0x02) { PWM2_DIR = DIR_OUT; // Set PWM2 as Output PWM2 = C_OFF; // Set state to OFF iPPSOutput(OUT_PIN_PPS_RP2, OUT_FN_PPS_OC2); //Assing OC1 to pin PWM1 } /*** Configure PWM3 ***/ if((v_PWMUse_U8&0x04) == 0x04) { PWM3_DIR = DIR_OUT; // Set PWM3 as Output PWM3 = C_OFF; // Set state to OFF iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_OC3); //Assing OC1 to pin PWM1 } /*** Configure PWM4 ***/ if((v_PWMUse_U8&0x08) == 0x08) { PWM4_DIR = DIR_OUT; // Set PWM4 as Output PWM4 = C_OFF; // Set state to OFF iPPSOutput(OUT_PIN_PPS_RP24, OUT_FN_PPS_OC4); //Assing OC1 to pin PWM1 } }
// Set up the SPI for the MicroSD card void sdSetup(void) { // Configure Port Direction TRISDbits.TRISD5 = 0; // Turn RD5 into output for SCLK TRISDbits.TRISD4 = 1; // Turn RD4 into input for MISO TRISDbits.TRISD3 = 0; // Turn RD3 into output for MOSI TRISDbits.TRISD2 = 0; // Turn RD2 into output for SS TRISDbits.TRISD1 = 1; // Turn RD1 into input for CD (card detect) // Configure PPS pins for MicroSD iPPSInput(IN_FN_PPS_SDI1,IN_PIN_PPS_RP25); // Assign SDI1 to pin RP25 iPPSOutput(OUT_PIN_PPS_RP20,OUT_FN_PPS_SCK1OUT); // Assign SCK1OUT to pin RP20 iPPSOutput(OUT_PIN_PPS_RP22,OUT_FN_PPS_SDO1); // Assign SDO1 to pin RP22 iPPSOutput(OUT_PIN_PPS_RP23,OUT_FN_PPS_SS1OUT); // Assign SS1OUT to pin RP23 // Close SPI in case it's already open CloseSPI1(); // Enable SPI interface // Clear and disable SPI interupts for now SPI1_Clear_Intr_Status_Bit; DisableIntSPI1; ConfigIntSPI1(SPI_INT_DIS); // Interrupts disabled OpenSPI1(0x0000, MASTER_ENABLE_ON, SPI_ENABLE); // Master Mode // SPI enabled }
// Set up the UART for the FTDI chip void usbSetup(void) { // Configure Port Direction TRISDbits.TRISD11 = 0; // Turn RD11 into output for USB TX TRISDbits.TRISD10 = 1; // Turn RD10 into input for USB RX TRISDbits.TRISD9 = 0; // Turn RD9 into output for USB RTS# TRISDbits.TRISD8 = 0; // Turn RD8 into output for LED TRISDbits.TRISD6 = 0; // Turn RD6 into output for LED // TRISDbits.TRISD2 = 0; // Turn RD2 into output for LED // TRISDbits.TRISD1 = 0; // Turn RD1 into output for LED TRISDbits.TRISD0 = 1; // Turn RD0 into input for USB CTS# // Configure PPS pins for USB iPPSInput(IN_FN_PPS_U3RX,IN_PIN_PPS_RP3); // Assign U3RX to pin RP3 iPPSInput(IN_FN_PPS_U3CTS,IN_PIN_PPS_RP11); // Assign U3CTS# to pin RP11 iPPSOutput(OUT_PIN_PPS_RP12,OUT_FN_PPS_U3TX); // Assign U3TX to pin RP12 iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_U3RTS); // Assign U3RTS# to pin RP4 // Close UART in case it's already open CloseUART3(); // Enable UART Interface ConfigIntUART3(UART_RX_INT_DIS | UART_RX_INT_PR5 | UART_TX_INT_DIS | UART_TX_INT_PR5); // Receive interrupt disabled // Transmit interrupt disabled OpenUART3(UART_EN | UART_UEN_10, UART_TX_ENABLE, 25); // Module enable // UxTX, UxRX, UxCTS and UxRTS pins are enabled and used // BRG generates 4 clocks per bit period // Even parity 8 bit // Transmit enable // 9600 baud rate (@ 4 MHz FCY) }
/* -------------------------------------------------------------------------------- [NAME] : ConfigPins_SPI 1 [TYPE] : Internal Function & accessible publically through structure [INPUT] : None [RETURN] : None [DESCRIPTION]: This function maps the remappable pins to SPI1. -------------------------------------------------------------------------------- */ void ConfigPins_SPI1(void) { /*** Assign SPI1 pins using PPS ***/ SS1_DIR = DIR_OUT; SDI1_DIR = DIR_IN ; SDO1_DIR = DIR_OUT; SCK1_DIR = DIR_OUT; iPPSOutput(OUT_PIN_PPS_RP20, OUT_FN_PPS_SS1OUT); iPPSInput( IN_FN_PPS_SDI1 , IN_PIN_PPS_RP25 ); iPPSOutput(OUT_PIN_PPS_RP22, OUT_FN_PPS_SDO1); iPPSOutput(OUT_PIN_PPS_RP23, OUT_FN_PPS_SCK1OUT); }
/** * interface_init_uart: Initialize UART module including * PPS. Does not set baud rate and module must be enabled * after this function is run. */ void interface_init_uart() { // Setup PPS (use pps.h macros.) PPSUnLock; iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP9); iPPSInput(IN_FN_PPS_U1CTS, 31); // always clear to send to PIC24F (tie internally to Vss) iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_U1RTS); iPPSOutput(OUT_PIN_PPS_RP8, OUT_FN_PPS_U1TX); // Setup UART1. U1MODEbits.UARTEN = 0; // Disable UART1 for now U1MODEbits.USIDL = 0; // Don't stop in idle mode(?) U1MODEbits.IREN = 0; // Disable IrDA mode U1MODEbits.RTSMD = 0; // Flow control mode - automatically control U1RTS U1MODEbits.UEN = 0b10; // UxTX, UxRX and UxRTS pins are enabled and used; UxCTS pin is controlled by port latches U1MODEbits.WAKE = 0; // Disable wake-up U1MODEbits.LPBACK = 0; // Disable loop-back //U1MODEbits.LPBACK = 1; // Enable loop-back (testing) U1MODEbits.ABAUD = 0; // Disable auto-baud for now U1MODEbits.URXINV = 0; // Disable receive invert U1MODEbits.BRGH = 1; // High-speed mode U1MODEbits.PDSEL = 0b00; // 8-bit, no parity (consider odd/even parity?) U1MODEbits.STSEL = 0; // 1 stop bit U1STAbits.UTXEN = 0; // Disable transmit (for now) // Setup interrupts (required for DMA) U1STAbits.URXISEL = 0b00; // "Interrupt" on each byte // Disable interrupts on the CPU side, so the processor doesn't get interfered with. IEC0bits.U1RXIE = 0; IPC2bits.U1RXIP = 0; // Setup DMA for RX side. DMA5CONbits.CHEN = 0; // Disable channel for now DMA5CONbits.SIZE = 1; // Byte transfers DMA5CONbits.DIR = 0; // Read from peripheral to DPSRAM DMA5CONbits.HALF = 0; // Don't interrupt on half written DMA5CONbits.NULLW = 0; // Don't do a null write DMA5CONbits.AMODE = 0b00; // Peripheral indirect addressing mode, post-increment DMA5CONbits.MODE = 0b10; // Continuous, ping pong buffer DMA5REQbits.FORCE = 0; // Don't force transfer yet (peripheral control only) DMA5REQbits.IRQSEL = 0b0001011; // UART1RX IRQ DMA5STA = __builtin_dmaoffset(uart_buffA); // Buffer A DMA5STB = __builtin_dmaoffset(uart_buffB); // Buffer B DMA5CNT = UART_BUFFSZ - 1; // Maximum UART_BUFFSZ bytes per transaction DMA5PAD = (volatile unsigned int) &U1RXREG; // DMA peripheral address U1MODEbits.UARTEN = 1; // Enable UART DMA5CONbits.CHEN = 1; // Turn channel on // Set channel tracker up. UART_RX_DMA_last = DMACS1bits.PPST5; // Kick-start the first transfer. DMA5REQbits.FORCE = 1; // Lock PPS & OSCCON. PPSLock; }
void ConfigPins_SPI2(void) { _ANSG9 = 0; _ANSG8 = 0; _ANSG7 = 0; _ANSG6 = 0; /*** Assign SPI1 pins using PPS ***/ SS2_DIR = DIR_OUT; SDI2_DIR = DIR_IN ; SDO2_DIR = DIR_OUT; SCK2_DIR = DIR_OUT; iPPSOutput(OUT_PIN_PPS_RP27, OUT_FN_PPS_SS2OUT); iPPSInput( IN_FN_PPS_SDI2 , IN_PIN_PPS_RP19 ); iPPSOutput(OUT_PIN_PPS_RP26, OUT_FN_PPS_SDO2); iPPSOutput(OUT_PIN_PPS_RP21, OUT_FN_PPS_SCK2OUT); }
// Set up the UART for the GSM chip void gsmSetup(void) { // Configure Port Direction TRISGbits.TRISG6 = 0; // Turn RG6 into output for GSM TX TRISGbits.TRISG7 = 1; // Turn RG7 into input for GSM RX // Configure PPS pins for GSM iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP26); // Assign U1RX to pin RP26 iPPSOutput(OUT_PIN_PPS_RP21,OUT_FN_PPS_U1TX); // Assign U1TX to pin RP21 // Close UART in case it's already open CloseUART1(); // Enable UART Interface ConfigIntUART1(UART_RX_INT_DIS | UART_RX_INT_PR7 | UART_TX_INT_DIS | UART_TX_INT_PR7); // Receive interrupt disabled // Transmit interrupt disabled OpenUART1(UART_EN, UART_TX_ENABLE, 25); // Module enable // BRG generates 4 clocks per bit period // Transmit enable // 9600 baud rate (@ 4 MHz FCY) }
/*.........................................................................................*/ void vPorts_Init(void) { /* Peripherical Pin Select Configuration*/ PPSUnLock; iPPSOutput(OUT_PIN_PPS_RP20, OUT_FN_PPS_U1TX); //PPS RP20 function UART1 -> Tx iPPSInput (IN_FN_PPS_U1RX, IN_PIN_PPS_RP21); //PPS RP21 function UART1 <- Rx PPSLock; /* General Ports Configuration */ TRISA = IOPORT_A_CFG; TRISB = IOPORT_B_CFG; TRISC = IOPORT_C_CFG; /*Push Buttons Configuration*/ /* PushB_Up_Tris = 1 PushB_Enter_Tris = 1 PushB_Down_Tris = 1*/ /*LCD Pins Configuration*/ LCD_DB7_Lat = 0; LCD_DB6_Lat = 0; LCD_DB5_Lat = 0; LCD_DB4_Lat = 0; LCD_E_Lat = 0; LCD_RS_Lat = 0; LCD_Pwr_Lat = 1; }
int main() { ADB_FILE_HANDLE f; iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP2); //Assign U2RX to pin RP2 (42) iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_U2TX); //Assign U2TX to pin RP4 (43) UART2Init(); UART2PrintString("***** Hello from app! *******\r\n"); f = ADBFileRead("/data/data/ioio.manager/files/image.ioio", &FileCallback); UART2PrintString("***** file handle: "); UART2PutHexWord(f); UART2PrintString("*****\r\n"); state = STATE_READ_FILE; while (state == STATE_READ_FILE) { BootloaderTasks(); } // blink LED TRISFbits.TRISF3 = 0; while (1) { long i = 1000L; LATFbits.LATF3 = 0; while (i--); i = 1000000L; LATFbits.LATF3 = 1; while (i--); BootloaderTasks(); } }
void remapAllPins() { PPSUnLock(); /* pins used by mimac to comunicate radio */ iPPSInput(IN_FN_PPS_INT1, IN_PIN_PPS_RP17); /* pins used by usart loging */ iPPSOutput(OUT_PIN_PPS_RP21, OUT_FN_PPS_TX2CK2); // Mapping USART2 TX iPPSInput(IN_FN_PPS_RX2DT2, IN_PIN_PPS_RP22); // Mapping USART2 RX iPPSInput(IN_FN_PPS_INT2, IN_PIN_PPS_RP4); iPPSOutput(OUT_PIN_PPS_RP23, OUT_FN_PPS_CCP1P1A); // LEDs mapped to PWM iPPSOutput(OUT_PIN_PPS_RP24, OUT_FN_PPS_P1B); // Lock System PPSLock(); }
/****************************************************************************** * 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) { // Real time clock start RtccInitClock(); RtccWrOn(); { rtccTimeDate initd; initd.f.year=0x10; initd.f.mon=0x01; initd.f.mday=0x01; initd.f.wday=5; // 2010.01.01 is friday initd.f.hour=0; initd.f.min=0; initd.f.sec=0; RtccWriteTimeDate(&initd,FALSE); RtccWriteAlrmTimeDate(&initd); } mRtccOn(); mRtccAlrmEnable(); RtccSetAlarmRpt(RTCC_RPT_MIN,TRUE); // Mtouch init mTouchInit(); mTouchCalibrate(); cmdstr[0]=0; screen=0; screenvalid=0; position=0; buttonstate.Val=0; buttonpressed.Val=0; devicereset=0; clockss=0; resetcounter=0; alarmcnt=0; TRISBbits.TRISB1=0; PPSUnLock(); iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_CCP1P1A); //Configre RP24 as C1OUT pin PPSLock(); //----Configure pwm ---- period = 0xFF; OpenPWM1( period); //Configure PWM module and initialize PWM period //-----set duty cycle---- duty_cycle = 256; SetDCPWM1(duty_cycle); //set the duty cycle //----set pwm output---- outputconfig = HALF_OUT ; outputmode = PWM_MODE_1; SetOutputPWM1( outputconfig, outputmode); //output PWM in respective modes ADCON0bits.CHS=4; /* Make sure A/D interrupt is not set */ PIR1bits.ADIF = 0; /* Begin A/D conversion */ }//end UserInit
void ConfigPins_UART2(void) { /*** Assign UART2 pins using PPS ***/ _ANSB15 = 0; _ANSB14 = 0; TRISBbits.TRISB15 = 1; TRISBbits.TRISB14 = 0; iPPSInput(IN_FN_PPS_U2RX, IN_PIN_PPS_RP29); //Assing U1RX to pin P_RX1_RP iPPSOutput(OUT_PIN_PPS_RP14, OUT_FN_PPS_U2TX); //Assing U1TX to pin P_TX2_RP }
/* -------------------------------------------------------------------------------- [NAME] : ConfigPins_UART 1 [TYPE] : Internal Function & accessible publically through structure [INPUT] : None [RETURN] : None [DESCRIPTION]: This function maps the remappable pins to UART1. -------------------------------------------------------------------------------- */ void ConfigPins_UART1(void) { /*** Assign UART1 pins using PPS ***/ _ANSB4 = 0; _ANSB5 = 0; TRISBbits.TRISB4 = 1; TRISBbits.TRISB5 = 0; iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP28); //Assing U1RX to pin P_RX1_RP iPPSOutput(OUT_PIN_PPS_RP18, OUT_FN_PPS_U1TX); //Assing U1TX to pin P_TX2_RP }
void serio_init(uckernel_task handler) { serio_set_rx_handler(handler); new_queue(&tx_queue, tx_queue_data, QUEUE_SIZE, sizeof(uint8_t)); new_queue(&rx_queue, rx_queue_data, QUEUE_SIZE, sizeof(uint8_t)); iPPSInput(IN_FN_PPS_U2RX, IN_PIN_PPS_RP10); iPPSInput(IN_FN_PPS_U2CTS, IN_PIN_PPS_RPI32); iPPSOutput(OUT_PIN_PPS_RP17, OUT_FN_PPS_U2TX); iPPSOutput(OUT_PIN_PPS_RP31, OUT_FN_PPS_U2RTS); CloseUART2(); /*Enable UART intruupts*/ ConfigIntUART2(UART_RX_INT_EN | UART_RX_INT_PR6 | UART_TX_INT_EN | UART_TX_INT_PR6 | UART_INT_TX_BUF_EMPTY); /*UART initialized to 9600 baudrate @BRGH=0, 8bit,no parity and 1 stopbit*/ OpenUART2(UART_EN | UART_BRGH_FOUR, UART_TX_ENABLE, 34); serio_initialized = true; }
void map_io(void) { /* Attach SPI1 module to I/O pads on SD card holder */ iPPSInput(IN_FN_PPS_SDI1, IN_PIN_SD_SDI); iPPSOutput(OUT_PIN_SD_SCK, OUT_FN_PPS_SCK1_ALL); iPPSOutput(OUT_PIN_SD_SDO, OUT_FN_PPS_SDO1); /* Attach UART1 module to IO pin for 1-wire devices */ iPPSOutput(OUT_PIN_OW_TX, OUT_FN_PPS_U1TX); iPPSInput(IN_FN_PPS_U1RX, IN_PIN_OW_RX); #ifdef USE_GPS iPPSInput(IN_FN_PPS_U2RX, IN_PIN_GPS_RX); iPPSInput(IN_FN_PPS_IC1, IN_PIN_GPS_PPS); #endif /* Debug output pin for UART2 module */ iPPSOutput(OUT_PIN_DBG_TX, OUT_FN_PPS_U2TX); }
int main(void) { ADPCFG = 0xFFFF; // Ports as digital, not analog #warning "Building for dsPIC33FJ128GP804" ETH_CS = 1; RF_SPI_CS = 1; FLASH_CS1 = 1; FLASH_CS2 = 1; SysInitGpio(); RF_POWER = 0; SENSOR_PWR = 0; CNPU2bits.CN21PUE = 1; // Setup UART1 to ICSP pins PPSUnLock; iPPSOutput(OUT_PIN_PPS_RP0, OUT_FN_PPS_U1TX); iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP1); PPSLock; ExtIntInit(); //spiInit(1); UartInit(1, 115200*2); printf("Hello world!\r\n"); // Disable nested ISR //INTCON1bits.NSTDIS = 1; RtosTaskInit(); RfInit(); DbgInit(); RtosTaskRun(); //while(1); return 0; }
void gpsSetup(void) { /* Configure Port Direction */ TRISBbits.TRISB8 = 0; // Turn RB8 into output for GPS EN TRISBbits.TRISB9 = 1; // Turn RB9 into input for GPS FIX TRISBbits.TRISB14 = 1; // Turn RB14 into input for GPS RX TRISBbits.TRISB15 = 0; // Turn RB15 into output for GPS TX TRISFbits.TRISF4 = 1; // Turn RF4 into input for GPS PPS /* Configure PPS pins for GPS */ iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP14); // Assign U2RX to pin RP14 iPPSOutput(OUT_PIN_PPS_RP29,OUT_FN_PPS_U2TX); // Assign U2TX to pin RP29 /* Enable the GPS module */ PORTB |= 0x0100; /* Close UART in case it's already open */ CloseUART2(); /*Enable UART Interface */ ConfigIntUART2(UART_RX_INT_DIS | UART_RX_INT_PR6 | UART_TX_INT_DIS | UART_TX_INT_PR6); // Receive interrupt disabled // Priority RX interrupt 6 // Transmit interrupt disabled // Priority TX interrupt 6 OpenUART2(UART_EN, UART_TX_ENABLE, 25); // Module enable // Transmit enable // 9600 baud rate (@ 4 MHz internal clock) /* Initalize the Adafruit GPS libraries */ common_init(); }
/****************************************************************************** **** **** ** ** init() ** ** **** **** ******************************************************************************/ void init(void) { // Force WDT off for now ... having it on tends to confuse novice // users. csk_wdt_off(); // Keep interrupts off for now ... __disable_interrupt(); // All CSK control signals are active LOW. #if defined(__PIC24FJ256GA110__) // PSPM D // Minimal set of I/O ... only necessary control signals are configured as outputs. TRISA = 0xFFFF; TRISB = ~( BIT5); // TX3 TRISC = ~( BIT1); // -OE_USB TRISD = ~( BIT8+BIT5+BIT2+BIT1); // HS3, HS4 & HS5, TX2 TRISE = ~( BIT8+BIT4+BIT3+BIT2); // IO.30, -ON_SD, -ON_MHX & -OE_MHX TRISF = ~( BIT5+BIT3); // TX1 & TX0 PORTA = 0x0000; PORTB = 0x0000+BIT5; // TX3 initially HIGH PORTC = 0x0000+BIT1; // -OE_USB is OFF PORTD = 0x0000+BIT8; // TX2 initially HIGH PORTE = 0x0000+BIT4+BIT3+BIT2; // -ON_SD, -ON_MHX, -OE_MHX are OFF PORTF = 0x0000+BIT3+BIT5; // TX0 & TX1 initially HIGH. PORTG = 0x0000; AD1PCFGL = 0xFFFF; #elif defined(__PIC24FJ256GB110__) // PSPM E Rev A // Minimal set of I/O ... only necessary control signals are configured as outputs. TRISA = 0xFFFF; TRISB = ~( BIT5 ); // TX3 TRISC = ~( BIT1 ); // -OE_USB TRISD = ~( BIT9+BIT8+BIT7+ BIT5 ); // TX0, TX2, HS3, HS5 TRISE = ~( BIT8+ BIT4+BIT3+BIT2 ); // IO.30, -ON_SD, -ON_MHX & -OE_MHX TRISF = ~( BIT5 ); // TX1 TRISG = ~(BIT15 ); // HS4 PORTA = 0x0000; PORTB = 0x0000+BIT5; // TX3 initially HIGH PORTC = 0x0000+BIT1; // -OE_USB is OFF PORTD = 0x0000+BIT9+BIT8; // TX0, TX2 initially high PORTE = 0x0000+BIT4+BIT3+BIT2; // -ON_SD, -ON_MHX, -OE_MHX are OFF PORTF = 0x0000+BIT5; // TX1 initially high. PORTG = 0x0000; #elif defined(__PIC24FJ256GB210__) // PSPM E Rev B // Minimal set of I/O ... only necessary control signals are configured as outputs. TRISA = 0xFFFF; TRISB = ~( BIT5 ); // TX3 TRISC = ~( BIT1 ); // -OE_USB TRISD = ~( BIT9+BIT8+BIT7+ BIT5 ); // TX0, TX2, HS3, HS5 TRISE = ~( BIT8+ BIT4+BIT3+BIT2 ); // IO.30, -ON_SD, -ON_MHX & -OE_MHX TRISF = ~( BIT5 ); // TX1 TRISG = ~(BIT15 ); // HS4 PORTA = 0x0000; PORTB = 0x0000+BIT5; // TX3 initially HIGH PORTC = 0x0000+BIT1; // -OE_USB is OFF PORTD = 0x0000+BIT9+BIT8; // TX0, TX2 initially high PORTE = 0x0000+BIT4+BIT3+BIT2; // -ON_SD, -ON_MHX, -OE_MHX are OFF PORTF = 0x0000+BIT5; // TX1 initially high. PORTG = 0x0000; ANSA = 0x0000; ANSB = 0x0000; ANSC = 0x0000; ANSD = 0x0000; ANSE = 0x0000; ANSF = 0x0000; ANSG = 0x0000; #else #error PIC24F device not supported by CubeSat Kit #endif // High-level inits (works at any clock speed). csk_mhx_close(); csk_mhx_pwr_off(); csk_usb_close(); csk_led_status_close(); // Set up to run with primary oscillator. // See _CONFIG2 above. A configuration-word-centric setup of the // oscillator(s) was chosen because of its relative simplicity. // Note e.g. that PwrMgnt_OscSel() returns FALSE if clock switching // (FCKSM) is disabled ... // Set up Timer2 to run at system tick rate ConfigIntTimer2(T2_INT_ON & T2_INT_PRIOR_1); // Timer is configured for 10 msec (100Hz), with interrupts OpenTimer2(T2_ON & T2_IDLE_CON & T2_GATE_OFF & T2_PS_1_1 & T2_32BIT_MODE_OFF & T2_SOURCE_INT, (MAIN_XTAL_FREQ/(2*100))); // A prescalar is not required because 8E6/200 < 16 bits. #if defined(__PIC24FJ256GA110__) // PSPM D // Configure I/O pins for UARTs via PIC24's PPS system. // RP inputs must be configured as inputs! // CSK UART0 is used as the terminal, via USB, IO.6(RP17) & IO.7(RP10) // CSK UART0 (PIC24 UART1) TX/RX = IO.6/IO.7 iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); // CSK UART1 can talk to GPSRM 1 via IO.4(RP16) & IO.5(RP30) // CSK UART1 (PIC24 UART2) TX/RX = IO.4/IO.5 iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP30); iPPSOutput(OUT_PIN_PPS_RP16,OUT_FN_PPS_U2TX); // CSK UART2 can talk to GPSRM 1 via IO.16(RP2) & IO.17(RP22) // CSK UART2 (PIC24 UART3) TX/RX = IO.16/IO.17 iPPSInput(IN_FN_PPS_U3RX,IN_PIN_PPS_RP22); iPPSOutput(OUT_PIN_PPS_RP2,OUT_FN_PPS_U3TX); // CSK UART3 can talk to GPSRM 1 via IO.32(RP18) & IO.33(RP28) // CSK UART3 (PIC24 UART4) TX/RX = IO.4/IO.5 iPPSInput(IN_FN_PPS_U4RX,IN_PIN_PPS_RP28); iPPSOutput(OUT_PIN_PPS_RP18,OUT_FN_PPS_U4TX); #elif defined(__PIC24FJ256GB110__) || defined(__PIC24FJ256GB210__) iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); // RF4 iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); // RF5 iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP30); // RF2 iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_U2TX); // RD9 iPPSInput(IN_FN_PPS_U3RX,IN_PIN_PPS_RP22); // RD3 iPPSOutput(OUT_PIN_PPS_RP2,OUT_FN_PPS_U3TX); // RD8 iPPSInput(IN_FN_PPS_U4RX,IN_PIN_PPS_RP28); // RB4 iPPSOutput(OUT_PIN_PPS_RP18,OUT_FN_PPS_U4TX); // RB5 #else #error PIC24F device not supported by CubeSat Kit #endif // Init UARTs to 9600,N,8,1 // UARTs won't transmit until interrupts are enabled ... csk_uart0_open(CSK_UART_9600_N81); csk_uart1_open(CSK_UART_9600_N81); csk_uart2_open(CSK_UART_9600_N81); csk_uart3_open(CSK_UART_9600_N81); csk_usb_open(); csk_uart0_puts(STR_CRLF STR_CRLF); csk_uart0_puts("Pumpkin " STR_CSK_TARGET " " STR_APP_NAME "." STR_CRLF); csk_uart0_puts(STR_VERSION "." STR_CRLF); csk_uart0_puts(STR_WARNING "." STR_CRLF); i2c1_open(); } /* init() */
void log_init() { iPPSOutput(OUT_PIN_PPS_RP28,OUT_FN_PPS_U2TX); // U2TX to pin 32 UART2Init(); }
int main(void) { /*** LOCAL VARIABLES ***/ unsigned int period , period2, config1=0 ,config2=0; Int_flag = 0; /*** CONFIGURE OSCILLATOR ***/ SET_FreqOsc( FRCDIV_1MHZ ); //Set Frequency /*** CONFIGURE HARDWARE ****/ Hardware_INIT(); //Initialise Hardware functions LCD_INIT(); //NOTE: PPS Unlock & Lock Sequence not required when Using Hardware.ConfigPins_Default() __builtin_write_OSCCONL(OSCCON & 0xbf); //UNLCOK PPS // Hardware.ConfigPins_PWM(USE1 | USE2 | USE4 | USE3 ); //Configure the PWM Pins to use PWM4_DIR = DIR_OUT; // Set PWM4 as Output PWM4 = C_OFF; iPPSInput(IN_FN_PPS_IC1, IN_PIN_PPS_RP10); iPPSOutput(OUT_PIN_PPS_RP12, OUT_FN_PPS_OC1); iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_OC9); __builtin_write_OSCCONL(OSCCON | 0x40); //LOCK PPS Int_flag = 0; // timers T1CON = 0x8000; T2CON = 0x8000; T1CONbits.TCKPS = 0b00; T2CONbits.TCKPS = 0b01; T3CON = 0x8000; T4CON = 0x8000; T4CONbits.TCKPS = 0b01; // input capture ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_4); config1 = IC_IDLE_STOP | IC_TIMER2_SRC | IC_INT_1CAPTURE | IC_EVERY_EDGE; config2 = IC_CASCADE_DISABLE /*| IC_SYNC_ENABLE | IC_SYNC_TRIG_IN_TMR2*/; OpenCapture1_GB(config1, config2); // output compare EnableIntOC9; OC9R = 0x5FF0; OC9RS = 0x5FF4; OC9CON1bits.OCTSEL = 0b000; OC9CON2bits.SYNCSEL = 0x1F; OC9CON1bits.OCM = 0b110; OC9CON2bits.OCINV = 1; // PR1 = 2000;// period for timer 1 // PR2 = 0xFFFF; // IFS0bits.IC1IF = 0; // Clear the IC1 interrupt status flag // IEC0bits.IC1IE = 1; // Enable IC1 interrupts // IPC0bits.IC1IP = 1; // Set module interrupt priority as 1 // IC1CON1 = 0x1C24; // IC1CON2 = 0x0040; // IC1CON1bits.ICSIDL = 0; //Continue in idle mode // IC1CON1bits.ICI = 0b00; //Interrupt on every capture // IC1CON1bits.ICM = 0b001; //Every edge // EnableIntIC1; /*** INITIALIZE PERIPHERAL ***/ // TIMER3_INIT( 1000, TMR_INT_PRI7 ); PWM1_INIT(PWMsrc_FOSC, 20); //Set PWM Period of 20 mSec // PWM3_INIT(PWMsrc_Timer1, 100); //Set PWM Period of 1000 mSec // PWM3_INIT(PWMsrc_FOSC, 30); /*** APPLICATION CODE BEGINS ***/ // PWM3_SET_PulseWidth(1); PWM1_SET_PulseWidth(1.3); // PWM3_SET_PulseWidth(10); //Set PWM1 Dutycycle Time 5 mSec //To Test, Probe the Pin1 of PWM connector J7 LED1_DIR = DIR_OUT; // Set LED1 as Output LED1 = C_OFF; LED2_DIR = DIR_OUT; // Set LED1 as Output LED2 = C_OFF; LED3_DIR = DIR_OUT; // Set LED1 as Output LED3 = C_OFF; /*** ENTER ETERNITY ***/ int buf[100]; Int_flag = 2; //LOCK PPS while (1) { // while (!read_enable); //wait till two succssive falling edges // M_ToggleIO(LED1); // period = timer_second_edge - timer_first_edge; // period2 = 65535 + timer_first_edge - timer_second_edge; int j; for(j=1;j<5;j++){ if(edge_buffer[j+1] - edge_buffer[j] > 30){ if(edge_buffer[j+1] - edge_buffer[j] < 500){ pulse = edge_buffer[j+1] - edge_buffer[j]; break; }else{ pulse = 11111; } }else{ pulse = 11111; } } if(pulse != 11111){ LCD_Clear(); sprintf(A_Str_U8, "%u", pulse); // Print variable to string LCD_WriteString(1, 1, A_Str_U8); } // sprintf(A_Str_U8, "%u", timer_second_edge); // Print variable to string // LCD_WriteString(1, 8, A_Str_U8); // sprintf(A_Str_U8, "%u", abs(timer_second_edge - timer_first_edge)); // Print variable to string // LCD_WriteString(2, 1, A_Str_U8); // sprintf(A_Str_U8, "%u", abs(timer_third_edge - timer_second_edge)); // Print variable to string // LCD_WriteString(2, 7, A_Str_U8); // DELAY_mSec(100); // sprintf(A_Str_U8, "%d", Interrupt_Count); // Print variable to string // LCD_WriteString(2, 8, A_Str_U8); // Int_flag = 0; read_enable = 0; // __builtin_write_OSCCONL(OSCCON & 0xbf); // iPPSOutput(OUT_PIN_PPS_RP10, OUT_FN_PPS_OC4); // __builtin_write_OSCCONL(OSCCON | 0x40); // // PWM4 = C_OFF; // PWM4 = C_ON; // PWM4 = C_OFF; // DELAY_mSec(200); // DELAY_mSec(200); // LATEbits.LATE5 = 1; // DELAY_mSec(500); // LATEbits.LATE5 = 0; // ReadCapture1_v4(buf) ; /*** RECURRING CODE HERE***/ //Use TIMER Interrupts to perform time based tasks at fixed interval. //Use Peripheral Interrupts to perform event based tasks int i; for (i = 40; i < 100; i++) { PWM1_SET_PulseWidth(0.02 * i); DELAY_mSec(20); } while (i>=40) { PWM1_SET_PulseWidth(0.02 * i); DELAY_mSec(20); i--; } } }
/** * Configurar los pines de I/O para el bus PC-104 */ void GPIO_PC104_init(void) { //------------------------------------------------------------------------------ #if (SCH_PAYBUS_ONBOARD==1) // I2C3 para perifericos de Payload // H1.01 SDA3/CN65/PMD7/RE7 (Pin 5) => pin es RE7 // H1.02 SCL3/CN64/PMD6/RE6 (Pin 4) => pin es RE6 // I2C-3 habilita el mismo sus pines cuando se configura i2c3_open(157, SCH_I2C3_ADDR); #else // H1.01 SDA3/CN65/PMD7/RE7 (Pin 5) => pin es RE7 _TRISE7=0; //pin 0-output 1-input. _LATE7=0; //parte en 0 // H1.02 SCL3/CN64/PMD6/RE6 (Pin 4) => pin es RE6 _TRISE6=0; //pin 0-output 1-input. _LATE6=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_MGN_ONBOARD==1) // H1.03 SDA2/CN36/RA3 (Pin 59) => pin es RA3 _TRISA3=0; //pin 0-output 1-input. PPC_MGN_SWITCH=0; //parte en 0 //pin es Magnetorquer_switch #else // H1.03 SDA2/CN36/RA3 (Pin 59) => pin es RA3 _TRISA3=0; //pin 0-output 1-input. _LATA3=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_PAY_CAM_nMEMFLASH_ONBOARD==1) // H1.04 SCL2/CN35/RA2 (Pin 58) => pin es RA2 _TRISA2=0; //pin 0-output 1-input. PPC_CAM_SWITCH=0; //parte en 0 //pin es Camera_switch #else // H1.04 SCL2/CN35/RA2 (Pin 58) => pin es RA2 _TRISA2=0; //pin 0-output 1-input. _LATA2=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_PAY_GPS_ONBOARD==1) // H1.05 RP25/CN13/PMWR/RD4 (Pin 81) => pin es RD4 _TRISD4=0; //pin 0-output 1-input. PPC_GPS_nRESET=1; //parte en 1 <=> no-reset //pin es GPS_nReset #else // H1.05 RP25/CN13/PMWR/RD4 (Pin 81) => pin es RD4 _TRISD4=0; //pin 0-output 1-input. _LATD4=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_PAY_CAM_nMEMFLASH_ONBOARD==1) // H1.06 RPI42/CN57/RD12 (Pin 79) => pin es RD12 _TRISD12=1; //pin 0-output 1-input. PPC_CAM_HOLD_CHECK; //pin es Hold_Camera #else // H1.06 RPI42/CN57/RD12 (Pin 79) => pin es RD12 _TRISD12=1; //pin 0-output 1-input. _LATD12=0; //parte en 0 #endif //------------------------------------------------------------------------------ // H1.07 RP22/CN52/PMBE/RD3 (Pin 78) => pin es RD3 _TRISD3=0; //pin 0-output 1-input. _LATD3=0; //parte en 0 // H1.08 RTCC/RP2/CN53/RD8 (Pin 68) => pin es RD8 _TRISD8=0; //pin 0-output 1-input. _LATD8=0; //parte en 0 // H1.09 RPI32/CN75/RF12 (Pin 40) => pin es RF12 _TRISF12=0; //pin 0-output 1-input. _LATF12=0; //parte en 0 //------------------------------------------------------------------------------ // H1.10 RP31/CN76/RF13 (Pin 39) => pin es RF13 #if (SCH_PAY_LANGMUIR_ONBOARD==1) _TRISF13=0; //pin 0-output 1-input. PPC_LANGMUIR_DEP_SWITCH=0; //parte en 0 //pin es LANGMUIR_switch #else _TRISF13=0; //pin 0-output 1-input. _LATF13=0; //parte en 0. #endif //------------------------------------------------------------------------------ // H1.11 RPI43/CN20/RD14 (Pin 47) => pin es RD14 _TRISD14=0; //pin 0-output 1-input. _LATD14=0; //parte en 0 //------------------------------------------------------------------------------ // H1.12 RP5/CN21/RD15 (Pin 48) => pin es RD15 #if (SCH_PAY_GPS_ONBOARD==1) _TRISD15=0; //pin 0-output 1-input. PPC_GPS_SWITCH=0; //parte en 0 //pin es GPS_switch #else _TRISD15=0; //pin 0-output 1-input. _LATD15=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_PAY_CAM_nMEMFLASH_ONBOARD==1) //Pines para la Camara con SPI-1 (SCK1, SDI1, SDO1 nSS1 y nWP) // H1.13 C1IND/RP21/CN8/PMA5/RG6 (Pin 10) => pin es RP21 (SCK) iPPSOutput(OUT_PIN_PPS_RP21,OUT_FN_PPS_SCK1OUT); //iPPSOutput(RPOR10bits.RP21R,0x08); // H1.14 C1INC/RP26/CN9/PMA4/RG7 (Pin 11) => pin es RP26 (SDI) _TRISG7=1; //pin 0-output 1-input. iPPSInput(IN_FN_PPS_SDI1,IN_PIN_PPS_RP26); // H1.15 C2IND/RP19/CN10/PMA3/RG8 (Pin 12) => pin es RP19 (SDO) _TRISG8=0; //pin 0-output 1-input. iPPSOutput(OUT_PIN_PPS_RP19,OUT_FN_PPS_SDO1); //iPPSOutput(RPOR5bits.RP19R,OUT_FN_PPS_SDO1); // H1.16 C2INC/RP27/CN11/PMA2/RG9 (Pin 14) => pin es RG9 (nCS) _TRISG9=0; //pin 0-output 1-input. _LATG9=0; //parte en 0 Open_SPI_1_default(); SPI_nSS_1=1; //nCS de la camara #else //SPI_1 es configurado en PPM_init() para la MemFlash en los pines 70, 71, 72, 80 y 83 // H1.13 C1IND/RP21/CN8/PMA5/RG6 (Pin 10) => pin es RG6 _TRISG6=0; //pin 0-output 1-input. _LATG6=0; //parte en 0 // H1.14 C1INC/RP26/CN9/PMA4/RG7 (Pin 11) => pin es RG7 _TRISG7=0; //pin 0-output 1-input. _LATG7=0; //parte en 0 // H1.15 C2IND/RP19/CN10/PMA3/RG8 (Pin 12) => pin es RG8 _TRISG8=0; //pin 0-output 1-input. _LATG8=0; //parte en 0 // H1.16 C2INC/RP27/CN11/PMA2/RG9 (Pin 14) => pin es RG9 _TRISG9=0; //pin 0-output 1-input. _LATG9=0; //parte en 0 #endif //------------------------------------------------------------------------------ //Conifg para Consola: // H1.17 - U1RX - RP10 - IO.7 - UART 1 PARA CONSOLA SERIAL iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); // H1.18 - U1TX - RP17 - IO.6 - UART 1 PARA CONSOLA SERIAL iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); //UART1 - CONSOLA SERIAL - 19200, 8, N, 1 */ //ConfigRS232(51, RS2_M_UART1); //19200 ConfigRS232(25, RS2_M_UART1); //38400 EnableIntU1RX; SetPriorityIntU1RX(5); //------------------------------------------------------------------------------ #if (SCH_PAY_LANGMUIR_ONBOARD == 1) // UART3 para la Langmiur // H1.19 RP30/CN70/RF2 (Pin 52) => (URX3) para el PAY_LANGMUIR iPPSInput(IN_FN_PPS_U3RX,IN_PIN_PPS_RP30); // H1.20 RP16/CN71/RF3 (Pin 51) => (UTX3) para PAY_LANGMUIR iPPSOutput(OUT_PIN_PPS_RP16,OUT_FN_PPS_U3TX); //UART3 para PAY_LANGMUIR ConfigRS232(25, RS2_M_UART3); EnableIntU3RX; SetPriorityIntU3RX(5); #else // H1.19 RP30/CN70/RF2 (Pin 52) => pin es RF2 _TRISF2=0; //pin 0-output 1-input. _LATF2=0; //parte en 0 // H1.20 RP16/CN71/RF3 (Pin 51) => pin es RF3 _TRISF3=0; //pin 0-output 1-input. _LATF3=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_MEMSD_ONBOARD==1) // SPI2 para Tarjeta SD de la MB // H1.21 RP4/CN54/RD9 (Pin 69) => pin es RP4 (SCK) iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_SCK2OUT); // H1.22 RPI44/CN73/RF7 (pin 54) => pin es RPI44 (SDI) iPPSInput(IN_FN_PPS_SDI2,IN_PIN_PPS_RPI44); // H1.23 RP15/CN74/RF8 (Pin 53) => pin es RP15 (SDO) iPPSOutput(OUT_PIN_PPS_RP15,OUT_FN_PPS_SDO2); // H1.24 CN63/PMD5/RE5 (Pin 3) => pin es RE5 (nSS) _TRISE5=0; //pin 0-output 1-input SPI_nSS_2=1; Open_SPI_2_default(); //SPI_SDI_2 //SPI_SCK_2 //SPI_SDO_2 SPI_nSS_2=1; #else // H1.21 RP4/CN54/RD9 (Pin 69) => pin es RD9 _TRISD9=0; //pin 0-output 1-input _LATD9=0; //parte en 0 // H1.22 RPI44/CN73/RF7 (pin 54) => pin es RF7 _TRISF7=0; //pin 0-output 1-input _LATF7=0; //parte en 0 // H1.23 RP15/CN74/RF8 (Pin 53) => pin es RF8 _TRISF8=0; //pin 0-output 1-input _LATF8=0; //parte en 0 // H1.24 CN63/PMD5/RE5 (Pin 3) => pin es RE5 _TRISE5=0; //pin 0-output 1-input _LATE5=0; //parte en 0 #endif //------------------------------------------------------------------------------ // H1.25 Fault [Active Low] // Este pin del header, no tiene un pin del PIC asignado // H1.26 PMA6/VREF+/CN42/RA10 (Pin 29) => pin es RA10 _VCFG=0b000; // Vr+=Vdd, Vr-=Vss => Vref+ no es usado (_VCFG es bit 15:13 de ADC1CON2) _TRISA10=0; //pin 0-output 1-input. _LATA10=0; //parte en 0 // H1.27 Sense // Este pin del header, no tiene un pin del PIC asignado // H1.28 VREF1 // Este pin del header, no tiene un pin del PIC asignado // H1.29 Reset [Active Low] // Este pin del header, no tiene un pin del PIC asignado // H1.30 VREF-/CN41/PMA7/RA9 (Pin 28) => pin es RA9 _VCFG=0b000; // Vr+=Vdd, Vr-=Vss => Vref- no es usado (_VCFG es bit 15:13 de ADC1CON2) _TRISA9=0; //pin 0-output 1-input. _LATA9=0; //parte en 0 // H1.31 OFF_VCC // Este pin del header, no tiene un pin del PIC asignado // H1.32 5V_USB // Este pin del header, no tiene un pin del PIC asignado // H1.33 PWR_MHX // Este pin del header, no tiene un pin del PIC asignado // H1.34 RST_MHX [Active Low] HS[5..0] //9 RPI41/CN48/RC4 => pin es RC4 //HSO _TRISC4=0; //pin 0-output 1-input. _LATC4=0; // parte en 0 // H1.35 CTS_MHX [Active Low] HS[5..0] //8 RPI40/CN47/RC3 => pin es RC3 //HS1 _TRISC3=0; //pin 0-output 1-input. _LATC3=0; // parte en 0 // H1.36 RTS_MHX [Active Low] HS[5..0] //76 RP24/CN50/RD1 => pin es RD1 //HS5 _TRISD1=0; //pin 0-output 1-input. _LATD1=0; // parte en 0 // H1.37 DSR_MHX [Active Low] HS[5..0] //82 RP20/CN14/PMRD/RD5 => pin es RD5 //HS3 _TRISD5=0; //pin 0-output 1-input. _LATD5=0; // parte en 0 // H1.38 DTR_MHX [Active Low] HS[5..0] //77 RP23/CN51/RD2 => pin es RD2 //HS4 _TRISD2=0; //pin 0-output 1-input. _LATD2=0; // parte en 0 // H1.39 TXD_MHX // copia de H1.18 // H1.40 RXD_MHX // copia de H1.17 //------------------------------------------------------------------------------ #if ((SCH_SYSBUS_ONBOARD == 1) || (SCH_TRX_ONBOARD == 1)) // I2C1 para TRX, EPS y otros perifericos del sistema // H1.41 SDA1/CN84/RG3 (Pin 56) => pin es SDA1 // H1.42 VBACKUP // Este pin del header, no tiene un pin del PIC asignado // H1.43 SCL1/CN83/RG2 (Pin 57) => pin es SCL1 // I2C-1 habilita el mismo sus pines cuando se configura i2c1_open(37, SCH_I2C1_ADDR); #else // H1.41 SDA1/CN84/RG3 (Pin 56) => pin es RG3 _TRISG3=0; //pin 0-output 1-input. _LATG3=0; // parte en 0 // H1.42 VBACKUP // Este pin del header, no tiene un pin del PIC asignado // H1.43 SCL1/CN83/RG2 (Pin 57) => pin es RG2 _TRISG2=0; //pin 0-output 1-input. _LATG2=0; // parte en 0 #endif //------------------------------------------------------------------------------ // H1.44 RSVD0 // Este pin del header, no tiene un pin del PIC asignado // H1.45 RSVD1 // Este pin del header, no tiene un pin del PIC asignado // H1.46 RSVD2 // Este pin del header, no tiene un pin del PIC asignado // H1.47 USER0 // Este pin del header, no tiene un pin del PIC asignado // H1.48 USER1 // Este pin del header, no tiene un pin del PIC asignado // H1.49 USER2 // Este pin del header, no tiene un pin del PIC asignado // H1.50 USER3 // Este pin del header, no tiene un pin del PIC asignado // H1.51 USER4 // Este pin del header, no tiene un pin del PIC asignado // H1.52 USER5 // Este pin del header, no tiene un pin del PIC asignado //------------------------------------------------------------------------------ // H2.01 AN15/REFO/RP29/CN12/PMA0/RB15 (Pin 44) => pin es RB15 _PCFG15=1; //pin 0-ADC 1- I/O _TRISB15=0; //pin 0-output 1-input. _LATB15=0; //parte en 0 // H2.02 AN14/CTPLS/RP14/CN32/PMA1/RB14 (Pin 43) => pin es RB14 _PCFG14=1; //pin 0-ADC 1- I/O _TRISB14=0; //pin 0-output 1-input. _LATB14=0; //parte en 0 //------------------------------------------------------------------------------ #if (SCH_PAY_FIS_ONBOARD==1) // H2.03 AN13/CTED1/CN31/PMA10/RB13 (Pin 42) => pin es AN13 (SENS1) _PCFG13=0; //pin 0-ADC 1- I/O _TRISB13=1; //pin 0-output 1-input. //_LATB13=0; //parte en 0 // H2.04 AN12/CTED2/CN30/PMA11/RB12 (Pin 41) => pin es RB12 (nSS) _PCFG12=1; //pin 0-ADC 1- I/O _TRISB12=0; //pin 0-output 1-input. SPI_nSS_3=1; //parte en 1 // H2.05 AN11/CN29/PMA12/RB11 (Pin 35) => pin es AN11 (SENS2) _PCFG11=0; //pin 0-ADC 1- I/O _TRISB11=1; //pin 0-output 1-input. //_LATB11=0; //parte en 0 // H2.06 AN10/CVREF/CN28/PMA13/RB10 (Pin 34) => pin es RB10 _PCFG10=1; //pin 0-ADC 1- I/O _TRISB10=0; //pin 0-output 1-input. _LATB10=0; //parte en 0 // H2.07 AN9/RP9/CN27/RB9 (Pin 33) => pin es RP9 (SCK) _PCFG9=1; //pin 0-ADC 1- I/O _TRISB9=0; //pin 0-output 1-input. iPPSOutput(OUT_PIN_PPS_RP9,OUT_FN_PPS_SCK3OUT); //_LATB9=0; //parte en 0 // H2.08 AN8/RP8/CN26/RB8 (Pin 32) => pin es RP8 (SDO) _PCFG8=1; //pin 0-ADC 1- I/O _TRISB8=0; //pin 0-output 1-input. iPPSOutput(OUT_PIN_PPS_RP8,OUT_FN_PPS_SDO3); //_LATB8=0; //parte en 0 Open_SPI_3_default(); //SPI_SDI_3 no existe //SPI_SCK_3 //SPI_SDO_3 SPI_nSS_3=1; #else // H2.03 AN13/CTED1/CN31/PMA10/RB13 (Pin 42) => pin es RB13 _PCFG13=1; //pin 0-ADC 1- I/O _TRISB13=0; //pin 0-output 1-input. _LATB13=0; //parte en 0 // H2.04 AN12/CTED2/CN30/PMA11/RB12 (Pin 41) => pin es RB12 _PCFG12=1; //pin 0-ADC 1- I/O _TRISB12=0; //pin 0-output 1-input. _LATB12=0; //parte en 0 // H2.05 AN11/CN29/PMA12/RB11 (Pin 35) => pin es RB11 _TRISB11=0; //pin 0-output 1-input. _LATB11=0; //parte en 0 // H2.06 AN10/CVREF/CN28/PMA13/RB10 (Pin 34) => pin es RB10 _PCFG10=1; //pin 0-ADC 1- I/O _TRISB10=0; //pin 0-output 1-input. _LATB10=0; //parte en 0 // H2.07 AN9/RP9/CN27/RB9 (Pin 33) => pin es RB9 _PCFG9=1; //pin 0-ADC 1- I/O _TRISB9=0; //pin 0-output 1-input. _LATB9=0; //parte en 0 // H2.08 AN8/RP8/CN26/RB8 (Pin 32) => pin es RB8 _PCFG8=1; //pin 0-ADC 1- I/O _TRISB8=0; //pin 0-output 1-input. _LATB8=0; //parte en 0 #endif //------------------------------------------------------------------------------ //Estos pines son TMS_COM, TCK_COM, TDI_COM, TDO_COM del JTAG del TRX //Sin embargo no son ni serian ocupados // H2.09 PGED2/AN7/RP7/CN25/RB7 (Pin 27) => pin es RB7 _PCFG7=1; //pin 0-ADC 1- I/O _TRISB7=0; //pin 0-output 1-input. _LATB7=0; //parte en 0 // H2.10 PGEC2/AN6/RP6/CN24/RB6 (Pin 26) => pin es RB6 _PCFG6=1; //pin 0-ADC 1- I/O _TRISB6=0; //pin 0-output 1-input. _LATB6=0; //parte en 0 // H2.11 PGED1/AN0/RP0/CN2/RB0 (Pin 25) => pin es PGED1 // este pin es usado como PGED1 para programming/debugging con ICD // por lo que modificarlo implica posibles errores al quierer debuggear con el ICD3 // H2.12 PGEC1/AN1/RP1/CN3/RB1 (Pin 24) => pin es PGEC1 // este pin es usado como PGEC1 para programming/debugging con ICD // por lo que modificarlo implica posibles errores al querer debuggear con el ICD3 //------------------------------------------------------------------------------ // H2.13 AN2/C2INB/RP13/CN4/RB2 (Pin 23) => pin es RB2 _PCFG2=1; //pin 0-ADC 1- I/O _TRISB2=0; //pin 0-output 1-input. _LATB2=1; //parte en 1 (por si TRX esta conectado, aunque no deberia) // H2.14 AN3/C2INA/CN5/RB3 (Pin 22) => pin es RB3 _PCFG3=1; //pin 0-ADC 1- I/O _TRISB3=0; //pin 0-output 1-input. _LATB3=1; //parte en (por si TRX esta conectado, aunque no deberia) //------------------------------------------------------------------------------ #if (SCH_PAY_GPS_ONBOARD==1) // H2.15 PGED3/AN4/C1INB/RP28/CN6/RB4 (Pin 21) => pin es RP28 (TX del UART4) _PCFG4=1; //pin 0-ADC 1- I/O _TRISB4=0; //pin 0-output 1-input. _LATB4=0; //parte en 0 iPPSOutput(OUT_PIN_PPS_RP28,OUT_FN_PPS_U4TX); // H2.16 PGEC3/AN5/C1INA/RP18/CN7/RB5 (Pin 20) => pin es RP18 (RX del UART4) _PCFG5=1; //pin 0-ADC 1- I/O _TRISB5=1; //pin 0-output 1-input. //_LATB5=0; //parte en 0 iPPSInput(IN_FN_PPS_U4RX,IN_PIN_PPS_RP18); //UART4 para GPS ConfigRS232(8, RS2_M_UART4); EnableIntU4RX; SetPriorityIntU4RX(5); #else // H2.15 PGED3/AN4/C1INB/RP28/CN6/RB4 (Pin 21) => pin es RB4 _PCFG4=1; //pin 0-ADC 1- I/O _TRISB4=0; //pin 0-output 1-input. _LATB4=0; //parte en 0 // H2.16 PGEC3/AN5/C1INA/RP18/CN7/RB5 (Pin 20) => pin es RB5 _PCFG5=1; //pin 0-ADC 1- I/O _TRISB5=0; //pin 0-output 1-input. _LATB5=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_ANTENNA_ONBOARD==1) // H2.17 RPI34/CN67/RE9 (Pin 19) => pin es RE9 (ANTENNA1) _TRISE9=0; //pin 0-output 1-input. PPC_ANT1_SWITCH=0; //parte en 0 //pin es ANT1_switch // H2.18 RPI33/CN66/RE8 (Pin 18) => pin es RE8 (ANTENNA2) _TRISE8=0; //pin 0-output 1-input. PPC_ANT2_SWITCH=0; //parte en 0 //pin es ANT2_switch #else // H2.17 RPI34/CN67/RE9 (Pin 19) => pin es RE9 _TRISE9=0; //pin 0-output 1-input. _LATE9=0; //parte en 0 // H2.18 RPI33/CN66/RE8 (Pin 18) => pin es RE8 _TRISE8=0; //pin 0-output 1-input. _LATE8=0; //parte en 0 #endif //------------------------------------------------------------------------------ // H2.19 ASDA2/RPI35/CN44/RA15 (Pin 67) => pin es RA15, pues I2C-2 esta en H1.3 y H1.4 _TRISA15=0; //pin 0-output 1-input. _LATA15=0; //parte en 0 // H2.20 ASCL2/RPI36/CN43/RA14 (Pin 66) => pin es RA14, pues I2C-2 esta en H1.3 y H1.4 _TRISA14=0; //pin 0-output 1-input. _LATA14=0; //parte en 0 // H2.21 CN77/RG0 (Pin 90) => pin es RG0 _TRISG0=0; //pin 0-output 1-input. _LATG0=0; //parte en 0 //------------------------------------------------------------------------------ #if (SCH_ANTENNA_ONBOARD==1) // H2.22 CN78/RG1 (Pin 89) => pin es RG1 _TRISG1=0; //pin 0-output 1-input. PPC_ANT12_SWITCH=0; //parte en 0 //pin es ANT12_switch // H2.23 CN68/RF0 (Pin 87) => pin es PPC_ANT12_CHECK (CHECK ANTENNA DEPLOY) _TRISF0=1; //pin 0-output 1-input. #else // H2.22 CN78/RG1 (Pin 89) => pin es RG1 _TRISG1=0; //pin 0-output 1-input. _LATG1=0; //parte en 0 // H2.23 CN68/RF0 (Pin 87) => pin es RF0 _TRISF0=1; //pin 0-output 1-input. _LATF0=0; //parte en 0 #endif //------------------------------------------------------------------------------ #if (SCH_PAY_GYRO_ONBOARD==1) // H2.24 CN69/RF1 (Pin 88) => pin es PPC_GYRO_INT2_CHECK _TRISF1=1; //pin 0-output 1-input. //_LATF1=0; //parte en 0 #else // H2.24 CN69/RF1 (Pin 88) => pin es RF1 _TRISF1=0; //pin 0-output 1-input. _LATF1=0; //parte en 0 #endif //------------------------------------------------------------------------------ // H2.25 5V_SYS // Este pin del header, no tiene un pin del PIC asignado // H2.26 5V_SYS // Este pin del header, no tiene un pin del PIC asignado // H2.27 VCC_SYS // Este pin del header, no tiene un pin del PIC asignado // H2.28 VCC_SYS // Este pin del header, no tiene un pin del PIC asignado // H2.29 DGND // Este pin del header, no tiene un pin del PIC asignado // H2.30 DGND // Este pin del header, no tiene un pin del PIC asignado // H2.31 AGND // Este pin del header, no tiene un pin del PIC asignado // H2.32 DGND // Este pin del header, no tiene un pin del PIC asignado // H2.33 S0 // Este pin del header, no tiene un pin del PIC asignado // H2.34 S0 // Este pin del header, no tiene un pin del PIC asignado // H2.35 S1 // Este pin del header, no tiene un pin del PIC asignado // H2.36 S1 // Este pin del header, no tiene un pin del PIC asignado // H2.37 S2 // Este pin del header, no tiene un pin del PIC asignado // H2.38 S2 // Este pin del header, no tiene un pin del PIC asignado // H2.39 S3 // Este pin del header, no tiene un pin del PIC asignado // H2.40 S3 // Este pin del header, no tiene un pin del PIC asignado // H2.41 S4 // Este pin del header, no tiene un pin del PIC asignado // H2.42 S4 // Este pin del header, no tiene un pin del PIC asignado // H2.43 S5 // Este pin del header, no tiene un pin del PIC asignado // H2.44 S5 // Este pin del header, no tiene un pin del PIC asignado // H2.45 VBATT // Este pin del header, no tiene un pin del PIC asignado // H2.46 VBATT // Este pin del header, no tiene un pin del PIC asignado // H2.47 USER6 // Este pin del header, no tiene un pin del PIC asignado // H2.48 USER7 // Este pin del header, no tiene un pin del PIC asignado // H2.49 USER8 // Este pin del header, no tiene un pin del PIC asignado // H2.50 USER9 // Este pin del header, no tiene un pin del PIC asignado // H2.51 USER10 // Este pin del header, no tiene un pin del PIC asignado // H2.52 USER11 // Este pin del header, no tiene un pin del PIC asignado //------------------------------------------------------------------------------ }
/** * Configurar los pines de IO para PPM */ void GPIO_PPM_init(void) { // PINES NO CONECTADOS, NO IMPLEMENTADOS //1 CN82/RG15 => pin es RA5 _TRISG15=0; //pin 0-output 1-input _LATG15=0; // parte en 0 //84 C3INA/CN16/RD7 => pin es RA5 _TRISD7=0; //pin 0-output 1-input _LATD7=0; // parte en 0 //91 CN39/RA6 => pin es RA5 _TRISA6=0; //pin 0-output 1-input _LATA6=0; // parte en 0 //92 CN40/RA7 => pin es RA5 _TRISA7=0; //pin 0-output 1-input _LATA7=0; // parte en 0 //93 CN58/PMD0/RE0 => pin es RE0 _TRISE0=0; //pin 0-output 1-input _LATE0=0; // parte en 0 //94 CN59/PMD1/RE1 => pin es RE1 _TRISE1=0; //pin 0-output 1-input _LATE1=0; // parte en 0 //95 CN81/RG14 => pin es RG14 _TRISG14=0; //pin 0-output 1-input _LATG14=0; // parte en 0 //96 CN79/RG12 => pin es RG12 _TRISG12=0; //pin 0-output 1-input _LATG12=0; // parte en 0 //97 CN80/RG13 => pin es RG13 _TRISG13=0; //pin 0-output 1-input _LATG13=0; // parte en 0 //55 ASCK1/RPI45/INT0/CN72/RF6 => pin es RF6 _TRISF6=0; //pin 0-output 1-input _LATF6=0; // parte en 0 #if SCH_PAY_CAM_nMEMFLASH_ONBOARD == 1 //SPI_1 es configurado para la Camara en los pines (H1.13 al H1.16) #else //Pines para la mem flash de 64 Mbit con SPI-1 (SCK1, SDI1, SDO1 nSS1 y nWP) // pin 71= RP12/CN56/PMCS1/RD11 => pin es RP12 (SCK) //iPPSOutput(OUT_PIN_PPS_RP12,OUT_FN_PPS_SCK1); iPPSOutput(RPOR6bits.RP12R,0x08); // pin 72 RP11/CN49/RD0 => pin es RP11 (SDI) //iPPSOutput(OUT_PIN_PPS_RP11,OUT_FN_PPS_SDO1); iPPSOutput(RPOR5bits.RP11R,OUT_FN_PPS_SDO1); // 70 RP3/CN55/PMCS2/RD10 => pin es RP3 (SDO) iPPSInput(IN_FN_PPS_SDI1,IN_PIN_PPS_RP3); // pin 80 CN19/RD13 => pin es RD13 (nCS) _TRISD13=0; //pin 0-output 1-input _LATD13=0; // parte en 0 // pin 83 C3INB/CN15/RD6 => pin es RD6 (nWP) _TRISD6=0; //pin 0-output 1-input Open_SPI_1_default(); //SPI_SDI_1 //SDO en nomenclatura Pumpkin's //SPI_SCK_1 //SCK en nomenclatura Pumpkin's //SPI_SDO_1 //SDI en nomenclatura Pumpkin's SPI_nSS_1=1; //nCS en nomenclatura Pumpkin's SPI_nWP_1=1; //nWP en nomenclatura Pumpkin's #endif // PPC_DEFAULT_CW1() desactiva JTAG (TMS, TCK, TDI, TDO) //17 TMS/CN33/RA0 => pin es RA0 _TRISA0=0; //pin 0-output 1-input _LATA0=0; // parte en 0 //38 TCK/CN34/RA1 => pin es RA1 _TRISA1=0; //pin 0-output 1-input _LATA1=0; // parte en 0 //60 TDI/CN37/RA4 => pin es RA4 _TRISA4=0; //pin 0-output 1-input _LATA4=0; // parte en 0 //61 TDO/CN38/RA5 => pin es RA5 _TRISA5=0; //pin 0-output 1-input _LATA5=0; // parte en 0 }