;************************************************************************
;   Filename:       pic12f509_rtty_01.asm                              *
;   Date:           2022-01-05                                          *
;   File Version:   1.0                                                 *
;                                                                       *
;   Author:     Harry Lythall, SM0VPO,      http://www.sm0vpo.com       *
;                                                                       *
;               harry.lythall@sm0vpo.com    +46736295002                *
;               All rights reserved                                     *
;************************************************************************
;   Architecture:   Baseline PIC                                        *
;   Processor:      12C508 / 12F509                                     *
;                                                                       *
;************************************************************************
;   Description: 1275Hz/1445Hz RTTY AFSK genererator                    *
;                                                                       *
;   Pinout:     Pin 1   Vdd +5 V DC                                     *
;               Pin 4   GP3 (tone select) High (N/C) = Del6             *
;               Pin 7   GP0 (tone out)                                  *
;               Pin 8   Vss  Ground -ve                                 *
;                                                                       *
;   Vcc +5V to Pin 2 and program Del6 (1445Hz) for the required tone    *
;   Ground Pin 2 to select Del5 as secondary tone (1275Hz)              *
;                                                                       *
;   Output requires LP filter and high resistor to rig microphone       *
;                                                                       *
;************************************************************************
;  Timing values for tones:                                             *
;     Count = 161925 / freq                                             *
;                                                                       *
;************************************************************************

    list        p=12F509      
    #include    <p12F509.inc>

                ; ext reset, no code protect, no watchdog, 4Mhz int clock
    __CONFIG    _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC


;***** VARIABLE DEFINITIONS
        UDATA
dc1     res 1               ; Count loop counter value

;***** OSCCAL AND PORT CONFIGURATION
RESET   CODE    0x000       ; effective reset vector
        movwf   OSCCAL      ; update OSCCAL with factory cal value 

start   movlw   b'111110'   ; configure GP0 as output
        tris    GPIO

;***** MAIN PROGRAM ****************************

;**************************** Switch GP0=ON
Main    movlw	b'000001'   ; set w to 1 in bit0
        movwf	GPIO        ; set GP0 high

;**************************** Test 77/123 select and wait
        btfsc   GPIO,3      ; Test GP3 - skip if 0
        call    Del5        ; GOSUB for 123Hz
        btfss   GPIO,3      ; Test GP3 - skip if 1
        call    Del6        ; GOSUB for 77Hz

;**************************** Switch GP0=OFF
        movlw   b'000000'   ; set w to 0 in bit0
        movwf   GPIO        ; set GP0 low

;**************************** Test 77/123 select and wait
        btfsc   GPIO,3      ; Test GP3 - skip if 0
        call    Del5        ; GOSUB for 1275Hz
        btfss   GPIO,3      ; Test GP3 - skip if 1
        call    Del6        ; GOSUB for 1445Hz

;**************************** Start again
        goto    Main


;***** SUBROUTINES ****************************

;***** Delay loop for 1275Hz
Del5    movlw   .127        ; Seed Count Lo (Count value)
        movwf   dc1         ; Store it

Del5a   decfsz  dc1         ; Decrement Lo
        goto    Del5a       ; Repeat if not zero
        retlw   0           ; Done

;***** Delay loop for 1445Hz
Del6    movlw   .111        ; Seed Count Lo (Count value)
        movwf   dc1         ; Store it

Del6a   decfsz  dc1         ; Decrement Lo
        goto    Del6a       ; Repeat if not zero
        retlw   0           ; Done

        END
