3.5 Shift Register Operation
Several applications require shift register operations such as CRC calculation, serial communication, pseudo-random number generation, and KeeLoq® sequencers. One of the input selections for a signal routing port pin is the shifted input from the next immediate signal routing port pin. When combined with synchronous operation, the shifted input allows the Signal Routing Port to operate as a shift register. Shift Register Operation with Signal Routing Ports shows a Signal Routing Port operating in shift register mode to receive serial data on pin RC7 (serial clock is routed through a Universal Timer module to count clock pulses).
Shift Register Operation with Signal Routing Ports
// Input to SRPORT: Shifted Input // Output from SRPORT: PORTW // Note: Initialization routines are not shown void ShiftRegister_SRPORT() { // Set RWn inputs as shifted inputs PORTWIN0 = 0x01; // 0x01 = RW[n+1] shifted input on PIC18F46Q71 PORTWIN1 = 0x01; PORTWIN2 = 0x01; PORTWIN3 = 0x01; PORTWIN4 = 0x01; PORTWIN5 = 0x01; PORTWIN6 = 0x01; // Set RW7 as external input to receive serial data PORTWIN7 = 0x02; // 0x02 = RC7 on PIC18F46Q71 // Enable flip-flop on all signal routing port pins in PORTW PORTWDF = 0xFF; // Select clock (external clock routed through TU16A timer for counting) PORTWCLK = 0x1B; // 0x1B = TU16A_OUT on PIC18F46Q71 // Initialize shift register PORTW = 0x00; // Enable clock to activate shift register PORTWCONbits.CLKEN = 1; // Wait for 8 clocks (use TU16A interrupt as necessary) Wait(); // Disable clock to deactivate shift register and enable reading PORTWCONbits.CLKEN = 1; // Read received data from PORTW uint8_t rxSerialData = PORTW; }
