3.2 Firmware-Driven Peripheral Operation
In many applications, the user firmware must control the operation of a hardware peripheral. As explained in section Software Input to the Signal Routing Port Pin, LATW register can act as a software input to the Signal Routing Port. When the user firmware writes to LATW register while the PORTWINx register has been configured to select LATW as the input source for the corresponding signal routing port pin, the Signal Routing Port can act as a bridge between the firmware code and the hardware peripheral. This becomes particularly useful in debug applications where software intervention is frequently required. Firmware-Driven Peripheral Operation with Signal Routing Port shows how a software-generated ERS signal controls the PWM1 peripheral.
Firmware-Driven Peripheral Operation with Signal Routing Port
// Input to SRPORT: LATW Register (software-driven) // Output from SRPORT: PWM1 ERS PPS input // Note: Initialization routines are not shown void FirmwareDriverSetup_SRPORT() { // Set RW0 input as LATW0 PORTWIN0 = 0x00; // 0x00 = LATW0 on PIC18F46Q71 // Set RW0 as PWM1 ERS PPS input PWM1ERSPPS = 0x38; // 0x38 = RW0 on PIC18F46Q71 } void GenerateERS_SRPORT() { // Assert LATW0 to generate PWM1 ERS signal LATWbits.LATW0 = 1; // Wait for appropriate duration Delay(); // De-assert LATW0 to clear PWM1 ERS signal LATWbits.LATW0 = 0; }