Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; …ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ—ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ; ∫ ≥Author: ∫
- ; ∫ ⁄ƒø⁄ƒƒ ⁄ ø ≥ Daniel Henzulea ∫
- ; ∫ _\\|//_ (C) 1996 by √ƒ¥¿ƒø ≥ ≥ ≥ zulea@utcluj.ro ∫
- ; ∫ (` o-o ') ¿ ŸƒƒŸ ¿ƒŸ √ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ∂
- ; «ƒƒƒƒƒƒooO-(_)-Oooƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ¥Automatic Soft - ASU ∫
- ; ∫ …ÕÕª …ÕÕª … ª ª …ÕÕª ≥Republicii 5/5 ∫
- ; ∫ ∫ ∫ ∫ ∫ ê ∫ ∫ ∫ ∫ ≥Cluj-Napoca 3400-RO ∫
- ; ∫ .oooO Oooo. ÃÕÕº ÃÕÕπ ∫»Õπ …ÕÕπ ÃÕÕπ ≥Phone *40-64-197427 ∫
- ; ∫ ( ) ( ) » » º » º »ÕÕº » º ≥Fax *40-64-199794 ∫
- ; «ƒƒƒƒ-\ (ƒƒƒƒƒƒƒ) /ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ¡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ∂
- ; ∫ \_) (_/ RADIO SECURITY SYSTEMS ∫
- ; »ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- ; …ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ; ∫ Program : SonaPIC ∫
- ; ∫ Vresion : 1.2 ∫
- ; ∫ Comment : Clock: 4 Mhz ∫
- ; ∫ Oscilator Type: HS ∫
- ; ∫ WatchDog: ON ∫
- ; »ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- Processor 16C84
- Radix DEC
- LIST F=INHX16
- EXPAND
- include "16cxx.h"
- include "sonapic.h"
- ORG _ResetVector
- goto Start
- ORG _IntVector
- goto Interrupt
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Main Program ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- Start:
- btfsc _to
- Loop: goto Loop
- clrwdt
- call Init
- call ProgIdleTimer
- call StartInt
- call GetChar
- MainLoop:
- call TaskRecByte
- call TaskSendByte
- goto MainLoop
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Interrupt service routines ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- Interrupt:
- movwf SaveWReg
- swapf _status,w ; affects no STATUS bits
- movwf SaveStatus ; Only way OUT to save STATUS Reg !!
- btfsc _rtif
- goto TimerInt
- btfsc _intf
- goto Int
- RestoreIntStatus:
- swapf SaveStatus,w
- movwf _status ; restore STATUS Reg
- swapf SaveWReg, F ; save WREG
- swapf SaveWReg,w ; restore WREG
- retfie
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- TimerInt:
- bcf _rtif
- clrwdt
- movf Counter2mS, f
- btfss _z
- bsf GainControl ; Set A max if past 2 ms from first
- incf Counter2mS, f ; pulse transmited.
- movfw Counter2mS
- sublw InternDelayTime ; Check if past the time between
- btfsc _z ; two pulses packets.
- call SendPulse ; Yes: Send pulses.
- goto RestoreIntStatus
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- Int:
- bcf _intf
- bcf _inte
- movlw BufferAdress ; Store 8 LSBytes in buffer
- addwf IndexLowByte, w ; The MSB is Counter2mS and the LSB is _rtcc
- movwf _fsr ; This two bytes count the time between
- movfw _rtcc ; the first transmited pulse and the first
- movwf _indf ; received pulse (echo).
- incf IndexLowByte, w
- andlw 0x07 ; Check if was made 8 measurements.
- movwf IndexLowByte
- btfsc _z ; Yes: Make the medium value for the LSB
- call LoadLowByte
- movfw Counter2mS
- movwf HighByteDelay ; Store MSB.
- goto RestoreIntStatus
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Task receive byte on serial asinchronous input ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- TaskRecByte
- btfss RecByte ; If the task isn't in working
- return ; return.
- btfss WaitStartBit ; Wait for start bit ?
- goto ReadNextBit ; No: Read the next bit.
- WaitForStartBit:
- btfsc RxIN ; Yes: Wait RxIN low.
- return
- movfw _rtcc ; Store real time (detected start bit).
- movwf SerialRTCC
- movlw 9 ; The number of bits (8N1).
- movwf BitIndex
- bcf WaitStartBit ; Reset flag for wait the start bit.
- bsf ReadStartBit ; Set flag for read the start bit.
- return
- ReadNextBit:
- btfsc ReadStartBit
- goto StartBit
- movfw SerialRTCC ; Is time to read next bit ?
- subwf _rtcc, w ;
- sublw BitTimeSerial
- btfsc _carry
- return ; No: Return.
- decfsz BitIndex, f ; Yes: Dec the bit counter and check
- goto NotStopBit ; if was the stop bit.
- StopBit: ; Was the stop bit:
- bcf RecByte ; Reset flag RecByte
- goto ByteReceived ; Check the byte received
- NotStopBit:
- bcf _carry
- btfsc RxIN ; Read the bit.
- bsf _carry ;
- rrf SerialRegister, f ; Make the byte.
- movlw BitTimeSerial
- addwf SerialRTCC, f
- return
- StartBit:
- movfw SerialRTCC ;
- subwf _rtcc, w ; Is time to read start bit?
- sublw FirstBitTimeSerial
- btfsc _carry
- return ; No: Return.
- btfsc RxIN ; Yes: Was a glitch ?
- goto GetChar ; Yes: Wait another byte (GOTO, no CALL!!!)
- bcf ReadStartBit ; No: Reset flag read start bit.
- movlw FirstBitTimeSerial
- addwf SerialRTCC, f
- return
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Check the byte received ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- ByteReceived:
- movfw SerialRegister ; Was the command for send the last
- sublw PleaseSendData ; measurement ?
- bz SendData ; Yes: Send data.
- call GetChar ; No: Wait to receive another byte.
- return
- SendData:
- bcf SendedSecondByte ; Rest flag sended second byte.
- movfw HighByteDelay ; Load first byte (MSB).
- call PutChar ; Send the byte.
- return
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Task send byte on serial asinchronous output ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- TaskSendByte
- btfss SendByte ; If the task isn't in working
- return ; return.
- movfw SerialRTCC
- subwf _rtcc, w
- sublw BitTimeSerial ; Is time to send next bit ?
- btfsc _carry
- return ; No: Return.
- btfsc SendedStopBit ; Yes: Was sended the stop bit ?
- goto SendNextByte ; Yes: Send next byte.
- decfsz BitIndex, f ; No: Is the stop bit ?
- goto SendNextBit ; No: Send next bit.
- bsf SendedStopBit ; Yes: Set flag sended stop bit.
- goto SendStopBit
- SendNextBit:
- rrf SerialRegister, f ; Send the next bit.
- bcf TxOUT
- btfsc _carry
- SendStopBit: ; Send stop bit ( always '1' ;-)
- bsf TxOUT
- movlw BitTimeSerial
- addwf SerialRTCC, f ; Store value for real time to read
- return ; next bit.
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Check if send more bytes ( only one... ) ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- SendNextByte:
- btfsc SendedSecondByte ; Sended second byte ?
- goto Sended ; Yes: Stop task send.
- movfw LowByteDelay ; No: Load second byte and send it.
- call PutChar
- bsf SendedSecondByte ; Set flag sended second byte.
- return
- Sended:
- bcf SendedSecondByte
- bcf SendByte ; Stop task send bytes.
- call GetChar ; Wait to receive a command.
- return
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Serial asinchronous procedures ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- PutChar
- movwf SerialRegister ; Store value for real time to send
- movfw _rtcc ; next bit.
- movwf SerialRTCC
- movlw 9 ; The number of bits (8N1).
- movwf BitIndex
- clrf SerialStatus ; Reset all serial flags.
- bsf SendByte ; Start task send.
- bcf TxOUT ; Send start bit.
- return
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- GetChar
- clrf SerialStatus
- bsf WaitStartBit ; Set flag wait start bit.
- bsf RecByte ; Start task receive byte.
- return ;
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Init PIC procedures (interrupts, hardware, regs ...) ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- Init
- movlw 0x0C
- movwf _fsr
- ClearRegs: ; Clear all data RAM.
- clrf _indf
- incf _fsr, f
- movlw 0x2F
- subwf _fsr, w
- bnz ClearRegs
- bsf _rp0 ; pag. 1
- movlw 0xFF
- movwf _trisa
- movwf _trisb
- bcf GainControl ; Make this pins outputs.
- bcf Out1
- bcf Out2
- bcf TxOUT
- bcf _rp0 ; pag. 0
- bcf GainControl ; Set initial values on outputs.
- bsf Out1
- bcf Out2
- bsf TxOUT
- return
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ProgIdleTimer ; Program the TMR0
- bsf _rp0 ; pag. 1
- bcf _rts ; TMR0 increments on internal clock
- bcf _psa ; at 8 uS ( prescaler 1:8 ).
- bcf _ps2 ;
- bsf _ps1
- bcf _ps0
- bsf _intedg
- bcf _rp0 ; pag. 0
- return
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- StartInt:
- clrf _intcon
- bsf _rtie ; Start real time interrupt.
- retfie ; Return with interrupts enabled.
- ;…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕª
- ;∫ Other procedures ∫
- ;»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
- LoadLowByte ; If was made 8 measurements make the
- ; medium value for LSB.
- movlw BufferAdress
- movwf _fsr
- clrf TempLowByte
- clrf TempHighByte
- movlw 8
- movwf IndexLowByte
- LoopAdd: ; Add the 8 values.
- movfw _indf
- addwf TempLowByte, f
- btfsc _carry
- incf TempHighByte, f
- incf _fsr, f
- decfsz IndexLowByte, f
- goto LoopAdd
- movlw 3
- movwf IndexLowByte
- LoopShift:
- bcf _carry
- rrf TempHighByte, f
- rrf TempLowByte, f
- decfsz IndexLowByte, f
- goto LoopShift
- movfw TempLowByte
- movwf LowByteDelay
- return
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- SendPulse ; Send 3 pulses at 40 kHz ( Yes, only 3 ).
- clrf Counter2mS
- movlw 3
- movwf PulseCounter
- PulseLoop:
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- bcf Out1
- bsf Out2
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- bsf Out1
- bcf Out2
- decfsz PulseCounter, f
- goto PulseLoop
- bcf GainControl ; Set A min.
- bcf _intf
- bsf _inte ; Start INT interrupt.
- return ; ( wait echo on INT pin ).
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- END
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement