; ------------------------------------------------------------------------
;
; Title:
;
;   PD32 -- PIC "4-pin" simplest frequency divider (divide by 32)
;
; Function:
;
;   This PIC program implements a digital frequency divider: the external
;   input clock is divided by a factor of 32. For example, if the input
;   clock is 16 MHz, the output is 500 kHz. Similarly 10 MHz -> 312.5 kHz,
;   4 MHz -> 125 kHz, 32 Hz -> 1 Hz, etc.
;
; Diagram:
;                                ---__---
;                5V (Vdd)  +++++|1      8|=====  Ground (Vss)
;             input clock  ---->|2  pD  7|---->  output clock
;                              -|3  32  6|-
;                              o|4      5|-
;                                --------
; Notes:
;
;   Only 4 pins are required: power (2.0-5.5V), ground, input and output.
;   - For convenience: pin3/GP4, pin5/GP2, pin6/GP1 are also outputs.
;   o Suggestion: tie floating input pin4/GP3 to Vdd or Vss.
;   Input clock can be any frequency from 0 to 20 MHz.
;   Output frequency accuracy is perfectly as accurate as input clock.
;   Output drive current is 25 mA maximum per pin, 90 mA per package.
;   Coded for Microchip 12F675 but any '609 '615 '629 '635 '675 '683 works.
;
; Version:
;
;   13-Dec-2004  Tom Van Baak (tvb)  www.LeapSecond.com/pic
;
; ------------------------------------------------------------------------

; Microchip MPLAB IDE assembler code (mpasm).

        list        p=pic12f675
        include     p12f675.inc
        __config    _EC_OSC & _MCLRE_OFF & _WDT_OFF

; One-time PIC 12F675 initialization.

        movlw   0x07            ; turn comparator off
        movwf   CMCON           ;
        clrf    GPIO            ; set output latches low
        bsf     STATUS,RP0      ; bank 1
        clrf    ANSEL-0x80      ; all digital (no analog) pins
        clrf    TRISIO-0x80     ; set all possible pins output
        bcf     STATUS,RP0      ; bank 0

; A 4 instruction cycle toggle loop divides the external clock by 32.

loop:   movlw   0xFF            ;
        xorwf   GPIO,F          ; toggle bits
        goto    loop            ;
        end
