Смекни!
smekni.com

Охранная система с дистанционным управлением (стр. 13 из 13)

RETLW 31;'1'

RETLW 32;'2'

RETLW 33;'3'

RETLW 34;'4'

RETLW 35;'5'

RETLW 36;'6'

RETLW 37;'7'

RETLW 38;'8'

RETLW 39;'9'

;-------Interrupt subroutines-------------------------

INTMOVWF W_TEMP

MOVFF STATUS,STATUS_TEMP

MOVFF BSR,BSR_TEMP

MOVFF TMR0L,PERIOD;capture timer value

CLRF TMR0L

;-------

anothBTFSC FLAG,2;If parity bit will be received...

BRA PARITY;

BTFSC FLAG,1;If start bit was received...

BRA BIT_AN;

BTFSC FLAG,0;If "begin bit" set,then

BRA RES_AN;goto to analizing bit.

;

BTFSC INTCON,TMR0IF

LFSR FSR1,IRDA1

MOVLW B'00000001';set "begin receiving",

MOVWF FLAG;Reset flag "timer overflow"

CLRF COM_BUF;clear variables

BCF INTCON,TMR0IF

CLRF BIT;

BRA int_end;

RES_ANBTFSC INTCON,TMR0IF;If TMR0 overflow then error

BRA err

;Verifing...

MOVLW 0x6D;4 ms13 ms

CPFSGT PERIOD;normal 15 ms

BRA err;error if time is short

MOVLW 0xCB;6 ms17 ms

CPFSLT PERIOD;

BRA err;error if time is long

BSF FLAG,1;Set flag "START BIT"

BRA int_end

BIT_ANBTFSC INTCON,TMR0IF

BRA err

MOVLW 0x46;23-2.3 ms

CPFSLT PERIOD;12 ms

BRA err;error if time>H1 (normal 10 ms)

MOVLW 0x1A;old=43

CPFSGT PERIOD;0A-0.7 ms3 ms

BRA err;error if time<L0 (normal 5 ms)

;END of verifing

RLNCF COM_BUF;

MOVLW 0x30;14<X<1A

CPFSLT PERIOD;

BSF COM_BUF,0;if time>H0 then bit is "1"

CPFSGT PERIOD;

BCF COM_BUF,0;if time<H0 then bit is "0"

INCF BIT,F;

MOVLW .8

CPFSLT BIT

BSF FLAG,2;Next bit will be parity

BRA int_end;

PARITYBTFSC INTCON,TMR0IF

BRA err

MOVLW 0x46;23-2.3 ms

CPFSLT PERIOD;12 ms

BRA err;error if time>H1 (normal 10 ms)

MOVLW 0x1A;0A-0.7 msold=43

CPFSGT PERIOD;3 ms

BRA err;error if time<L0 (normal 5 ms)

MOVLW 0x30

CPFSLT PERIOD;

BSF FLAG2,0;if time>H0 then bit is "1"

CPFSGT PERIOD;

BCF FLAG2,0;if time<H0 then bit is "0"

;create received byte

MOVFF IRDA2,COMMAND

MOVFF IRDA3,PASS1

MOVFF IRDA4,PASS2

MOVFF IRDA5,PASS3

MOVFF IRDA6,PASS4

BSF REM_FLAG,3;Set flag "COMMAND" not executed

int_endBCF INTCON,INT0IF

MOVFF BSR_TEMP,BSR

MOVF W_TEMP,W

MOVFF STATUS_TEMP,STATUS

RETFIE

;-------Start of program----------------------------

STARTCLRF PORTA;

CLRF PORTB;Clear

CLRF PORTC;I/O ports

CLRF PORTD;

CLRF PORTE;

MOVLW B'00001111';

MOVWF TRISA;

SETF TRISB;

MOVLW B'11011000';

MOVWF TRISC;

CLRF TRISD;

CLRF TRISE;

MOVLW B'11010101';TMR0 16-bit counter

MOVWF T0CON;subdivider 1:64

;interrupts

MOVLW B'11010000';

MOVWF INTCON;

MOVLW B'10000000';INT1 fall_pulse

MOVWF INTCON2;

MOVLW B'00001000';Enable INT1 interrupt

MOVWF INTCON3;

MOVLW B'00000011';

MOVWF PIE1;interrupt TMR1,TMR2 enable

MOVLW B'00000000';All interrupts low priority

MOVWF IPR1;

MOVLW B'00000000';

MOVWF IPR2;

BSF RCON,7;Приоритетная система прерываний вкл.

;TMR1 setup

MOVLW B'00000001';TMR1 is active

MOVWF T1CON;subdivider 1:1

;TMR2 setup

MOVLW B'00001111';Enable, subdivider 1:16

MOVWF T2CON;

