; ---------------------------------------------------------------------- ; ; PIC frequency divider for PIC16F1823 ; Generates a 50% duty cycle square wave on Port C0 ; running at 1/256 the PIC input clock ; ; by John Beale Feb. 2011 ; ; based on PIC Divider code by tvb (Tom Van Baak) ; http://www.leapsecond.com/tools/PPSDIV.ASM ; see also, version by Richard H McCorkle at TAPR ; http://www.tapr.org/~n8ur/PIC_Code/dfdiv_04-2009.asm ; ---------------------------------------------------------------------- ; Using Microchip assembler. processor 16F1823 include ; INTOSC = internal RC osc at 4 MHz ; ECH = external clock at 4..32 MHz ; __CONFIG _CONFIG1, _FOSC_INTOSC&_PWRTE_ON&_MCLRE_ON&_BOREN_ON&_CLKOUTEN_ON&_WDTE_OFF&_IESO_OFF&_FCMEN_OFF __CONFIG _CONFIG1, _FOSC_ECH&_PWRTE_ON&_MCLRE_ON&_BOREN_ON&_CLKOUTEN_ON&_WDTE_OFF&_IESO_OFF&_FCMEN_OFF __CONFIG _CONFIG2, _PLLEN_OFF&_STVREN_ON&_BORV_19&_LVP_ON ORG 0x00 ;Start vector GOTO main main: BANKSEL PORTC ; configuration setup CLRF PORTC ; Init PORTC BANKSEL LATC ; Data Latch CLRF LATC ; BANKSEL ANSELC CLRF ANSELC ; Make Port C<5:0> digital BANKSEL TRISC ; MOVLW 0x0 ; Set Port C<5:0> as outputs MOVWF TRISC ; banksel PORTC MAIN_LOOP: ; 64 cycles each loop BSF PORTC,0 ; 1 Turn on pin CALL w31 ; 31 Wait BCF PORTC,0 ; 1 Turn off pin CALL w29 ; 29 Wait GOTO MAIN_LOOP ; 2 Repeat ;------Delay Routine------------- w31: nop ; 1 nop ; 1 w29: CALL Delay10 ; 10 CALL Delay10 ; 10 CALL Delay4 ; 4 nop ; 1 RETURN ; 4 call+return Delay10: GOTO $+1 Delay8: GOTO $+1 Delay6: GOTO $+1 Delay4: RETURN ; call+return = 4 cycles END