; This file is a basic code template for assembly code generation * ; on the PIC16F628A. This file contains the basic code * ; building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: Xtal_box.asm * ; Date: 04.08.2012 * ; File Version: 002 * ; * ; Author: s53ww * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=16f628A ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS cblock 0x20 PTTstatus ; trenutno stanje PTT (b0 = main; b1 = sub) in Obeh tipk (b2) Stejem ; stevec v filtru pri branju tipk Xflt ; trenutno izbrani filter Xflt_1 ; zadnji izbrani filter (pri skakanju na NoXFLT) Ttmp ; shranitev stanja tipk/PTT Ttmp_1 ; pomozna spremenjlivka pri filtriranju vhodov Ttpk ; zadnje stanje tipk Delay1 Delay2 Delay3 endc ;********************************************************************** ORG 0x000 ; processor reset vector ; nastavitve clrf PORTA movlw 0x07 movwf CMCON ; ugasnemo komparatorje bsf STATUS,RP0 ; BANK 1 bcf STATUS,RP1 ; BANK 1 movlw B'00000000' ; 00100000 movwf TRISA ; PORTA - vsi output (0) razen RA5 movlw B'10110000' ; 10110000 movwf TRISB ; PORTB - vsi output (0) razen RB4, RB5 in RB7 bcf OPTION_REG,7 ; PORTB pull-up enable bsf PCON,3 ; 4MHz INT OSC bcf STATUS,RP0 ; BANK 0 ; konec nastavitev ; inicializacija clrf PTTstatus clrf Ttpk movlw 0x00 movwf Xflt ; zacetno stanje izbranega filtra =NoXFLT (Y0) movlw B'01001000' ; RELE: vkljucimo No_XFLT (RB1=0) in RX (RB3=1) movwf PORTB movlw B'00000000' ; LED: vkljucimo No_XFLT (RA0,1,6,7=0) in RX (RB6=1; RA2=0) movwf PORTA ;---------------------------------------------------------------------------------- ;---------------------------- GLAVNA ZANKA ---------------------------------------- ;---------------------------------------------------------------------------------- loop: call ali_je_tipka ; beremo stanje tipk s filtriranjem movf Ttmp,0 ; stanje vhodov je v Ttmp movwf Ttpk ; shranimo stanje vhodov ; call delay aliPTTmainON: btfss Ttmp,4 ; ali je PTT main ON? goto aliPTTmainOFF btfsc PTTstatus,1 ; ce je PTTsub ON ignoriramo PTTmain goto aliPTTsubOFF ; movlw B'00000000' ; TX RELE RB3=0; RX LED RB6=0 ; movwf PORTB movf PORTB,0 andlw B'10110111' movwf PORTB bsf PORTA,2 ; TX LED ON bsf PTTstatus,0 ; oznacimo, da je PTT main ON (b0 = 1) ; goto loop ; ko je PTT main ON ignoriramo vnose in PTT sub aliPTTmainOFF: btfsc Ttmp,4 ; ali je PTT main OFF? goto aliPTTsubON btfss PTTstatus,0 ; ali je bil PTT main ON? goto aliPTTsubON ; movlw B'01001000' ; TX RELE RB3=1; RX LED RB6=1 ; movwf PORTB movf PORTB,0 addlw B'01001000' movwf PORTB bcf PORTA,2 ; TX LED OFF bcf PTTstatus,0 ; oznacimo, da je PTT main OFF (b0 = 0) ; goto loop aliPTTsubON: btfss Ttmp,5 ; ali je PTT sub ON? goto aliPTTsubOFF btfsc PTTstatus,0 ; ce je PTTmain ON ignoriramo PTTsub in tipke goto loop btfsc PTTstatus,1 ; ce je PTTsub ON ignoriramo tipke goto loop movf Xflt,0 movwf Xflt_1 ; shranimo zadnje stanje Xflt movlw 0x00 movwf Xflt ; call preklop ; movlw B'00000000' ; TX RELE RB3=0; NoXFLT RELE RB1=0; RX LED RB6=0 ; movwf PORTB movf PORTB,0 andlw B'10110101' movwf PORTB movf PORTA,0 andlw B'00111100' addlw B'00000100' movwf PORTA ; bsf PORTA,2 ; TX LED ON bsf PTTstatus,1 ; oznacimo, da je PTT sub ON (b1 = 1) ; goto loop ; ko je PTT sub ON ignoriramo vnose in PTT main aliPTTsubOFF: btfsc Ttmp,5 ; ali je PTT sub OFF? goto seTipke btfss PTTstatus,1 ; ali je PTT sub ON? goto seTipke movf Xflt_1,0 movwf Xflt ; restavriramo stanje Xflt ; call preklop ; movlw B'01001010' ; TX RELE RB3=1; NoXFLT RELE RB1=1; RX LED RB6=1 ; movwf PORTB movf PORTB,0 addlw B'01001010' ; andlw B'01000000' movwf PORTB call preklop movf PORTA,0 andlw B'11111011' movwf PORTA ; bcf PORTA,2 ; TX LED OFF bcf PTTstatus,1 ; oznacimo, da je PTT sub OFF (b1 = 0) ; goto loop seTipke: btfsc PTTstatus,0 ; ce je PTT ON ignoriramo tipke goto loop btfsc PTTstatus,1 goto loop aliObeON: btfss Ttmp,7 ; ali je Up? goto aliUp btfss Ttmp,6 ; in Down? goto aliUp btfsc PTTstatus,2 ; ali sta bili ze prej obe ON? goto aliObeOFF movf Xflt,0 movwf Xflt_1 ; shranimo zadnje stanje Xflt movlw 0x00 movwf Xflt call preklop bsf PTTstatus,2 ; oznacimo, da sta obe tipki ON (b2 = 1) goto loop aliObeOFF: btfss PTTstatus,2 ; ali sta bili ze prej obe ON? goto aliUp movf Xflt_1,0 movwf Xflt ; restavriramo stanje Xflt call preklop bcf PTTstatus,2 ; oznacimo, da sta bili obe tipki OFF (b2 = 0) goto loop aliUp: btfss Ttmp,7 ; ali je Up? goto aliDown bcf PTTstatus,2 ; zbrisemo spomin o ObeON call gremoGor ; povecamo Xflt call preklop ; izvedemo preklop RELE in vklop LED aliDown: btfss Ttmp,6 ; ali je Down? goto loop bcf PTTstatus,2 ; zbrisemo spomin o ObeON call gremoDol ; zmanjsamo Xflt call preklop ; izvedemo preklop RELE in vklop LED goto loop ;konec zanke ;---------------------------------------------------------------------------------- ;---------------------------- KONEC GLAVNE ZANKE----------------------------------- ;---------------------------------------------------------------------------------- ;********************************************************************************** ;rutina premikanje Gor gremoGor: incf Xflt,1 ; povecamo stevec filtrov movlw 0x0d xorwf Xflt,0 ; vec kot 12 btfsc STATUS,Z ; ce je 0, potem smo na 13 clrf Xflt ; postavimo Xflt na 0 return ;********************************************************************************** ;********************************************************************************** ;rutina premikanje Dol gremoDol: decf Xflt,1 ; zmanjsamo stevec filtrov movlw 0xff xorwf Xflt,0 ; manj kot 0 btfss STATUS,Z ; ce je 0, potem smo na 15 return movlw 0x0c movwf Xflt ; Xflt = 12 return ;********************************************************************************** ;********************************************************************************** ;rutina preklop XFL relejev in vklop XFLT LED preklop: movf Xflt,0 xorlw 0x00 ; ali je NoXFLT (Y0)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali1 movlw B'01001000' ; XFLT (RB1=0); RB6 = RX LED movwf PORTB movlw B'00000000' ; LED (RA0=0; RA1=0; RA6=0; RA7=0) movwf PORTA return ali1: movf Xflt,0 xorlw 0x01 ; ali je SSB1 (Y1)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali2 movlw B'01001010' ; XFLT (RB0=0; RB2=0); RB6 = RX LED movwf PORTB movlw B'00000010' ; XFLT (RA3=0; RA4=0) + LED (RA0=0; RA1=1; RA6=0; RA7=0) movwf PORTA return ali2: movf Xflt,0 xorlw 0x02 ; ali je SSB2 (Y2)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali3 movlw B'01001010' ; XFLT (RB0=0; RB2=0) movwf PORTB movlw B'00001001' ; XFLT (RA3=1; RA4=0) + LED (RA0=1; RA1=0; RA6=0; RA7=0) movwf PORTA return ali3: movf Xflt,0 xorlw 0x03 ; ali je SSB3 (Y3)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali4 movlw B'01001010' ; XFLT (RB0=0; RB2=0); RB6 = RX LED movwf PORTB movlw B'00011011' ; XFLT (RA3=1; RA4=1) + LED (RA0=1; RA1=1; RA6=0; RA7=0) movwf PORTA return ali4: movf Xflt,0 xorlw 0x04 ; ali je SSB4 (Y4)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali5 movlw B'01001010' ; XFLT (RB0=0; RB2=0); RB6 = RX LED movwf PORTB movlw B'10010000' ; XFLT (RA3=0; RA4=1) + LED (RA0=0; RA1=0; RA6=0; RA7=1) movwf PORTA return ali5: movf Xflt,0 xorlw 0x05 ; ali je SSB5 (Y5)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali6 movlw B'01001011' ; XFLT (RB0=1; RB2=0); RB6 = RX LED movwf PORTB movlw B'10010010' ; XFLT (RA3=0; RA4=1) + LED (RA0=0; RA1=1; RA6=0; RA7=1) movwf PORTA return ali6: movf Xflt,0 xorlw 0x06 ; ali je SSB6 (Y6)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali7 movlw B'01001011' ; XFLT (RB0=1; RB2=0); RB6 = RX LED movwf PORTB movlw B'10011001' ; XFLT (RA3=1; RA4=1) + LED (RA0=1; RA1=0; RA6=0; RA7=1) movwf PORTA return ali7: movf Xflt,0 xorlw 0x07 ; ali je SSB7 (Y7)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali8 movlw B'01001011' ; XFLT (RB0=1; RB2=0); RB6 = RX LED movwf PORTB movlw B'10001011' ; XFLT (RA3=1; RA4=0) + LED (RA0=1; RA1=1; RA6=0; RA7=1) movwf PORTA return ali8: movf Xflt,0 xorlw 0x08 ; ali je SSB8 (Y8)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali9 movlw B'01001011' ; XFLT (RB0=1; RB2=0); RB6 = RX LED movwf PORTB movlw B'01000000' ; XFLT (RA3=0; RA4=0) + LED (RA0=0; RA1=0; RA6=1; RA7=0) movwf PORTA return ali9: movf Xflt,0 xorlw 0x09 ; ali je CW1 (Y9)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali10 movlw B'01001111' ; XFLT (RB0=1; RB2=1); RB6 = RX LED movwf PORTB movlw B'01000010' ; XFLT (RA3=0; RA4=0) + LED (RA0=0; RA1=1; RA6=1; RA7=0) movwf PORTA return ali10: movf Xflt,0 xorlw 0xA ; ali je CW2 (Y10)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali11 movlw B'01001111' ; XFLT (RB0=1; RB2=1); RB6 = RX LED movwf PORTB movlw B'01001001' ; XFLT (RA3=1; RA4=0) + LED (RA0=1; RA1=0; RA6=1; RA7=0) movwf PORTA return ali11: movf Xflt,0 xorlw 0xB ; ali je CW3 (Y11)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali12 movlw B'01001110' ; XFLT (RB0=0; RB2=1); RB6 = RX LED movwf PORTB movlw B'01001011' ; XFLT (RA3=1; RA4=0) + LED (RA0=1; RA1=1; RA6=1; RA7=0) movwf PORTA return ali12: movf Xflt,0 xorlw 0xC ; ali je CW4 (Y12)? btfss STATUS,Z ; ce je Z=1 ---> preskoci goto ali13 movlw B'01001110' ; XFLT (RB0=0; RB2=1); RB6 = RX LED movwf PORTB movlw B'11000000' ; XFLT (RA3=0; RA4=0) + LED (RA0=0; RA1=0; RA6=0; RA7=0) movwf PORTA ali13: return ;********************************************************************************** ;********************************************************************************** ;rutina za branje stanja tipk s filtriranjem in ciklanjem ali_je_tipka: movlw .20 ; zacetna vrednost stevca movwf Stejem clrf Ttmp_1 ; zbrisemo prejsnje stanje tipk ; call delay beri_tipke: clrf Ttmp ; zbrisemo Ttmp (0 = ni spremembe) btfss PORTB,7 ; preberemo stanje RB7 bsf Ttmp,7 ; ce je pritisnjena (0) oznacimo bit 7 v Ttmp btfsc PORTB,5 ; preberemo stanje RB5 bsf Ttmp,5 ; ce je pritisnjena (0) oznacimo bit 5 v Ttmp btfsc PORTB,4 ; preberemo stanje RB4 bsf Ttmp,4 ; ce je pritisnjena (0) oznacimo bit 4 v Ttmp btfss PORTA,5 ; preberemo stanje RA5 bsf Ttmp,6 ; ce je pritisnjena (0) oznacimo bit 6 v Ttmp movf Ttpk,0 xorwf Ttmp,0 ; preverimo ali se je kaj spremenilo glede na prejsnje stanje btfss STATUS,Z ; ce je 0, potem je ena tipka/PTT ON/OFF --> tipka_je ; return goto tipka_je goto beri_tipke ;-------------------------------------- filter ---------------------------------------------- tipka_je: call delay1ms ; kratka zakasnitev - 1ms decfsz Stejem,f ; smo presteli do 50? goto je_tipka ; filtriranje return ; **************************** MAIN RETURN ********* je_tipka: movf Ttmp,0 xorwf Ttmp_1,0 ; ali je pritisnjena ista tipka? btfsc STATUS,Z ; ce je 1, potem je ista tipka --> beri_tipke goto beri_tipke movf Ttmp,0 ; ce ni, potem shrani novo vrednost v Ttmp_1 movwf Ttmp_1 ; movlw .20 ; resetiraj stevec movwf Stejem goto beri_tipke ;************************************************************************************ ;kratka delay rutina delay1ms: movlw D'71' ; delay ~1000uS - D'71' movwf Delay1 decfsz Delay1,1 ; this loop does 215 cycles goto $-1 decfsz Delay1,1 ; This loop does 786 cycles goto $-1 return ;konec delay rutine ;variablina delay rutina delay: clrf Delay1 clrf Delay2 clrf Delay3 delay0: decfsz Delay1,1 goto delay0 decfsz Delay2,1 goto delay0 ; decfsz Delay3,1 ; goto delay0 return ;konec delay rutine stop: call delay call delay call delay movlw B'00000000' movwf PORTA ; movlw Ttmp ; movwf Ttmp call delay call delay call delay btfsc Ttmp,7 bsf PORTA,7 btfsc Ttmp,6 bsf PORTA,6 btfsc Ttmp,5 bsf PORTA,1 btfsc Ttmp,4 bsf PORTA,0 ; movlw B'10000010' ; movwf PORTA lp: nop goto lp ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program'