Automatic Fish Feeder - Part 2

Schematic

Fish Feeder Schematic
My quick, crappy schematic drawing

The schematic is extremely simple. I tried to use parts that I already has on hand. I have a few weak stepper motors that I got from an overstock website (MOTOR1). The protection diodes (D1-4) are there to short the surge currents created by the motor coils. This will prevent the MOSFETs (Q1-4) from being destroyed over time. The gates of the MOSFETs are connected to bits <3-0> of Port C on the PICmicro. To minimize the number of parts, I used the built-in oscillator as the PICmicro's system clock. The power supply is a 5V power cable/battery charger for an old cell phone I had.

Source Code

The source code for this project was much more complicated in the beginning. As debugging became more and more frustrating, I rewrote it in the extremely simple version you see below. It is written for the SourceBoost BoostC compiler.

#include <system.h>

#define DEGREES_PER_PULSE 15

/*
* Timer0 prescaler 1:256
* Feed twice a day
* Timer ticks before-prescaler at 1 MHz (4 MHz oscillator)
* Every second is 3906.25 ticks
* Every 12 hours is 168,750,000
*/
#define TICKS_RESET 168750000

#pragma DATA _CONFIG, _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF

void feed (void)
{

    portc = 0b00000110;    // Turn on stepper motor

    unsigned char j;
    for (j = 0; j < 2; ++j)
    {
        unsigned char i;
        for (i = 0; i < 12; ++i)
        {
            portc = 0b00001010;
            delay_ms(20);
            portc = 0b00000011;
            delay_ms(20);
            portc = 0b00000101;
            delay_ms(20);
            portc = 0b00001100;
            delay_ms(20);
        }
    }
    portc = 0b00000000;    // Turn off stepper motor

}

void main (void)
{
    option_reg = 0b01010111;

    trisa = 0b11111111;
    ansel = 0x00;
    wpua = 0xFF;
    ioca = 0x00;

    trisc = 0xF0;

    while (1)
    {
        feed();
        signed short i = 720;
        for ( ; i >= 0; --i)
        {
            delay_s(60);
        }
    }
}

This code turns the motor one complete revolution every 12 hours. It doesn't minimize power consumption or use interrupts. That would be a lot better, but this started as just a quick project to last for a weekend or two.