; TITLE DRL05 August list p=16F877A,r=dec #include "P16F877.INC" CBLOCK 0x20 PntrA, PntrB, PntrC, PntrD, PntrE, PntrF, DlyA, DlyB, DlyC, Flag1 ; 29 temp, SJ, D_File, G_File, KeyVal, Rows, ; -F Columns, KeySet, Count, Debounce, KP_tmp, KP_A, KP_B, Dly, File_SJ, BS Ztmp, PntrQ, PntrX, ZG, TESTA, TESTB, S_File ENDC ; PntrA = UP/DN PntrB = L/R PntrC = DRL UP/DN ; PntrD = UP/DN Grid PntrE = L/R Grid PntrF = DRL Grid ; SJ = STEP/JOG D_File = DRL depth G_File = GRID ; S_File = TRAVEL SPEED ZG = Zero Gantry bit. Free flow throgh UP/DN/LT/RT. O_REG equ 0x01 ;page 1, 3 PC equ 0X02 Status equ 0x03 ;page 0, 1, 2, 3 ADCON1 equ 0x9F ;page 1 PortA equ 0x05 ;page 0 PortB equ 0x06 ;page 0, 2 PortC equ 0x07 ;page 0 PortD equ 0x08 ;page 0 PortE equ 0x09 ;page 0 TrisA equ 0x85 ;page 1 TrisB equ 0x86 ;page 1, 3 TrisC equ 0x87 ;page 1 TrisD equ 0x88 ;page 1 TrisE equ 0x89 ;page 1 NEXT equ 0x00 ; KpA 0 ENTER equ 0x01 ; KpA 1 ESC equ 0x02 ; KpA 2 GRID equ 0x03 ; KpA 3 UPsw equ 0x04 ; KpA 4 DNsw equ 0x05 ; KpA 5 LTsw equ 0x06 ; KpA 6 RTsw equ 0x07 ; KpA 7 Xsw equ 0x00 ; KpB 8 X zero limit sw Ysw equ 0x01 ; KpB 9 Y zero limit sw X1sw equ 0x02 ; KpB A Y1sw equ 0x03 ; KpB B DH equ 0x04 ; KpB C DL equ 0x05 ; KpB D OPEN equ 0x06 ; KpB E DRLsw equ 0x07 ; KpB F LCDmd equ 0x00 lcdRS equ 0x01 ; PortC LCD RS pin lcdE equ 0x02 ; PortC LCD E pin D4 equ 0x04 ; PortC LCD 4 D5 equ 0x05 ; PortC LCD 5 D6 equ 0x06 ; PortC LCD 6 D7 equ 0x07 ; PortC LCD 7 RP0 equ 5 ; STATUS bank reg RP1 equ 6 ; STATUS bank reg ORG 0 nop nop nop bcf STATUS,RP1 ; clear Page 2/3bit bsf STATUS,RP0 ; set page 1 bit movlw B'00000111' ; all diital I/O code movwf ADCON1 ; load into ADCON1 clrf TrisA clrf TrisB clrf TrisC movlw B'11110000' movwf TrisD clrf TrisE ; PortE bcf STATUS, RP0 ; rest to page 0 ;------------------------------------------------------------------------- call KILL clrf PortD clrf PortE clrf PntrA clrf PntrB clrf PntrC clrf PntrD clrf PntrE clrf PntrF clrf ZG ; ZG = Zero Gantry bit. SET = Free flow throgh UP/DN/LT/RT. clrf KP_A clrf KP_B ;######################################################################### LCD setup LCDini call DlyS ; 25mS powerup delay @ 4MHz clrf Flag1 ; send instruction as 8 bit mode movlw b'00110000' ; function set 8 bits call LCDins movlw b'00110000' ; function set 8 bits call LCDins movlw b'00110000' ; function set 8 bits call LCDins movlw b'00100000' ; function set 4 bits call LCDins bsf Flag1,LCDmd ; do 4 bit mode from here on movlw b'00101000' ; function set 4 bits, 2 lines, font set # 1 call LCDins movlw b'00001000' ; display = off call LCDins movlw b'00000001' ; clear the display call LCDins movlw b'00000110' ; increment - no display shift call LCDins movlw b'00001100' ; display on, cursor off, blink off call LCDins call CLEAR clrf G_File ; Grid File movlw b'00000011' movwf SJ ; Set S/J and Disp for STEP clrf PntrA clrf PntrB bsf G_File,1 ; Set gantry travel to .1" bsf D_File,4 ; Set drill travel .25" movlw 0x01 ; For bit count test movwf TESTA goto MENUlp ;******************************************************************************* CONFIG ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* MOTOR BITS Bits movf SJ,w ; The TESTA part is for the limit sw test, so it will test at every run through movwf TESTA bcf SJ,1 ; For "JOG" Free flow KP to test for limit sw call TestKP bsf SJ,1 ; Return KP to normal mode. movf TESTA,w movwf SJ btfsc PntrX,0 ; PntrA = bit 0 goto Px1 btfsc PntrX,1 ; PntrB = bit 1 goto Px2 btfsc PntrX,2 ; PntrC = bit 2 goto Px3 Px1 movf PntrA,w movwf PntrQ goto BitsPx Px2 movf PntrB,w movwf PntrQ goto BitsPx Px3 movf PntrC,w movwf PntrQ goto BitsPx BitsPx btfsc PntrX,3 ; BitsA BitsB Clr=A Set=B goto BitsB1 BitsA1 movlw 0x00 xorwf PntrQ,w btfss Status,Z goto BitsA2 retlw 0x03 ; 0011 BitsA2 movlw 0x01 xorwf PntrQ,w btfss Status,Z goto BitsA3 retlw 0x06 ; 0110 BitsA3 movlw 0x02 xorwf PntrQ,w btfss Status,Z goto BitsA4 retlw 0x0C ; 1100 BitsA4 movlw 0x03 xorwf PntrQ,w btfss Status,Z goto BitsA1 retlw 0x09 ; 1001 ;----------------------------------- BitsB1 movlw 0x00 xorwf PntrQ,w btfss Status,Z goto BitsB2 retlw 0x0C ; 1100 BitsB2 movlw 0x01 xorwf PntrQ,w btfss Status,Z goto BitsB3 retlw 0x06 ; 0110 BitsB3 movlw 0x02 xorwf PntrQ,w btfss Status,Z goto BitsB4 retlw 0x03 ; 0011 BitsB4 movlw 0x03 xorwf PntrQ,w btfss Status,Z goto BitsB1 retlw 0x09 ; 1001 X_Bits call KILL ; Kill motors goto MENUlp ;******************************************************************************* MOTOR BITS ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* MENU MENUlp bsf SJ,1 call CLEAR MenuRUN call RUNlp MenuDPOS call dPOS MenuGRID call GRIDlp MenuZERO call ZEROlp MenuDRLfd call DRLfd MenuSPEED call SPDlp goto MENUlp ;******************************************************************************* MENU ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* ZERO TABLE X - Y ZEROlp call CLEAR movlw 0x8A call mess? movlw 0x86 call messZ ; ZERO ? call EntNxt ; ZEROlp1 call TestKP btfsc KP_A,ENTER goto ZEROlp2 btfsc KP_A,NEXT return btfsc KP_A,ESC goto MENUlp goto ZEROlp1 ZEROlp2 call CLEAR movlw 0x89 call messX ; XY? movlw 0x8A ; call messY movlw 0x8B call mess? movlw 0x84 call messZ call EntNxt call TestKP ZEROlp3 btfsc KP_A,ENTER goto ZEROlp4 btfsc KP_A,NEXT goto ZeroX call TestKP btfsc KP_A,ESC goto MENUlp goto ZEROlp3 ZEROlp4 bsf SJ,1 ; Step Mode. Clears Step/Jog bit. If in JOG, code skips limit sw test call ZX1 call ZY1 return ;---------------------------------------------------------------- ZeroX call CLEAR movlw 0x8B call mess? movlw 0x8A call messX ; ZERO X? movlw 0x85 ; call messZ call EntNxt Zero1 call TestKP btfsc KP_A,ENTER goto Zero1a btfsc KP_A,NEXT goto ZeroY btfsc KP_A,ESC goto MENUlp goto Zero1 Zero1a call ZX1 return movf G_File,w ; Set GRID to 1 step. Otherwise possible wall slam. movwf Ztmp ; Temp storage for GRID file, swap back when done movlw b'00010000' movwf G_File return ZeroY call CLEAR movlw 0x8B call mess? movlw 0x8A call messY ; ZERO Y? movlw 0x85 ; call messZ call EntNxt Zero2 call TestKP btfsc KP_A,ENTER goto ZY1 btfsc KP_A,ESC goto MENUlp btfsc KP_A,NEXT return goto Zero2 ZX1 call CLEAR movlw 0x8A call messX ; GANTRY X movlw 0x82 call messZ ZX2 bsf ZG,0 ; Sets bit for X limit sw - run until found call LEFT ZX3 movf Ztmp,w ; Reset GRID movwf G_File call RIGHT ; This backs motor off SW .1" bcf ZG,0 call KILL ; Power off motors bcf KP_B,Xsw ; Clr X limit sw file or it remains set. return ;---------------------------------------------------------------- ZY1 movf G_File,w ; Set GRID to 1. Otherwise possible wall slam. movwf Ztmp movlw b'00010000' movwf G_File call CLEAR movlw 0x8A call messY ; GANTRY Y movlw 0x82 call messZ ZY2 bsf ZG,0 call DOWN ZY3 movf Ztmp,w ; Reset GRID movwf G_File call UP ; This backs motor off SW .1" bcf ZG,0 clrf PortB bcf KP_A,Ysw ; Clr X limit sw file or it remains set. return ;******************************************************************************* GANTRY ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* GRID GRIDlp call CLEAR ; Grid loop for ganrty travel movlw 0x8A call mess? movlw 0x86 call messGRID ; GRID ? call EntNxt ; GRID1 call TestKP btfsc KP_A,ENTER goto GRID3 btfsc KP_A,NEXT goto GRID2 btfsc KP_A,ESC goto MENUlp goto GRID1 GRID2 return GRID3 clrf G_File bsf G_File,0 ; 00000001 GRID4 call TestKP btfsc KP_A,ESC goto MENUlp rlf G_File ; Rotates bit for later test bcf G_File,0 btfsc G_File,4 ; 00010000 .006 goto GRID_0 btfsc G_File,3 ; 00001000 .025 goto GRID_25 btfsc G_File,2 ; 00000100 .050 goto GRID_50 btfsc G_File,1 ; 00000010 .100 goto GRID_100 goto GRID3 ;------------------------------------------------------------------------- GRID_0 call CLEAR movlw 0x8A call mess? movlw 0x89 call mess0 movlw 0x84 call messGRID ; GRID 0? call EntNxt ; GRID0a call TestKP btfsc KP_A,ENTER goto GRID0a1 btfsc KP_A,NEXT goto GRID4 btfsc KP_A,ESC goto MENUlp goto GRID0a GRID0a1 call CLEAR return ;------------------------------------------------------------------------- GRID_25 call CLEAR movlw 0x8b call mess? movlw 0x89 call mess25 movlw 0x84 call messGRID ; GRID 25? call EntNxt ; GRIDb call TestKP btfsc KP_A,ENTER goto GRIDb1 btfsc KP_A,NEXT goto GRID4 btfsc KP_A,ESC goto MENUlp goto GRIDb GRIDb1 call CLEAR return ;------------------------------------------------------------------------- GRID_50 call CLEAR movlw 0x8b call mess? movlw 0x89 call mess50 movlw 0x84 call messGRID ; GRID 50? call EntNxt ; GRIDc call TestKP btfsc KP_A,ENTER goto GRIDc1 btfsc KP_A,NEXT goto GRID4 btfsc KP_A,ESC goto MENUlp goto GRIDc GRIDc1 call CLEAR return ;------------------------------------------------------------------------- GRID_100 call CLEAR movlw 0x8c call mess? movlw 0x89 call mess100 movlw 0x84 call messGRID ; GRID 100? call EntNxt ; GRIDd call TestKP btfsc KP_A,ENTER goto GRIDd1 btfsc KP_A,NEXT goto GRID4 btfsc KP_A,ESC goto MENUlp goto GRIDd GRIDd1 call CLEAR return ;******************************************************************************* GRID ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* RUN RUNlp call CLEAR RUNlpA movlw 0x86 call messRUN ; RUN ? movlw 0x89 call mess? call EntNxt ; RUN1 call TestKP btfss KP_A,ENTER goto RUN3 goto RUN2 RUN2 goto RunSet1 ; "RUN" selected RUN3 btfsc KP_A,NEXT return goto RUN1 RunSet call GRIDlp ; No grid selected RunSet1 call CLEAR ; Check for selected grid movlw 0x8C call messRUN ; RUN btfsc G_File,4 ; 00010000 Free goto RunSet4 btfsc G_File,3 ; 00001000 .025 goto RunSet3 btfsc G_File,2 ; 00000100 .050 goto RunSet2 btfss G_File,1 ; 00000010 .100 goto RunSet call GRID100 ; Load selected grid for disp goto RUN4 RunSet2 call GRID50 goto RUN4 RunSet3 call GRID25 goto RUN4 RunSet4 call GRID0 RUN3a call TestKP call CLR ; Check for direction. UP DN LT RT DRL btfsc KP_A,UPsw goto RUN3a btfsc KP_A,DNsw goto RUN3a btfsc KP_A,LTsw goto RUN3a btfsc KP_A,RTsw goto RUN3a btfsc KP_B,DRLsw goto RUN3a movlw 0x8C call messRUN ; RUN RUN4 call TestKP btfsc KP_A,GRID call RunSet btfsc KP_A,ESC goto MENUlp call KILL btfsc SJ,0 call StpJog1 ; Disp for STEP/JOG - JOG btfss SJ,0 call StpJog2 ; STEP RunSJ0 btfss KP_A,NEXT goto RUN4b RunSJ1 btfsc SJ,0 goto RunSJ2 ; STEP bsf SJ,0 ; SET for STEP/JOG - STEP call StpJog2 ; STEP goto RUN4b RunSJ2 bcf SJ,0 ; CLR call StpJog1 ; JOG RUN4b btfss KP_A,UPsw ; Test for direction goto RUN5 call UP goto RUN3a RUN5 btfss KP_A,DNsw goto MAN6 call DOWN goto RUN3a MAN6 btfss KP_A,LTsw goto MAN7 call LEFT goto RUN3a MAN7 btfss KP_A,RTsw goto MAN8 call RIGHT goto RUN3a MAN8 btfss KP_B,DRLsw goto MAN9 call DRLlp goto RUN3a MAN9 btfss KP_B,OPEN ; Clears TESTA counter file goto RUN4 movlw 0x01 movwf TESTA goto RUN3a ;---------------------------------------------------------------- UP movlw 0xC0 ; UP call messUP movlw b'00000001' ; PntrX is for motor direction: PntrN / BitsA,B- PntrA BitsA movwf PntrX ; PntrX= (Bit0-2 = Pntr)(bit3= BitsA,B) UPa clrf PntrD ; (.1 .05 .25) UPb goto UPd ; Test limit sw UPc movf PntrA,w ; Bit pattern pointer (retlw) call Bits ; Get bit pattern for motor WAS BitsA movwf PortB ; Drive motor call SETa ; Call pointer loop call CountSet ; see if Pointer"x" = "n" xorwf PntrD,W ; if it is, reset it to 0 btfss Status,Z ; test Zero bit goto UPb ; Z = 0, Not done continue btfss SJ,0 ; Test JOG bit return ; Step mode, return bcf SJ,1 ; For "JOG" Free flow KP call TestKP btfsc KP_A,UPsw ; Z = 1, Done goto start. Check sw, if closed restart loop goto UPa bsf SJ,1 ; Return KP to normal mode. return UPd btfss KP_B,Y1sw ; Test for limit sw Otherwise continue to Down & back off sw. goto UPc ;---------------------------------------------------------------- DOWN bsf SJ,1 ; Return KP to normal mode. movlw 0xC0 ; DOWN call messDN DOWNa clrf PntrD movlw b'00001001' ; PntrA, BitsB movwf PntrX DOWNb goto DOWNg DOWNc movf PntrA,w call Bits ; BitsB movwf PortB call SETa call CountSet xorwf PntrD,W btfss Status,Z goto DOWNb btfss SJ,0 return bcf SJ,1 call TestKP btfsc ZG,0 ; ZERO Table Y test bit goto DOWNf ; Look for Y limit sw btfsc KP_A,DNsw goto DOWNa DOWNd call CLR bsf SJ,1 return DOWNe return goto DOWNd ;<<<<<<<<<<<<<<<<<<<<<<<<<<< ?????????????? DOWNf btfsc KP_B,Ysw goto DOWNe goto DOWNa DOWNg btfsc ZG,0 ; ZERO Table Y test bit goto DOWNc ; If in ZERO lp IGNORE, Already looking for this, only for RUN mode btfss KP_B,Ysw ; Test for limit sw goto DOWNc ; Goes to UP goto UP ;---------------------------------------------------------------- LEFT bsf SJ,1 ; Return KP to normal mode. movlw 0xC0 ; LEFT call messLT LEFTa clrf PntrE movlw b'00000010' ; PntrB, BitsA movwf PntrX LEFTb goto LEFTe LEFTc movf PntrB,w call Bits ; BitsA movwf PortA call SETb call CountSet xorwf PntrE,W btfss Status,Z goto LEFTb btfss SJ,0 return bcf SJ,1 call TestKP btfsc ZG,0 ; ZERO Table X test bit goto LEFTd ; Look for X limit sw btfsc KP_A,LTsw goto LEFTa call CLR bsf SJ,1 return LEFTd btfsc KP_B,Xsw ; Test for limit sw return ; ZX3 goto LEFTa LEFTe btfsc ZG,0 ; ZERO Table X left test bit goto LEFTc ; If in ZERO lp IGNORE, Already looking for this, only for RUN mode btfss KP_B,Xsw ; Test for limit sw goto LEFTc ;---------------------------------------------------------------- RIGHT bsf SJ,1 ; Return KP to normal mode. movlw 0xC0 ; RIGHT call messRT RIGHTa clrf PntrE movlw b'00001010' ; PntrB, BitsB movwf PntrX RIGHTb goto RIGHTd RIGHTc movf PntrB,w call Bits ; BitsB movwf PortA call SETb call CountSet xorwf PntrE,W btfss Status,Z goto RIGHTb btfss SJ,0 return bcf SJ,1 call TestKP btfsc KP_A,RTsw goto RIGHTa bsf SJ,1 return RIGHTd btfss KP_B,X1sw ; ZERO Table X right. Test bit Test for limit sw goto RIGHTc goto LEFT ;******************************************************************************* RUN ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* MOTOR BIT CONTROL CountSet btfsc G_File,4 ; For GRID set, see what current grid is set goto BS4 btfsc G_File,3 goto BS3 btfsc G_File,2 goto BS2 btfsc G_File,1 BS1 movlw 0xC8 ; Decimal 200. 2 revs 1.8 deg (.1") return BS2 movlw 0x64 ; Decimal 100. 1 rev 1.8 deg (.05") return BS3 movlw 0x32 ; Decimal 50. 1/2 rev 1.8 deg (.025") return BS4 movlw 0x01 ; Decimal 1. 0 revs 1 step (.001") return ;---------------------------------------------------------------- DRLset btfsc D_File,5 ; For DRILL DEPTH goto DS5 btfsc D_File,4 ; For DRILL DEPTH goto DS4 btfsc D_File,3 goto DS3 btfsc D_File,2 goto DS2 btfsc D_File,1 DS1 movlw 0xC8 ; Decimal 200. 2 revs 1.8 deg (.1") return DS2 movlw 0x96 ; Decimal 100. 1 rev 1.8 deg (.05") return DS3 movlw 0x64 ; Decimal 50. 1/2 rev 1.8 deg (.025") return DS4 movlw 0x32 ; Decimal 1. 0 revs 1 step (.001") return DS5 movlw 0x01 ; Decimal 1. 0 revs 1 step (.001") return ;---------------------------------------------------------------- SETa call DLYset ; Pointer A loop. Pointers for the 4 bit pattern to drive motors movf PntrA,w sublw 0x03 btfss Status,Z goto SETa1 clrf PntrA goto SETa2 SETa1 incf PntrA,f SETa2 incf PntrD return ;---------------------------------------------------------------- SETb call DLYset ; Pointer B loop movf PntrB,w sublw 0x03 btfss Status,Z goto SETb1 clrf PntrB goto SETb2 SETb1 incf PntrB,f SETb2 incf PntrE return ;---------------------------------------------------------------- SETd call DLYset ; Pointer C loop. For DRL movf PntrC,w sublw 0x03 btfss Status,Z goto SETd1 clrf PntrC goto SETd2 SETd1 incf PntrC,f SETd2 incf PntrF return ;---------------------------------------------------------------- DLYset btfsc S_File,3 goto Ds3 btfsc S_File,2 goto Ds2 btfsc S_File,1 Ds1 call Dly1 ; Delay return Ds2 call Dly2 ; Delay return Ds3 call Dly3 ; Delay return ;******************************************************************************* MOTOR BIT CONTROL ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* DRL ;------------------------------------------------------------------------- DRLfd call CLEAR ; Adjusts Drill depth, like spacing grid for travel movlw 0x8A call mess? movlw 0x86 call messFEED ; FEED ? call EntNxt ; FEED1 call TestKP btfsc KP_A,ENTER goto FEED3 btfsc KP_A,NEXT goto FEED2 btfsc KP_A,ESC goto MENUlp goto FEED1 FEED2 return FEED3 clrf D_File bsf D_File,0 ; 00000001 X FEED4 rlf D_File bcf D_File,0 btfsc D_File,5 ; 00100000 .006 goto FEED_0 btfsc D_File,4 ; 00010000 .025 goto FEED_25 btfsc D_File,3 ; 00001000 .050 goto FEED_50 btfsc D_File,2 ; 00000100 .100 goto FEED_75 btfsc D_File,1 ; 00000010 .100 goto FEED_100 goto FEED3 ;------------------------------------------------------------------------- FEED_0 call CLEAR movlw 0x8A call mess? movlw 0x89 call mess1 movlw 0x84 call messFEED ; FEED 1? call EntNxt ; FEED0a call TestKP btfsc KP_A,ENTER goto FEED0a1 btfsc KP_A,NEXT goto FEED4 btfsc KP_A,ESC goto MENUlp goto FEED0a FEED0a1 call CLEAR return ;------------------------------------------------------------------------- FEED_25 call CLEAR movlw 0x8b call mess? movlw 0x89 call mess25 movlw 0x84 call messFEED ; FEED 25? call EntNxt ; FEEDb call TestKP btfsc KP_A,ENTER goto FEEDb1 btfsc KP_A,NEXT goto FEED4 btfsc KP_A,ESC goto MENUlp goto FEEDb FEEDb1 call CLEAR return ;------------------------------------------------------------------------- FEED_50 call CLEAR movlw 0x8b call mess? movlw 0x89 call mess50 movlw 0x84 call messFEED ; FEED 50? call EntNxt ; FEEDc call TestKP btfsc KP_A,ENTER goto FEEDc1 btfsc KP_A,NEXT goto FEED4 btfsc KP_A,ESC goto MENUlp goto FEEDc FEEDc1 call CLEAR return ;------------------------------------------------------------------------- FEED_75 call CLEAR movlw 0x8b call mess? movlw 0x89 call mess75 movlw 0x84 call messFEED ; FEED 75? call EntNxt ; FEEDd call TestKP btfsc KP_A,ENTER goto FEEDd1 btfsc KP_A,NEXT goto FEED4 btfsc KP_A,ESC goto MENUlp goto FEEDd FEEDd1 call CLEAR return ;------------------------------------------------------------------------- FEED_100 call CLEAR movlw 0x8c call mess? movlw 0x89 call mess100 movlw 0x84 call messFEED ; FEED 100? call EntNxt ; FEEDe call TestKP btfsc KP_A,ENTER goto FEEDe1 btfsc KP_A,NEXT goto FEED4 btfsc KP_A,ESC goto MENUlp goto FEEDe FEEDe1 call CLEAR return ;---------------------------------------------------------------- dPOS bcf D_File,6 ; Clear Z limit sw test bit call CLEAR ; dPOS, Set drill hieght from table. movlw 0x83 call messDRL movlw 0x89 call messPOS movlw 0x8C call mess? ; DRILL POS? call EntNxt ; dPOS1 call TestKP btfsc KP_A,ENTER goto dPOS2 btfsc KP_A,NEXT return btfsc KP_A,ESC goto MENUlp goto dPOS1 dPOS2 call CLEAR movlw 0x83 call messDRL movlw 0x89 call messPOS movlw 0x8C ; "DRILL POS" movf D_File,w ; Set GRID to 0. Otherwise possible wall slam. movwf Ztmp movlw b'10100000' ; Bit 7 is bit for dPOS movwf D_File bcf SJ,1 ; JOG Mode. Clears Step/Jog bit. JOG dPOS3 call CLR ; Clear display UP - DOWN clrf PortD call TestKP btfsc KP_A,DNsw call DRLlp btfsc KP_A,UPsw call DRLup btfss KP_B,DH goto dPOS4 movlw b'11001000' ; Set for .5" call DRLlp to back off sw. Set bit 6 for BACKOFF test later movwf D_File call DRLlp dPOS4 btfss KP_B,DL goto dPOS5 movlw b'11001000' ; Set for .5" call up to back off sw. Set bit 6 for BACKOFF test later movwf D_File call DRLup dPOS5 btfss KP_A,ESC goto dPOS6 bsf SJ,1 ; Return KP to normal movf Ztmp,w ; Reset DRILL GRID movwf D_File call KILL return dPOS6 movlw b'10100000' movwf D_File goto dPOS3 ;---------------------------------------------------------------- DRLlp call CLR ; Drill loop for drilling. Drill down movlw 0xC0 ; DOWN call messDN DRLdn1 clrf PntrF DRLdn2 movlw b'00000100' ; PntrC, BitsA movwf PntrX movf PntrC,w call Bits ; BitsA movwf PortD call SETd call DRLset xorwf PntrF,W btfss Status,Z goto DRLdn2 goto DRLdn3 DRLdn3 btfsc D_File,6 ; Z limit sw test goto DRLclr ; Now clear test bit DRLdn4 btfss D_File,7 goto DRLup btfsc KP_A,DNsw goto DRLdn1 return DRLclr bcf D_File,6 goto DRLdn4 ;---------------------------------------------------------------- DRLup call CLR movlw 0xC0 ; UP call messUP DRLup1 clrf PntrF DRLup2 movlw b'00001100' ; PntrC, BitsB movwf PntrX movf PntrC,w call Bits ; BitsB movwf PortD call SETd call DRLset xorwf PntrF,W btfss Status,Z goto DRLup2 goto DRLup3 DRLup3 btfsc D_File,6 ; Z limit sw test goto DRLclr1 ; Now clear test bit DRLup4 btfss D_File,7 return btfsc KP_A,UPsw goto DRLup1 return DRLclr1 bcf D_File,6 goto DRLup4 ;******************************************************************************* DRL ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* ZERO X/Y KILL clrf PortA clrf PortB clrf PortD return ;******************************************************************************* ZERO X/Y ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* KP TestKP clrf KP_A clrf KP_B call K_Chk ; Check keypad btfss KeyVal,7 ; If = 1 then no key pressed goto K_Dn ; Key pressed return ;------------------------------------------------------------------------- K_Dn btfss SJ,1 ; For "Jog" Free flow KP. JOG=Clr goto K_Dn1 btfsc KeySet,0 ; If = 0 then key just pressed goto TestKP ; Key is still pressed bsf KeySet,0 ; Flag key is pressed K_Dn1 movf KeyVal,W ; Service key movwf KP_tmp ; KP data tmp file goto KP_1 ;------------------------------------------------------------------------- K_Chk movlw b'00000001' ; Make ready to set Row 1 high (RB0) movwf Rows clrf KeyVal ; Initialise Key Value RowLp movf Rows,W ; Set a Row high movwf PortC movf PortD,W ; Read PortD andlw b'11110000' ; This is columns 11111000=5, col 11111100=6 col etc. movwf Columns ; Save the data - only interested in upper 4 bits btfss STATUS,Z goto ChkCol ; Z = clear, key must be pressed movlw 4h ; No bits set for this row addwf KeyVal ; Looking at next row goto NxRow ChkCol bcf STATUS,C ; Clear the carry bit rlf Columns ; If Carry = 1, key is pressed btfsc STATUS,C goto Rows0 ; Key is pressed, KeyVal = key incf KeyVal ; On next column so increment Key Value movf Columns ; If = 0, then all columns checked for this row btfss STATUS,Z goto ChkCol ; Check value of next column NxRow bcf STATUS,C ; Clear the carry bit rlf Rows ; Make ready to set next Row = high btfss Rows,4 ; Test if all Rows have been set goto RowLp ; Not yet, bit 4 will be set when all rows checked movlw 0xFF ; No keys pressed movwf KeyVal bcf KeySet,0 return Rows0 clrf PortC ; All rows = low return ; Goto key check line ;------------------------------------------------------------ KP_1 movlw 0x00 ; Test for file match (0=match) Keypad puts out 0 to F hex xorwf KP_tmp,w ; btfss Status,Z ; Test Zero bit 0=match goto KP_2 ; No match bsf KP_A,NEXT ; Set bit for key pressed for later test return ;------------------------------------------------------------ KP_2 movlw 0x01 xorwf KP_tmp,w btfss Status,Z goto KP_3 bsf KP_A,ENTER return ;------------------------------------------------------------ KP_3 movlw 0x02 xorwf KP_tmp,w btfss Status,Z goto KP_4 bsf KP_A,ESC return ;------------------------------------------------------------ KP_4 movlw 0x03 xorwf KP_tmp,w btfss Status,Z goto KP_5 bsf KP_A,GRID return ;------------------------------------------------------------ KP_5 movlw 0x04 xorwf KP_tmp,w btfss Status,Z goto KP_6 bsf KP_A,UPsw return ;------------------------------------------------------------ KP_6 movlw 0x05 xorwf KP_tmp,w btfss Status,Z goto KP_7 bsf KP_A,DNsw return ;------------------------------------------------------------ KP_7 movlw 0x06 xorwf KP_tmp,w btfss Status,Z goto KP_8 bsf KP_A,LTsw return ;------------------------------------------------------------ KP_8 movlw 0x07 xorwf KP_tmp,w btfss Status,Z goto KP_9 bsf KP_A,RTsw return ;------------------------------------------------------------ KP_9 movlw 0x08 xorwf KP_tmp,w btfss Status,Z goto KP_10 bsf KP_B,Xsw return ;------------------------------------------------------------ KP_10 movlw 0x09 xorwf KP_tmp,w btfss Status,Z goto KP_11 bsf KP_B,Ysw return ;------------------------------------------------------------ KP_11 movlw 0x0A xorwf KP_tmp,w btfss Status,Z goto KP_12 bsf KP_B,X1sw return ;------------------------------------------------------------ KP_12 movlw 0x0B xorwf KP_tmp,w btfss Status,Z goto KP_13 bsf KP_B,Y1sw return ;------------------------------------------------------------ KP_13 movlw 0x0C xorwf KP_tmp,w btfss Status,Z goto KP_14 bsf KP_B,DH return ;------------------------------------------------------------ KP_14 movlw 0x0D xorwf KP_tmp,w btfss Status,Z goto KP_15 bsf KP_B,DL return ;------------------------------------------------------------ KP_15 movlw 0x0E xorwf KP_tmp,w btfss Status,Z goto KP_16 bsf KP_B,OPEN return ;------------------------------------------------------------ KP_16 movlw 0x0F xorwf KP_tmp,w btfss Status,Z return bsf KP_B,DRLsw return ;******************************************************************************* KP ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* DLY DRLdly movlw D'4' ; .75 sec movwf DlyC movlw D'209' movwf DlyB clrf DlyA loopA decfsz DlyA,1 goto loopA decfsz DlyB,1 goto loopA decfsz DlyC,1 goto loopA return ;---------------------------------------------------------------- SWdly movlw D'98' ; 0.0750 movwf DlyB movlw D'102' movwf DlyA loopB decfsz DlyA,1 goto loopB decfsz DlyB,1 goto loopB return ;---------------------------------------------------------------- DlyS movlw D'6' ;PIC Time Delay = 0.0040020 s with Osc = 4.000 MHz movwf DlyB movlw D'62' movwf DlyA loopD decfsz DlyA,1 goto loopD decfsz DlyB,1 goto loopD return ;---------------------------------------------------------------- Dly1 movlw D'6' ;PIC Time Delay = 0.0040020 s with Osc = 4.000 MHz movwf DlyB movlw D'49' movwf DlyA loopE decfsz DlyA,1 goto loopE decfsz DlyB,1 goto loopE return ;---------------------------------------------------------------- Dly2 movlw D'7' ;PIC Time Delay = 0.0040020 s with Osc = 4.000 MHz movwf DlyB movlw D'129' movwf DlyA loopF decfsz DlyA,1 goto loopF decfsz DlyB,1 goto loopF return ;---------------------------------------------------------------- Dly3 movlw D'8' ;PIC Time Delay = 0.0040020 s with Osc = 4.000 MHz movwf DlyB movlw D'202' movwf DlyA loopG decfsz DlyA,1 goto loopG decfsz DlyB,1 goto loopG return ;******************************************************************************* DLY ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* LCD LCDins bcf PortE,lcdRS bcf PortE,lcdE movwf temp ; temp save instruction andlw 0xF0 ; send high nibble first movwf PortC ; send it call Clock bsf PortE,lcdE ; (1) clock it in call Clock bcf PortE,lcdE ; (1) call Clock btfss Flag1,LCDmd ; test if sending byte or 2 nibbles goto bits8 ; 1 nibble swapf temp,W ; now send lower nibble andlw 0xF0 movwf PortC ; send it call Clock bsf PortE,lcdE ; (5) enable instruction call Clock bcf PortE,lcdE ; (5) bits8 clrf DlyA ; about a 6mS delay @ 4MHz movlw 8h movwf DlyC ctlp1 decfsz DlyA,F goto ctlp1 decfsz DlyC,F goto ctlp1 return LCDdata movwf temp ; temp save data andlw 0xF0 ; send high nibble first movwf PortC call Clock bsf PortE,lcdRS ; (0) Write "data" call Clock bsf PortE,lcdE ; (1) clock it in call Clock bcf PortE,lcdE ; (1) call Clock swapf temp,W ; now send lower nibble andlw 0xF0 movwf PortC call Clock bsf PortE,lcdRS ; (0) Write "data" call Clock bsf PortE,lcdE ; (5) enable instruction call Clock bcf PortE,lcdE ; (5) return Clock movlw 40h movwf DlyA kdloop decfsz DlyA,F goto kdloop return ;---------------------------------------------------------------- CLEAR movlw 1h call LCDins return ;******************************************************************************* LCD ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* TRAVEL SPEED SPDlp call CLEAR ; Grid loop for ganrty travel movlw 0x8A call mess? movlw 0x85 call messSPD ; SPEED ? call EntNxt ; SPD1 call TestKP btfsc KP_A,ENTER goto SPD3 btfsc KP_A,NEXT goto SPD2 btfsc KP_A,ESC goto MENUlp goto SPD1 SPD2 return SPD3 clrf S_File bsf S_File,0 ; 00000001 SPD4 call TestKP btfsc KP_A,ESC goto MENUlp rlf S_File ; Rotates bit for later test bcf S_File,0 btfsc S_File,3 ; 00001000 .006 goto SPD_1 btfsc S_File,2 ; 00000100 .025 goto SPD_2 btfsc S_File,1 ; 00000010 .050 goto SPD_3 goto SPD3 ;------------------------------------------------------------------------- SPD_1 call CLEAR movlw 0x8B call mess? movlw 0x8A call mess1 movlw 0x84 call messSPD ; SPEED 1? call EntNxt ; SPD0a call TestKP btfsc KP_A,ENTER goto SPD0a1 btfsc KP_A,NEXT goto SPD4 btfsc KP_A,ESC goto MENUlp goto SPD0a SPD0a1 call CLEAR return ;------------------------------------------------------------------------- SPD_2 call CLEAR movlw 0x8B call mess? movlw 0x8A call mess2 movlw 0x84 call messSPD ; SPEED 2? call EntNxt ; SPDb call TestKP btfsc KP_A,ENTER goto SPDb1 btfsc KP_A,NEXT goto SPD4 btfsc KP_A,ESC goto MENUlp goto SPDb SPDb1 call CLEAR return ;------------------------------------------------------------------------- SPD_3 call CLEAR movlw 0x8B call mess? movlw 0x8A call mess3 movlw 0x84 call messSPD ; SPEED 3? call EntNxt ; SPDc call TestKP btfsc KP_A,ENTER goto SPDc1 btfsc KP_A,NEXT goto SPD4 btfsc KP_A,ESC goto MENUlp goto SPDc SPDc1 call CLEAR return ;******************************************************************************* TRAVEL SPEED ;>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>< ;******************************************************************************* MESS CLR movlw 0xC0 call messCLEAR return EntNxt movlw 0xC1 call messEN ; return StpJog1 movlw 0xCB call messJOG return StpJog2 movlw 0xCB call messSTEP return GRID0 movlw 0x85 call mess0 movlw 0x80 call messGRID ; GRID 0 return GRID25 movlw 0x85 call mess25 movlw 0x80 call messGRID ; GRID 25 return GRID50 movlw 0x85 call mess50 movlw 0x80 call messGRID ; GRID 50 return GRID100 movlw 0x85 call mess100 movlw 0x80 call messGRID ; GRID 100 return XY0 movlw 0x85 call messX movlw 0x86 call mess0 movlw 0x87 call messY movlw 0x88 call mess0 movlw 0x89 call mess? return messZ call LCDins movlw 'Z' call LCDdata movlw 'E' call LCDdata movlw 'R' call LCDdata movlw 'O' call LCDdata return messFEED call LCDins movlw 'F' call LCDdata movlw 'E' call LCDdata movlw 'E' call LCDdata movlw 'D' call LCDdata return messNEXT call LCDins movlw '<' call LCDdata movlw 'N' call LCDdata movlw 'E' call LCDdata movlw 'X' call LCDdata movlw 'T' call LCDdata movlw '>' call LCDdata return mess? call LCDins movlw '?' call LCDdata return messX call LCDins movlw 'X' call LCDdata return messY call LCDins movlw 'Y' call LCDdata return messXY call LCDins movlw 'X' call LCDdata movlw '/' call LCDdata movlw 'Y' call LCDdata return mess0 call LCDins movlw '0' call LCDdata return mess1 call LCDins movlw '1' call LCDdata return mess2 call LCDins movlw '2' call LCDdata return mess3 call LCDins movlw '3' call LCDdata return mess4 call LCDins movlw '4' call LCDdata return mess5 call LCDins movlw '5' call LCDdata return mess25 call LCDins movlw '2' call LCDdata movlw '5' call LCDdata return mess50 call LCDins movlw '5' call LCDdata movlw '0' call LCDdata return mess75 call LCDins movlw '7' call LCDdata movlw '5' call LCDdata return mess100 call LCDins movlw '1' call LCDdata movlw '0' call LCDdata movlw '0' call LCDdata return messGRID call LCDins movlw 'G' call LCDdata movlw 'R' call LCDdata movlw 'I' call LCDdata movlw 'D' call LCDdata return messGRD call LCDins movlw 'G' call LCDdata movlw 'R' call LCDdata movlw 'D' call LCDdata return messEN call LCDins movlw '<' call LCDdata movlw 'N' call LCDdata movlw 'E' call LCDdata movlw 'X' call LCDdata movlw 'T' call LCDdata movlw '>' call LCDdata movlw ' ' call LCDdata movlw '<' call LCDdata movlw 'E' call LCDdata movlw 'N' call LCDdata movlw 'T' call LCDdata movlw 'E' call LCDdata movlw 'R' call LCDdata movlw '>' call LCDdata return messMENU call LCDins movlw '*' call LCDdata movlw '*' call LCDdata movlw 'M' call LCDdata movlw 'E' call LCDdata movlw 'N' call LCDdata movlw 'U' call LCDdata movlw '*' call LCDdata movlw '*' call LCDdata return messRUN call LCDins movlw 'R' call LCDdata movlw 'U' call LCDdata movlw 'N' call LCDdata return messJOG call LCDins movlw ' ' call LCDdata movlw 'J' call LCDdata movlw 'O' call LCDdata movlw 'G' call LCDdata return messSTEP call LCDins movlw 'S' call LCDdata movlw 'T' call LCDdata movlw 'E' call LCDdata movlw 'P' call LCDdata return messCLEAR call LCDins movlw ' ' call LCDdata movlw ' ' call LCDdata movlw ' ' call LCDdata movlw ' ' call LCDdata movlw ' ' call LCDdata movlw ' ' call LCDdata movlw ' ' call LCDdata return messUP call LCDins movlw 'U' call LCDdata movlw 'P' call LCDdata return messDN call LCDins movlw 'D' call LCDdata movlw 'O' call LCDdata movlw 'W' call LCDdata movlw 'N' call LCDdata return messLT call LCDins movlw 'L' call LCDdata movlw 'E' call LCDdata movlw 'F' call LCDdata movlw 'T' call LCDdata return messRT call LCDins movlw 'R' call LCDdata movlw 'I' call LCDdata movlw 'G' call LCDdata movlw 'H' call LCDdata movlw 'T' call LCDdata return messDRL call LCDins movlw 'D' call LCDdata movlw 'R' call LCDdata movlw 'I' call LCDdata movlw 'L' call LCDdata movlw 'L' call LCDdata return messPOS call LCDins movlw 'P' call LCDdata movlw 'O' call LCDdata movlw 'S' call LCDdata return messdFD call LCDins movlw 'd' call LCDdata movlw 'F' call LCDdata movlw 'D' call LCDdata return messSPD call LCDins movlw 'S' call LCDdata movlw 'P' call LCDdata movlw 'E' call LCDdata movlw 'E' call LCDdata movlw 'D' call LCDdata return end