κώδικας της εφαρμογής "τηλεφωνητής συναγερμού με επεξεργαστή"


;********************* AutoCall.asm 12/25/07 **********************

;********************************************************************

 LIST P=16F628 ; Device number (PIC16F628)

 ERRORLEVEL -224 ; suppress annoying message because of tris

 ERRORLEVEL -302 ; suppress message because of page change

;--------------------- Configuration ---------------------------------

_BODEN_OFF equ H'3FBF' ; Brown out detection off

_CP_OFF equ H'3FFF' ; Code protection off

_PWRTE_ON equ H'3FF7' ; Power-on reset enabled

_WDT_OFF equ H'3FFB' ; Watch dog timer off

_LVP_OFF equ H'3F7F' ; Low Voltage programming off

_INTRC_OSC_NOCLKOUT equ H'3FFC' ; Use Internal RC Oscillator

_MCLRE_OFF equ H'3FDF' ; Use RA5 as functional input

 __CONFIG _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _LVP_OFF & _BODEN_OFF & _MCLRE_OFF

   ;--------------------- Define Variables -----------------------------

INDF equ 00h ; Indirect file

FSR equ 04h ; File select register

CMCON equ 1Fh ; Comparator Control Address

INTCON equ 0Bh ; Interrupt control register

OPTION_REG equ 81h ; Option register

STATUS equ 03h ; Status register

TRISA equ 85h ; I/O control for port A

TRISB equ 86h ; I/O control for port B

PORTB equ 06h ; Address of port B

PORTA equ 05h ; Address of port A

PC equ 02h ; Program counter

COUNTER equ 20h ; General purpose Counters

COUNTER1 equ 21h

COUNTER2 equ 22h

COUNTER3 equ 23h

COUNTER4 equ 24h

TEMP equ 25h ; Temporary register

 bsf STATUS,5 ; Select memory bank 1 (01)

 bcf STATUS,6 ; Select memory bank 1 (01)

 movlw b'00000010'

 movwf TRISB ; Set port B as output, RB1 = Input

 movlw b'00100000' ;

 movwf TRISA ; Set port A as output, RA5 = Input

 bcf STATUS,5 ; Reset to bank 0

 bcf STATUS,0 ; Clear carry bit

 bcf STATUS,2 ; Clear zero flag

 bcf STATUS,1 ;

 movlw 07h

 movwf CMCON ; Comparators off

 clrf PORTB

 goto Loop ; Main loop

Phone ; Phone Number Table, in reverse order (0000000000)

 addwf PC,1

 nop ; No operation

                                        retlw  d'0'                       ; Last digit

 retlw d'0'

 retlw d'0'

 retlw d'0'

 retlw d'0'

 retlw d'0'

 retlw d'0'

 retlw d'0'

 retlw d'0'

                                        retlw d'0'                       ; First digit

Loop ;------------------- Main Loop -----------------

 movfw PORTB

 btfsc PORTB,1 ; Read pin 7, skip if clear

 goto Loop

 bsf PORTB,2 ; Close relay

 movlw d'3' ; 3 sec Delay

 movwf COUNTER4

Off_Hook_Delay ; 3 sec delay

 call Digit_Delay

 decfsz COUNTER4,f

 goto Off_Hook_Delay

Dial ;------- Change this value to indicate total digits -----

                                                                     movlw d'10'              ; Use 10 digit phone number in  Greece

 movwf COUNTER

Next

 movfw COUNTER

 call Phone ; Get Digit from table

 call Output ; Dial the digit

 call Digit_Delay ; Wait 1 second

 decfsz COUNTER,f

 goto Next ; Do next (1 of 7 digits)

 call Digit_Delay ; Wait 1 second

 movlw d'100' ; 30 second tone timer

 movwf COUNTER

 movwf COUNTER1

 movwf COUNTER2

Timeout ; Generate tone for 30 seconds

 movfw COUNTER

 movwf COUNTER1

Tone

 bsf PORTB,3 ; Set pin 9 high

 call Tone_Delay ; Wait 1.5mS

 bcf PORTB,3 ; Set pin 9 low

 call Tone_Delay ; Wait 1.5mS

 decfsz COUNTER1,f

 goto Tone

 decfsz COUNTER2,f

 goto Timeout ; Repeat until COUNTER2=0

 bcf PORTB,2 ; End call, On Hook, Done

Switch_Open ;------------------ Wait for switch open

 movfw PORTB

 btfss PORTB,1 ; Look at pin 7

 goto Switch_Open ; Loop until pin 7 is high

 call Digit_Delay ; Wait 1 second

 goto Loop ; Restart

;------------------ End sequence, restart from top ------

Tone_Delay ; 300 Hz Tone

 movlw d'255'

 movwf TEMP

Loop_4

 nop

 nop

 nop

 decfsz TEMP,f

 goto Loop_4

 return

;-------------------------------------------------------------

Output ; Open relay for each pulse

 movwf COUNTER1 ; Number of pulses

Next_Pulse

 bcf PORTB,2 ; Set Pin 8 low

 call Pulse_Delay

 bsf PORTB,2 ; Set pin 8 high

 call Pulse_Delay

 decfsz COUNTER1,f

 goto Next_Pulse ; Repeat until COUNTER1=0

 return

Pulse_Delay

 movlw d'150' ; 60 mS Delay

 movwf TEMP

Loop_1

 movwf COUNTER2

Loop_2

 decfsz COUNTER2,f

 goto Loop_2

 decfsz TEMP,f

 goto Loop_1

 return

Digit_Delay

 movlw d'16' ; 1 sec Delay

 movwf COUNTER3

Loop_3

 call Pulse_Delay

 decfsz COUNTER3,f

 goto Loop_3

 return

 end