;A/D setup

MOVLW B'00000001';A/D enable

MOVWF ADCON0;CLK is Fosc/4

MOVLW B'01001110';Left justify;0 analog channels

MOVWF ADCON1;VDD and VSS references

;MSSP setup

MOVLW 0x0A;100 kHz

MOVWF SSPADD;Set speed

MOVLW B'00101000';MSSP enabled,

MOVWF SSPCON1;I2C Master mode

;Usart setup

MOVLW B'00100000';Asynchronic,8bit transfer

MOVWF TXSTA;low speed mode

MOVLW B'10010000';UART on

MOVWF RCSTA

MOVLW B'00011001';2400 baud,error +1.67%

MOVWF SPBRG

CLEARLFSR FSR0,00;

clCLRF POSTINC0;

MOVLW .100;

CPFSEQ FSR0L;

BRA cl;

;-------Main program block------------------------------

PROGALFSR FSR1,IRDA1

RCALL I2C_STOP_

MOVLW B'10010000'

MOVWF SLAVE_TRM

MOVFF SLAVE_TRM,I2C_ADDR

MOVLW 0xEE

MOVWF I2C_DATA

RCALL I2C_COM;Command 'start converting'

RCALL LCD_INIT;

CLRF TBLPTRU;Set message adress 7000

MOVLW B'01110000';

MOVWF TBLPTRH;

CLRF TBLPTRL;

RCALL LCD_LD1;

RCALL LCD_LD2;

RCALL LCD_PR1;

RCALL LCD_PR2;Приветствие

RCALL DELL;Pause

RCALL LCD_CLR1

RCALL LCD_CLR2

BSF EVENTS,4

;-------Start program---------------------------------------

CONNECTRCALL M_NO_CONN;Show message "Нет подлючения!"

MOVLW B'00100000';

MOVWF TBLPTRL;Show message "Температура"

RCALL LCD_LD2;

RCALL TERM_DISP;Measure and display temperature

RCALL ADC_CONV

RCALL LCD_PR2

begBTFSC EVENTS,4

RCALL UART_ST

RCALL TERM_DISP;Measure and display temperature

RCALL ADC_CONV

;1-----Start receiving!-----------------

LFSR FSR0,PACK1

PACK_RXRCALL UART_RD

BTFSC EVENTS,4;If CONNECT ERROR then restart

BRA CONNECT

MOVFF UART_DATA,POSTINC0

MOVLW 0x4B

CPFSEQ FSR0L

BRA PACK_RX

MOVFF PACK2,HL_STAT

MOVFF PACK3,TERMAL_L

MOVFF PACK4,TERMAL_H

MOVFF PACK5,AD_VREF

MOVFF PACK6,SENSOR_MODE

;-Transmite-----------------------------------------

PACK_TXMOVLW .16;Set address of device

MOVWF PACK_OUT1;

MOVFF SENS1_STAT,PACK_OUT2;

MOVFF SENS2_STAT,PACK_OUT3;

MOVFF AD,PACK_OUT4;

MOVFF TERMAL,PACK_OUT5;

MOVFF ADD_BYTE,PACK_OUT6

LFSR FSR0,PACK_OUT1;Write data to terminal

txMOVF POSTINC0,W;

RCALL UART_WRT;

RCALL M_DEL;6 bytes...

MOVLW 0x55;

CPFSEQ FSR0L;

BRA tx;

asddRCALL LCD_PR1

RCALL LCD_PR2

;+++++++++++Place for main subroutine+++++++++++++++

BTFSS HL_STAT,7

BRA m_block

BCF SENS1_STAT,5;Reset flag "Change status HL1"

BCF SENS1_STAT,6;Reset flag "Change status HL2"

BCF SENS1_STAT,7;Reset flag "Change status "HL3"

BCF SENS2_STAT,6;Reset flag "Was command from IRDA"

BCF SENS2_STAT,7;Reset flag "Change security mode"

sens_vrCLRF PASS1

CLRF PASS2

CLRF PASS3

CLRF PASS4

BTFSC SENS1_STAT,0;Set flag "perimetr error"

BSF EVENTS,1;if sensors unlock

BTFSC SENS1_STAT,1;

BSF EVENTS,1;

BTFSC SENS1_STAT,2;

BSF EVENTS,1

re2MOVF AD_VREF,W

CPFSLT AD

BSF EVENTS,1

re3MOVF TERMAL_H,W

CPFSLT TERMAL

BSF EVENTS,2;if TERMAL>TERMAL_H

MOVF TERMAL_L,W;

CPFSGT TERMAL;if TERMAL<TERMAL_L

BSF EVENTS,3;

BTFSS EVENTS,2;

BRA re4

RCALL M_FIRE;FIRE CONTROL

BSF REM_FLAG,5

