Program 22: Stepper Motor – Clockwise
PIC18F4550 · Embedded C

#include <xc.h>

   #define _XTAL_FREQ 20000000UL

   void main(void)
   {
       TRISC = 0x00;                        // PORTC = output (motor driver)
       LATC = 0x00;

        while(1)
        {
            // Clockwise sequence: 03 -> 06 -> 24 -> 21
            LATC = 0x03;            // RC0 + RC1
            __delay_ms(5);

             LATC = 0x06;                   // RC1 + RC2
             __delay_ms(5);

             LATC = 0x24;                   // RC2 + RC5
             __delay_ms(5);

             LATC = 0x21;                   // RC5 + RC0
             __delay_ms(5);
        }
   }