BRA gym2

re4BTFSS HL_STAT,3;if mode=off then ok

BRA gym

RCALL M_ACES_NO;

BTFSC EVENTS,1;If sensors unlock,

RCALL M_PERIM;Show message "Периметр нарушен"

BTFSC EVENTS,1

BSF REM_FLAG,5

BTFSC EVENTS,3

BSF REM_FLAG,5

BTFSC EVENTS,3

RCALL M_COLD;Show message "Переохлаждение!"

BRA gym2

;+++++++++++End of place for main subroutine+++++++++++++++++++

gymRCALL M_ACES_OK

gym2BTFSS HL_STAT,4;Verifying reset command from PC

BRA main_end

BCF EVENTS,1;Reset perimetr

BCF EVENTS,2;Reset fire

BCF EVENTS,3;Reset cold

BCF EVENTS,4;Reset connect error

BCF PORTC,5;Reset ALARM_LIGHT

BCF PORTA,5;Reset flag for external system

BCF ADD_BYTE,0

BCF REM_FLAG,5;Reset flag ALARM_LIGHT

CLRF PASS_ERR

main_endBRA beg

;++++++++++++++++++++++++++++++++++++++++++++++++++++++

GOTO FINAL

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

;Different subroutines

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

M_DELMOVLW .49

MOVWF CYC2

mdl1DECF CYC2,F

MOVLW .255

MOVWF CYC

mdlDECF CYC,F

TSTFSZ CYC

BRA mdl

TSTFSZ CYC2

BRA mdl1

RETURN

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

UART_WRTMOVWF TXREG

BTFSS PIR1,4

BRA $-2

BCF PIR1,4

RETURN

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

UART_STBCF EVENTS,0

BCF EVENTS,1

BCF EVENTS,2

BCF EVENTS,3

BCF EVENTS,5

BCF PIR1,5

BCF EVENTS,4

BCF RCSTA,4

BSF RCSTA,4

ur_stBTFSS PIR1,5

BRA $-2

BCF PIR1,5

MOVFF RCREG,UART_DATA

MOVLW .238

CPFSEQ UART_DATA

BRA ur_st

RETURN

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

UART_RDRCALL UART_WAIT

MOVFF RCREG,UART_DATA

RETURN

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

DELLMOVLW .8;8-Time delay.

MOVWF TIME_DEL;Variable LSD is

tmdTSTFSZ TIME_DEL

BRA tmd

RETURN

;--------Sub-zero termo-correction-------------------------

TERM_CORRMOVLW 2D;"-"

MOVWF MSD;MSD used temporary

BCF SENS1_STAT,3

MOVF I2C_BYTE1,W

SETF I2C_BYTE1

SUBWF BYTE1

RETURN

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

TERMOSCANMOVFF SLAVE_TRM,I2C_ADDR;Slave-address DS1621

MOVLW 0xAA;Command "Read temperature"

MOVWF I2C_DATA

RCALL I2C_2RD

RETURN

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

M_NO_CONNMOVLW B'1110000';

MOVWF TBLPTRL;Show message "Нет подключения!"

RCALL LCD_LD1;

RCALL LCD_PR1

RETURN

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

M_ACES_OKMOVLW B'00110000';

MOVWF TBLPTRL;Show message "Доступ разрешен"

RCALL LCD_LD1;

RCALL LCD_PR1

RETURN

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

M_FIREMOVLW B'01000000';

MOVWF TBLPTRL;Show message "Пожарная тревога!"

RCALL LCD_LD1;

RCALL LCD_PR1

BSF PORTA,5;Set flag for external system

RETURN

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

M_PERIMMOVLW B'01010000';

MOVWF TBLPTRL;Show message "Периметр нарушен!"

RCALL LCD_LD1;

RCALL LCD_PR1

BSF PORTA,5;Set flag for external system

RETURN

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

M_COLDMOVLW B'10000000';

MOVWF TBLPTRL;Show message "Переохлаждение!"

RCALL LCD_LD1;

RCALL LCD_PR1;

BSF PORTA,5;

RETURN

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

M_ACES_NOMOVLW B'01100000';

MOVWF TBLPTRL;Show message "Доступ запрещен!"

RCALL LCD_LD1;

RCALL LCD_PR1

RETURN

;-----------A/D Converting----------------------------------

ADC_CONVMOVLW D'20'

MOVWF DEL_ADC

DECFSZ DEL_ADC,F

BRA $-2

BSF ADCON0,GO;Start A/D conversion

WaitBTFSS PIR1,ADIF;Wait for conversion to complete

BRA $-2

BCF PIR1,ADIF

MOVFF ADRESH,AD

RETURN

;-------Looped end of program----------------------------

FINALNOP

BRA FINAL

END