;new structure started as 08/02/09 ;V6.1.6 ;d/D added ;J added ;E added ;i/o completed ;I added ;reduce code space in i command ;o command change to H ;L command added ;OXYYYY command added ;cXYYYY command added ;c4 can not activate ;bug in H2,3 ;need to move some code to other page ;pin assignment ; ;LCD data pins -------> portd 0~7 ;LCD control ---------> porte 0,1 ;Keyboard ------------> portc 6,7 ; ; ; list p=16f877 #INCLUDE __CONFIG _HS_OSC & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF ;--------------------------------------------------------------------------------------------- ; DEFINES: ;--------------------------------------------------------------------------------------------- #DEFINE dpin PORTC, 6 #DEFINE clkpin PORTC, 7 #DEFINE lcdport PORTD #DEFINE lcdrs PORTE, 0 #DEFINE lcden PORTE, 1 #DEFINE dirpin PORTE, 1 #DEFINE pulspin PORTE, 1 #DEFINE INPUT PORTA #DEFINE INPUT0 PORTA, 0 #DEFINE INPUT1 PORTA, 1 #DEFINE INPUT2 PORTA, 2 #DEFINE INPUT3 PORTA, 3 #DEFINE INPUT4 PORTA, 4 #DEFINE OUTPUT PORTC #DEFINE OUTPUT0 PORTC, 0 #DEFINE OUTPUT1 PORTC, 1 #DEFINE OUTPUT2 PORTC, 2 #DEFINE OUTPUT3 PORTC, 3 ;--------------------------------------------------------------------------------------------- ;Function specific ;--------------------------------------------------------------------------------------------- #DEFINE ONTIME 2 #DEFINE OFFTIME 2 ;--------------------------------------------------------------------------------------------- cblock 0x020 DISPLAY1 DISPLAY2 counter ps2data POINTER CHAR_CT LCD_DATA VMS_D VS_D d1svar d1msvar d.5msvar vmsvar edata addi temp temp1 temp2 ; to be used only within routine keycnt ; keycnt_temp check keystatus ; F/E/cap/tab/rctrl/lctrl/rshift/lshift keystatus1 ; / / / / /right arrow/left arrow/backspace/unsave stepstatus ; / / / / / /dir inbuff:10 lcnt lcnt_temp VMSD limit oldkey olddkey mem0 mem1 wtmp pcltmp stmp IN1 IN11 IN2 IN3 IN4 CRESULT CRESULT11 MUL1 MUL2 MUL16LL MUL16LH MUL16HL MUL16HH PRODL PRODH PROD16LL PROD16LH PROD16HL PROD16HH TMPMULH TEMP0 TEMP1 TEMP2 TEMP3 abscnt rcntl rcnth firstChar index endc ORG H'00' GOTO MAINLINE ORG H'04' movwf wtmp movf STATUS,w movwf stmp movf PCLATH,w movwf pcltmp movf lcnt,w movwf lcnt_temp ; movf keycnt,w ; movwf keycnt_temp bcf INTCON,4 ;disable int during routine bcf INTCON,1 clrf lcnt isr_bgn call LCD_CLR call header call LCD_NX call recallmem ;;;;;;;;;debug ; call LCD_CLR ; call D1S ; call header ; call LCD_NX ; call header ; call D1S ; call D1S ;;;;;;;;;;;; ; call D1S ; call LCD_CLR ; call D1S MOVLW inbuff MOVWF FSR movf INDF,w movwf firstChar ;;;;;;;;;debug ; movwf LCD_DATA ; call LCD_W ; call D1S ; call D1S ;;;;;;;;;;;; ;return here is ALL ASCII character movf keycnt,w sublw d'1' btfsc STATUS,Z goto chkd call CONVERT ;if 0, no need to check anymore MOVF rcntl,w btfss STATUS,Z goto chkd MOVF rcnth,w btfsc STATUS,Z goto chkJ ;;need to review decf rcnth,f movlw h'ff' movwf rcntl chkd movf firstChar,w ; ms delay sublw b'01100100' btfss STATUS,Z goto chkD ; bsf PORTA,0 ; movf INDF,w ; second delay ; movlw b'01100100' ; movwf LCD_DATA ; call LCD_W ; call D1S ; bcf PORTA,0 dproc btfss firstChar,5 goto dprocM call D1MS goto dprocS dprocM call D1S ; decfsz rcntl dprocS movf rcntl,f btfsc STATUS,Z goto dproc1 decf rcntl,f goto dproc dproc1 movf rcnth,f btfsc STATUS,Z goto dend decf rcnth,f movlw h'ff' movwf rcntl goto dproc dend goto nextLine chkD movf firstChar,w ; second delay sublw b'01000100' btfss STATUS,Z goto chki goto dprocS ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine chki movf firstChar,w ; wait inpute sublw b'01101001' btfss STATUS,Z goto chkI ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine iIproc movf rcntl,w call bitmask movwf index iChk btfss firstChar,5 goto IChk movf INPUT,w andwf index,w btfsc STATUS,Z goto iChk movlw d'20' movwf vmsvar call DMS_V movf INPUT,w andwf index,w btfss STATUS,Z goto nextLine goto iChk IChk movf INPUT,w andwf index,w btfsc STATUS,Z incf lcnt,f goto nextLine ;chkichk ; btfss INPUT,rcntl ; goto chkichk ; ; movlw d'20' ; movwf vmsvar ; call DMS_V ; ; btfsc INPUT,rcntl ; goto nextLine ; goto chkichk chkI movf firstChar,w ; wait inpute sublw b'01001001' btfss STATUS,Z goto chkc goto iIproc ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine chkc movf firstChar,w ; wait inpute sublw b'01100011' btfss STATUS,Z goto chkH ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine MOVLW inbuff MOVWF FSR incf FSR,f movf INDF,w movwf firstChar andlw b'11111000' xorlw b'00110000' btfss STATUS,Z goto nextLine movlw b'00000111' andwf firstChar,w movwf firstChar addlw -d'5' btfsc STATUS,C goto nextLine ; movlw d'5' ; subwf firstChar,w ; call DEBUG ; call D1S ; call D1S ; movf firstChar,w ; sublw d'4' movf firstChar,w call bitmask movwf index ; call DEBUG ; call D1S ; call D1S ; call D1S ; call D1S ; call D1S call CONVERT ; movf rcntl,w ; call DEBUG MOVF rcntl,w btfss STATUS,Z goto cproc3 MOVF rcnth,w btfsc STATUS,Z goto nextLine ;;need to review decf rcnth,f movlw h'ff' movwf rcntl cproc3 decf rcntl,f cproc movf index,w ;up edge andwf INPUT btfsc STATUS,Z goto cproc movlw d'50' movwf vmsvar call DMS_V cproc2 movf index,w ;down edge andwf INPUT btfss STATUS,Z goto cproc2 ; call LCD_CLR ; movf rcntl,w ; call DEBUG ;;;;;;;;;;;;;;;;;;; ; movf index,w ; iorwf OUTPUT,f ; ; movlw ONTIME ; movwf vmsvar ; call DMS_V ; ; comf index,w ; andwf OUTPUT,f ; ; movlw OFFTIME ; movwf vmsvar ; call DMS_V ;;;;;;;;;;;;;;;;;; movf rcntl,f btfsc STATUS,Z goto cproc1 decf rcntl,f goto cproc cproc1 movf rcnth,f btfsc STATUS,Z goto nextLine decf rcnth,f movlw h'ff' movwf rcntl goto cproc chkH movf firstChar,w ; output sublw b'01001000' btfss STATUS,Z goto chkO ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine ; bcf STATUS,DC ; movlw d'6' ; subwf rcntl,w ; movf rcntl,w ; sublw d'4' ; btfss STATUS,DC ; goto nextLine ; decf rcntl,f chkH0 decfsz rcntl goto chkH1 HZero bsf OUTPUT0 goto nextLine chkH1 decfsz rcntl goto chkH2 HOne bsf OUTPUT1 goto nextLine chkH2 decfsz rcntl goto chkH3 HTwo bsf OUTPUT2 goto nextLine chkH3 decfsz rcntl goto nextLine HThree bsf OUTPUT3 goto nextLine chkO movf firstChar,w ; output pulse sublw b'01001111' btfss STATUS,Z goto chkl MOVLW inbuff MOVWF FSR incf FSR,f ; movf INDF,w ; movwf LCD_DATA ; call LCD_W ; call D1S ; call D1S ; call D1S ; call D1S movf INDF,w movwf firstChar andlw b'11111000' xorlw b'00110000' btfss STATUS,Z goto nextLine movlw b'00000111' andwf firstChar,w movwf firstChar addlw -d'5' btfsc STATUS,C goto nextLine movf firstChar,w call bitmask movwf index ; call DEBUG ; call D1S ; call D1S ; call D1S ; call D1S ; call D1S call CONVERT MOVF rcntl,w btfss STATUS,Z goto Oproc MOVF rcnth,w btfsc STATUS,Z goto nextLine ;;need to review decf rcnth,f movlw h'ff' movwf rcntl Oproc movf index,w iorwf OUTPUT,f movlw ONTIME movwf vmsvar call DMS_V comf index,w andwf OUTPUT,f movlw OFFTIME movwf vmsvar call DMS_V movf rcntl,f btfsc STATUS,Z goto Oproc1 decf rcntl,f goto Oproc Oproc1 movf rcnth,f btfsc STATUS,Z goto nextLine decf rcnth,f movlw h'ff' movwf rcntl goto Oproc chkl movf firstChar,w ; for loop sublw b'01101100' btfss STATUS,Z goto chkL ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine chkL movf firstChar,w ; forever loop sublw b'01001100' btfss STATUS,Z goto chkJ ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine ; goto HLproc ; decf rcntl,f chkL0 decfsz rcntl goto chkL1 LZero bcf OUTPUT0 goto nextLine chkL1 decfsz rcntl goto chkL2 LOne bcf OUTPUT1 goto nextLine chkL2 decfsz rcntl goto chkL3 LTwo bcf OUTPUT2 goto nextLine chkL3 decfsz rcntl goto nextLine LThree bcf OUTPUT3 goto nextLine chkJ movf firstChar,w ; jump sublw b'01001010' btfss STATUS,Z goto chkE ; movf firstChar,w ; second delay ; movlw b'11001111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; goto nextLine bcf STATUS,C ; movlw d'6' ; subwf rcntl,w movf rcntl,w sublw d'16' btfss STATUS,C goto nextLine ; movlw d'16' ; movf rcntl,f ; subwf rcntl,w ; btfss STATUS,C ; goto nextLine ; decf rcntl,f ; call LCD_CLR ; movf rcntl,w ; call DEBUG ; call D1S ; call D1S ; call D1S ; call D1S movf rcntl,w movwf lcnt ; goto nextLine goto isr_bgn chkE movf firstChar,w ; end sublw b'01000101' btfss STATUS,Z goto chkInvalid movf firstChar,w ; second delay ; movlw b'11001111' movwf LCD_DATA call LCD_W call D1S goto isr_end ;ploop movwf vmsvar ; call DMS_V ; movf rcnth,w ; btfsc STATUS,Z ; goto chknxt ; movlw h'ff' ; movwf vmsvar ; decfsz rcnth ; goto ploop ; goto chknxt ;to handle invalid instruction and character ;skip instruction chkInvalid goto nextLine chknxt movf INDF,w ; next line sublw h'3e' btfsc STATUS,Z goto nextLine incf FSR,f incf keycnt,f movf keycnt,w sublw d'17' btfsc STATUS,Z goto isr_end goto chknxt ; movf INDF,w nextLine ; bcf PORTA,0 incf lcnt,f call LCD_CLR goto isr_bgn errpl movlw b'11101111' movwf LCD_DATA call LCD_W call D1S call LCD_CLR call header call LCD_NX call recallmem isr_end call LCD_CLR ; movf keycnt_temp,w ; movwf keycnt movf lcnt_temp,w movwf lcnt call header call LCD_NX call recallmem movlw b'10010000' ;interrupt setting movwf INTCON movf pcltmp,w movwf PCLATH movf stmp,w movwf STATUS movf wtmp,w ; decf lcnt,f retfie MAINLINE NOP CLRF PCLATH CLRF STATUS clrf PORTA clrf PORTB clrf PORTC clrf PORTD clrf keycnt clrf temp1 clrf check clrf keystatus clrf keystatus1 clrf lcnt clrf abscnt BSF STATUS,RP0 MOVLW B'000000111' MOVWF ADCON1 MOVLW B'00011111' MOVWF TRISA MOVLW B'00000001' MOVWF TRISB MOVLW B'00000000' MOVWF TRISC MOVLW B'00000000' MOVWF TRISD MOVLW B'00000000' MOVWF TRISE BSF TXSTA,BRGH MOVLW D'255' ; Form a byte to signify 19.2 Baud rate. MOVWF SPBRG ; Set the Baud Rate Generator to 19.2 Baud Rate. BCF STATUS,RP0 ; Select Bank 0 Registers. MOVLW B'10010000' ; Form a byte to signify: ; Bit 7 Serial Port enabled. ; Bit 6 Select 8 bit reception. ; Bit 5 Don't care. ; Bit 4 Enable continuous receive mode. ; Bit 3 Don't care. ; Bit 2 Framing Error. ; Bit 1 Overrun Error. ; Bit 0 9th bit. MOVWF RCSTA ; Initialize Receive Status and control register. BSF STATUS,RP0 ; Select Bank 1 Registers. MOVLW B'00000010' ; Form a byte to signify: ; Bit 7 Don't care in Asynchronous mode. ; Bit 6 Select 8 bit transmission. ; Bit 5 Enable the transmitter. ; Bit 4 Select Asynchronous mode. ; Bit 3 Don't care. ; Bit 2 Select Low Speed BRG. ; Bit 1 Xmit Shift Reg. Empty. ; Bit 0 9th bit. MOVWF TXSTA ; Initialize Transmit Status/control register. BsF OPTION_REG,6 CLRF STATUS bsf pulspin movlw b'10010000' ;interrupt setting movwf INTCON ;--------------------------------------------------------------------- ;WELCOME NOTE ;--------------------------------------------------------------------- CALL D0.5S CALL LCD_INI CALL D1S movlw d'0' movwf DISPLAY1 movlw d'13' movwf DISPLAY2 movlw d'250' MOVWF vmsvar call DISPLAY ; call D1S ;delay checking ;aaa bsf PORTA,0 ; call D1MS ; bcf PORTA,0 ; call D1MS ; goto aaa ;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- call clreeprom movlw d'16' movwf temp movlw inbuff movwf FSR clrloop ; movf temp,w ; movwf addi ; ; movlw h'fe' ; movwf edata ; ; call dwrite ; call D1MS ; ; incf FSR,F ; incf temp,f ; ; movf temp,w ; sublw h'ff' ; ; btfss STATUS,Z movlw h'fe' MOVWF INDF INCF FSR,F decfsz temp goto clrloop call LCD_CLR a call header call LCD_NX clrf keycnt ; call D1MS ; call D1MS ; call D1MS call addaline ; bcf keystatus1,0 call LCD_CLR movlw h'FF' subwf lcnt,w btfss STATUS,Z goto aa movlw d'15' movwf lcnt goto a aa movlw d'16' subwf lcnt,w btfsc STATUS,Z clrf lcnt goto a ;--------------------------------------------------------------------- ;receive program line ;--------------------------------------------------------------------- ;lcnt has some problems addaline call recallmem kbb call keyboard movf keycnt,w sublw d'17' btfss STATUS,Z goto kbb1 incf lcnt,f return ; decf keycnt,f ; goto kbb ; goto showLshift ; bcf PORTA,1 kbb1 btfss keystatus,7 goto showuparrow movf ps2data,w sublw h'12' btfss STATUS,Z goto $+3 decf keycnt goto Ldisable movf ps2data,w sublw h'59' btfsc STATUS,Z goto showuparrow bcf keystatus,7 ; bcf keystatus,1 call D1MS decf keycnt goto kbb showuparrow btfss keystatus,6 goto showdnarrow movf ps2data,w sublw h'75' btfss STATUS,Z goto showdnarrow decf lcnt,f bcf keystatus1,2 bcf keystatus1,3 return showdnarrow btfss keystatus,6 goto showlfarrow movf ps2data,w sublw h'72' btfss STATUS,Z goto showlfarrow incf lcnt,f bcf keystatus1,2 bcf keystatus1,3 return showlfarrow btfsc keystatus1,0 goto show call LCD_CLR call sheader call LCD_NX bsf keystatus1,0 ; movlw d'16' ; movwf temp ; goto showent ; movf keycnt,w call recallmem incf keycnt,f show btfss keystatus,6 goto showrgarrow movf ps2data,w sublw h'6b' btfss STATUS,Z goto showrgarrow ; btfsc keystatus1,2 decf keycnt,f decf keycnt,f MOVLW B'11000000' addwf keycnt,w CALL LCD_I ; btfsc keystatus1,2 ; decF FSR,F decF FSR,F bsf keystatus1,2 goto kbb showrgarrow btfss keystatus,6 goto showenter movf ps2data,w sublw h'74' btfss STATUS,Z goto showenter ; btfss keystatus1,3 ; incf keycnt,f ; incf keycnt,f MOVLW B'11000000' addwf keycnt,w CALL LCD_I ; btfss keystatus1,2 ; decF FSR,F incF FSR,F bsf keystatus1,3 ; MOVLW B'11000000' ; addwf keycnt,w ; ; CALL LCD_I ; INCF FSR,F goto kbb showenter ; btfsc keystatus1,0 ; goto showent ; ; call LCD_CLR ; call sheader ; call LCD_NX ; ; bsf keystatus1,0 ; ; movlw d'16' ; movwf temp ; goto showent ; movf keycnt,w ; call recallmem showent movf ps2data,w sublw h'5a' btfss STATUS,Z goto showdel bcf keystatus1,0 ; clrf temp decf keycnt ; call LCD_CLR ; movf lcnt,w ; call NUM ; movwf LCD_DATA ; call LCD_W ; call D1S call LCD_CLR call header call LCD_NX call writemem call D1MS ;impt to keep enough delay here call D1MS call D1MS call D1MS call D1MS ;impt call recallmem call D1MS ;impt call D1MS call D1MS ; incf lcnt ; return bcf keystatus1,1 ; bcf keystatus1,2 bcf keystatus1,3 goto kbb showdel movf ps2data,w sublw h'71' btfss STATUS,Z goto showbackspace ; movlw h'fe' ; movwf LCD_DATA ; call LCD_W ; incf keycnt,f ; decf FSR,F decf keycnt,f movf keycnt,w movwf olddkey incf FSR,F ; movf LCD_DATA,w ; MOVWF INDF ; CALL D1MS lpdel2 movf INDF,w decf FSR,F movwf INDF movwf LCD_DATA call LCD_W incf FSR,F incf FSR,F incf keycnt,f movf keycnt,w sublw d'15' btfss STATUS,Z goto lpdel2 ; movlw b'1010011' ; movwf INDF movf olddkey,w movwf keycnt MOVLW inbuff MOVWF FSR lpdel3 incf FSR,f decfsz keycnt goto lpdel3 goto lpdel ; movf olddkey,w ; movwf keycnt ; ;lpbksp movf INDF,w ; movwf LCD_DATA ; call LCD_W ; INCF FSR,F ; ; incf keycnt,f ; ; movf keycnt,w ; sublw d'16' ; btfss STATUS,Z ; goto lpbksp ; movlw h'fe' ; movwf LCD_DATA ; ; call LCD_W ; ; decf FSR,F ; ; movf LCD_DATA,w ; MOVWF INDF ; CALL D1MS ; movf olddkey,w ; movwf keycnt ; ; MOVLW inbuff ; MOVWF FSR ;lpbksp1 incf FSR,f ; decfsz keycnt ; goto lpbksp1 lpdel ; movf olddkey,w ; movwf keycnt ; ; MOVLW B'11000000' ; addwf keycnt,w ; ; CALL LCD_I ; CALL D1MS movf olddkey,w movwf keycnt ; decf keycnt,w MOVLW B'11000000' addwf keycnt,w CALL LCD_I CALL D1MS bcf keystatus1,1 ; bcf keystatus1,2 bcf keystatus1,3 goto kbb showbackspace movf ps2data,w sublw h'66' btfss STATUS,Z goto showLshift ; btfsc keystatus1,1 decf keycnt,f decf keycnt,f movf keycnt,w movwf olddkey MOVLW B'11000000' addwf keycnt,w bsf keystatus1,1 CALL LCD_I CALL D1MS ; movf keycnt,w ; movwf olddkey ; movf INDF,w ; decf FSR,f ; ; movwf LCD_DATA ; call LCD_W ; movlw b'10100000' ; movwf INDF ; deCF FSR,F lpbksp2 movf INDF,w decf FSR,F movwf INDF movwf LCD_DATA call LCD_W incf FSR,F incf FSR,F incf keycnt,f movf keycnt,w sublw d'15' btfss STATUS,Z goto lpbksp2 ; movlw b'1010011' ; movwf INDF movf olddkey,w movwf keycnt MOVLW inbuff MOVWF FSR lpbksp3 incf FSR,f decfsz keycnt goto lpbksp3 goto lp ; movf olddkey,w ; movwf keycnt ; ;lpbksp movf INDF,w ; movwf LCD_DATA ; call LCD_W ; INCF FSR,F ; ; incf keycnt,f ; ; movf keycnt,w ; sublw d'16' ; btfss STATUS,Z ; goto lpbksp ; movlw h'fe' ; movwf LCD_DATA ; ; call LCD_W ; ; decf FSR,F ; ; movf LCD_DATA,w ; MOVWF INDF ; CALL D1MS ; movf olddkey,w ; movwf keycnt ; ; MOVLW inbuff ; MOVWF FSR ;lpbksp1 incf FSR,f ; decfsz keycnt ; goto lpbksp1 lp movf olddkey,w movwf keycnt MOVLW B'11000000' addwf keycnt,w CALL LCD_I CALL D1MS bcf keystatus1,3 ; bcf keystatus1,2 goto kbb showLshift movf ps2data,w sublw h'12' btfss STATUS,Z goto showRshift decf keycnt ; decf keycnt call D1MS call D1MS GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 btfsc keystatus,7 goto Ldisable bsf keystatus,0 l call skeyboard decf keycnt btfss keystatus,7 goto $+3 incf keycnt goto Ldisable incf keycnt movf ps2data,w sublw h'12' btfss STATUS,Z goto showCchar decf keycnt goto l Ldisable bcf keystatus,0 bcf keystatus,7 bcf keystatus1,1 bcf keystatus1,2 bcf keystatus1,3 call D1MS ; bcf PORTA,0 goto kbb showRshift movf ps2data,w sublw h'59' btfss STATUS,Z goto keycheck decf keycnt call D1MS call D1MS GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 btfsc keystatus,7 goto Rdisable bsf keystatus,1 r call skeyboard decf keycnt btfss keystatus,7 goto $+3 incf keycnt goto Rdisable incf keycnt movf ps2data,w sublw h'59' btfss STATUS,Z goto showCchar decf keycnt goto r Rdisable bcf keystatus,1 bcf keystatus,7 bcf keystatus1,1 ; bcf keystatus1,2 bcf keystatus1,3 call D1MS ; bcf PORTA,0 goto kbb keycheck btfsc keystatus,0 goto showCchar btfsc keystatus,1 goto showCchar showSchar movf ps2data,w call charS movwf LCD_DATA MOVWF INDF INCF FSR,F call LCD_W ; call LCD_CLR ; movf lcnt,w ; call NUM ; movwf LCD_DATA ; call LCD_W ; call D1S ; call D1MS ; movf ps2data,w ; movf LCD_DATA,w bcf keystatus1,1 ; bcf keystatus1,2 bcf keystatus1,3 goto kbb showCchar movf ps2data,w call charC movwf LCD_DATA call LCD_W ; call D1MS ; movf ps2data,w movf LCD_DATA,w MOVWF INDF INCF FSR,F bcf keystatus1,1 bcf keystatus1,2 bcf keystatus1,3 goto kbb ;showerr movlw b'00111111' ; movwf LCD_DATA ; call LCD_W ; call D1MS ; goto lcdshow ;lcdshow call LCD_W ; call D0.5S ; call D1MS ; movf ps2data,w ; movwf temp ; movlw d'8' ; movwf counter ;loop btfss temp,7 ; goto show00 ; movlw b'00110001' ;show 1 ; movwf LCD_DATA ; call LCD_W ; goto lp ;show00 movlw b'00110000' ;show 0 ; movwf LCD_DATA ; call LCD_W ;lp call D1MS ; rlf temp,f ; decfsz counter ; goto loop ; call D1S ;--------------------------------------------------------------------- ;receive keyboard input ;--------------------------------------------------------------------- keyboard movlw d'8' movwf counter btfss dpin goto $-1 btfsc clkpin goto $-1 btfss clkpin goto $-1 kb btfsc clkpin goto $-1 GOTO $+1 GOTO $+1 bcf STATUS,C btfsc dpin bsf STATUS,C rrf ps2data,f btfss clkpin goto $-1 decfsz counter goto kb movf ps2data,w sublw h'f0' btfss STATUS,Z goto chke0 bsf keystatus,7 goto kskip chke0 movf ps2data,w sublw h'e0' btfss STATUS,Z goto parity bsf keystatus,6 kskip btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 movlw d'9' movwf counter goto kb parity btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 ; bcf temp1,0 bcf temp1,0 btfss dpin goto parity bsf temp1,0 movf ps2data,w movwf temp SWAPF temp, W XORWF temp, F RRF temp, W XORWF temp, F BTFSC temp, 2 INCF temp, F movf temp,w subwf temp1 btfss STATUS,Z goto kbok movlw b'11101111' movwf LCD_DATA call LCD_W call D1MS kbok ; btfss keystatus,7 ; goto kbend ; ; movf ps2data,w ; sublw h'12' ; btfss STATUS,Z ; goto keyboard ; goto kbend ; movf ps2data,w ; sublw h'59' ; btfss STATUS,Z ; goto keyboard kbend btfss dpin goto $-1 ; btfss clkpin ; goto $-1 incf keycnt,f return ;--------------------------------------------------------------------- skeyboard movlw d'8' movwf counter btfsc clkpin goto $-1 btfsc dpin goto $-1 btfss clkpin goto $-1 kbbb btfsc clkpin goto $-1 GOTO $+1 GOTO $+1 bcf STATUS,C btfsc dpin bsf STATUS,C rrf ps2data,f btfss clkpin goto $-1 decfsz counter goto kbbb movf ps2data,w sublw h'f0' btfss STATUS,Z goto kbbbb bsf keystatus,7 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 call D1MS call D1MS call D1MS call D1MS return ; goto kbbbb skbfchk movf ps2data,w sublw h'e0' btfss STATUS,Z goto skbfchk bsf keystatus,6 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 call D1MS call D1MS call D1MS call D1MS return ; goto kbbbb kbbbb btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfsc clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 btfss clkpin ;parity bit goto $-1 GOTO $+1 GOTO $+1 incf keycnt,f return ;--------------------------------------------------------------------- ;character table ;--------------------------------------------------------------------- Schartb MOVWF PCL DT " q1 zsaw2 cxde43 vftr5 nbhgy6 mju78 ,kio09 ./l;p- ` [= ] 1 47 0.2568 +3-*9" Cchartb MOVWF PCL DT " Q! ZSAW@ CXDE$# VFTR% NBHGY^ MJU&* ?L:P_ ~ {+ } 1 47 0.2568 +3-*9" ;--------------------------------------------------------------------- ;SHOW NUM ;--------------------------------------------------------------------- charC MOVWF POINTER INCF POINTER MOVLW LOW Cchartb ADDWF POINTER MOVLW HIGH Cchartb BTFSC STATUS,C ADDLW H'01' MOVWF PCLATH MOVF POINTER,W CALL Cchartb RETURN charS MOVWF POINTER INCF POINTER MOVLW LOW Schartb ADDWF POINTER MOVLW HIGH Schartb BTFSC STATUS,C ADDLW H'01' MOVWF PCLATH MOVF POINTER,W CALL Schartb RETURN ;--------------------------------------------------------------------- ;MESSAGE ;--------------------------------------------------------------------- header movlw d'24' movwf DISPLAY1 movlw d'1' MOVWF vmsvar call SDISPLAY ;;;;;;;;;;;;; 29/8 need to add double digits movlw d'10' subwf lcnt,w btfss STATUS,C goto headerS movlw d'1' CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS movlw d'10' subwf lcnt,w CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS goto headerend headerS movlw d'18' CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS movf lcnt,w CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS headerend movlw d'33' movwf DISPLAY1 movlw d'1' MOVWF vmsvar movlw d'2' call SDISPLAY return ;--------------------------------------------------------------------- ;recall old memeory ;--------------------------------------------------------------------- recallmem movf lcnt,w movwf mem0 bcf STATUS,C rlf mem0,f ;16 characters so need to multiply rlf mem0,f rlf mem0,f rlf mem0,f movf lcnt,w movwf mem1 incf mem1,f bcf STATUS,C rlf mem1,f rlf mem1,f rlf mem1,f rlf mem1,f decf mem1,f clrf keycnt clrf oldkey MOVLW inbuff MOVWF FSR erloop1 movf mem0,w movwf addi call dread movf edata,w movwf LCD_DATA call LCD_W ; call D1MS movf edata,w MOVWF INDF INCF FSR,F incf oldkey,f movf edata,w sublw h'fe' btfsc STATUS,Z goto erjmp movf oldkey,w movwf keycnt erjmp incf mem0,f movf mem0,w subwf mem1,w btfss STATUS,Z ; decfsz temp goto erloop1 ; decf keycnt MOVLW inbuff addwf keycnt,w MOVWF FSR ; incf keycnt MOVLW B'11000000' addwf keycnt,w CALL LCD_I CALL D1MS ; MOVLW inbuff ; MOVWF FSR return ;--------------------------------------------------------------------- ;MESSAGE ;--------------------------------------------------------------------- writemem movf lcnt,w movwf mem0 bcf STATUS,C rlf mem0,f rlf mem0,f rlf mem0,f rlf mem0,f movf lcnt,w movwf mem1 incf mem1,f bcf STATUS,C rlf mem1,f rlf mem1,f rlf mem1,f rlf mem1,f decf mem1,f clrf keycnt clrf oldkey MOVLW inbuff MOVWF FSR ewloop movf mem0,w movwf addi movf INDF,w movwf edata ; call page1 ; page1 ; BCF PCLATH,4 ; BSF PCLATH,3 call dwrite call D1MS incf FSR,F incf mem0,f movf mem0,w subwf mem1,w btfss STATUS,Z goto ewloop MOVLW inbuff MOVWF FSR return ;--------------------------------------------------------------------- ;MESSAGE ;--------------------------------------------------------------------- clreeprom clrf temp clrloop1 movf temp,w movwf addi movlw h'fe' movwf edata ; call page1 ; page1 ; BCF PCLATH,4 ; BSF PCLATH,3 call dwrite call D1MS call D1MS call D1MS call D1MS incf temp,f movf temp,w sublw h'ff' btfss STATUS,Z goto clrloop1 call D1MS return ;--------------------------------------------------------------------- ;MESSAGE ;--------------------------------------------------------------------- sheader movlw d'40' movwf DISPLAY1 movlw d'1' MOVWF vmsvar call SDISPLAY ;;;;;;;;;;;;; 29/8 need to add double digits movlw d'10' subwf lcnt,w btfss STATUS,C goto sheaderS movlw d'1' CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS movlw d'10' subwf lcnt,w CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS goto sheaderend sheaderS movlw d'18' CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS movf lcnt,w CALL NUM MOVWF LCD_DATA CALL LCD_W call D1MS sheaderend movlw d'49' movwf DISPLAY1 movlw d'2' MOVWF vmsvar call SDISPLAY return ;--------------------------------------------------------------------- ;NUMBER ;--------------------------------------------------------------------- NO MOVWF PCL DT "0123456789*#ASDC+- QWERT" ;--------------------------------------------------------------------- ;SHOW NUM ;--------------------------------------------------------------------- NUM MOVWF POINTER INCF POINTER MOVLW LOW NO ADDWF POINTER MOVLW HIGH NO BTFSC STATUS,C ADDLW H'01' MOVWF PCLATH MOVF POINTER,W CALL NO RETURN ;--------------------------------------------------------------------- ;MESSAGE ;--------------------------------------------------------------------- MESS MOVWF PCL DT "PROGRAMMABLE" RETLW H'00' ;0 DT "CONTROLLER" RETLW H'00' ;13 DT ">>>>> X-" RETLW H'00' ;24 DT " <<<<<" RETLW H'00' ;33 DT "<<<<< X-" RETLW H'00' ;40 DT " >>>>>" RETLW H'00' ;49 DT "DIAMETER:" RETLW H'00' ;67 ;157 ;--------------------------------------------------------------------- ;DISPLAY ;--------------------------------------------------------------------- DISPLAY ; MOVWF vmsvar ; MOVLW H'01' ; CALL LCD_I ; ; MOVLW H'02' ; CALL LCD_I MOVF DISPLAY1,W MOVWF CHAR_CT movlw d'1' movwf vmsvar CALL WEL_NOTE ; CALL D0.5S call LCD_NX ; MOVLW H'C0' ; CALL LCD_I ; ; MOVLW B'00001110' ; CALL LCD_I MOVF DISPLAY2,W MOVWF CHAR_CT movlw d'1' movwf vmsvar CALL WEL_NOTE ; CALL D0.5S ; MOVLW H'01' ; CALL LCD_I ; MOVLW H'02' ; CALL LCD_I RETURN ;--------------------------------------------------------------------- WEL_NOTE MOVF CHAR_CT,W MOVWF POINTER LOOP_LCD MOVF CHAR_CT,W MOVWF POINTER INCF POINTER MOVF POINTER,W MOVWF CHAR_CT MOVLW LOW MESS ADDWF POINTER MOVLW HIGH MESS BTFSC STATUS,C ADDLW H'01' MOVWF PCLATH MOVF POINTER,W CALL MESS IORLW H'00' BTFSC STATUS,Z GOTO LCD_END MOVWF LCD_DATA CALL LCD_W ; call D1MS CALL DMS_V GOTO LOOP_LCD LCD_END RETURN ;--------------------------------------------------------------------- ;single line display ;--------------------------------------------------------------------- SDISPLAY ; MOVWF vmsvar MOVf DISPLAY1,w MOVWF CHAR_CT CALL WEL_NOTE CALL DMS_V ; call D1MS RETURN ;--------------------------------------------------------------------- ;ASK MESSAGE ;--------------------------------------------------------------------- #if 0 MESS_ASK ADDWF PCL,F DT "PLEASE ENTER" RETLW H'00' ;0 DT "DIAMETER" RETLW H'00' ;13 DT "PLEASE ENTER" RETLW H'00' ;22 DT "RPM" RETLW H'00' ;35 DT "*************" RETLW H'00' ;47 #endif ;--------------------------------------------------------------------- ;CONVERT THE STRING ;--------------------------------------------------------------------- #if 0 drive ; bsf cwpin btfss stepstatus,0 goto fwd goto rev fwd bsf dirpin lpfwd bcf pulspin call dstep bsf pulspin call dstep decfsz rcntl goto lpfwd movlw h'ff' movwf rcntl decfsz rcnth goto lpfwd return rev bcf dirpin lprev bcf pulspin call dstep bsf pulspin call dstep decfsz rcntl goto lprev movlw h'ff' movwf rcntl decfsz rcnth goto lprev return #endif ;--------------------------------------------------------------------- ;CONVERT THE STRING ;--------------------------------------------------------------------- CONVERT CLRF IN11 ;;;;;;;;;;;;;;;;;;; ;to add minus sign ;;;;;;;;;;;;;;;;;;;;;;;; ; incf FSR,f ; incf keycnt,f clrf rcntl clrf rcnth CONMINUS incf FSR,f incf keycnt,f movf INDF,w andlw b'11110000' sublw b'00110000' btfss STATUS,Z goto CONCHK movf INDF,w andlw b'00001111' movwf IN1 incf FSR,f ;coding n lost man..... incf keycnt,f movf INDF,w andlw b'11110000' sublw b'00110000' btfss STATUS,Z goto CON1 movf INDF,w andlw b'00001111' movwf IN2 incf FSR,f incf keycnt,f movf INDF,w andlw b'11110000' sublw b'00110000' btfss STATUS,Z goto CON2 movf INDF,w andlw b'00001111' movwf IN3 incf FSR,f incf keycnt,f movf INDF,w andlw b'11110000' sublw b'00110000' btfss STATUS,Z goto CON3 movf INDF,w andlw b'00001111' movwf IN4 goto CON CONCHK movf INDF,w sublw b'00101101' btfss STATUS,Z goto CONSKIP bsf IN11,7 goto CONMINUS CONSKIP CLRF IN1 CLRF IN2 CLRF IN3 CLRF IN4 CLRF CRESULT CLRF CRESULT11 movlw b'11111111' movwf LCD_DATA call LCD_W call D1S GOTO CONEND ; GOTO DIG CON1 MOVF IN1,W MOVWF IN4 CLRF IN3 CLRF IN2 CLRF IN1 ; CLRF IN11 ; GOTO CONN2 GOTO CONN2 CON2 MOVF IN1,W MOVWF IN3 MOVF IN2,W MOVWF IN4 CLRF IN2 CLRF IN1 ; CLRF IN11 ; goto CONN1 goto CONN1 CON3 MOVF IN3,W movwF IN4 MOVF IN2,W MOVWF IN3 MOVF IN1,W MOVWF IN2 CLRF IN1 ; CLRF IN11 goto CONN CON MOVF IN1,W MOVWF MUL16LL clrf MUL16LH MOVLW b'00000011' movwf MUL16HH MOVLW b'11101000' movwf MUL16HL CALL MUL16 MOVF PROD16LL,W MOVWF IN1 MOVF PROD16LH,W MOVWF IN11 CONN MOVF IN2,W MOVWF MUL1 MOVLW D'100' MOVWF MUL2 CALL MUL8 MOVF PRODL,W addWF IN1,f BTFSC STATUS,C INCF IN11 MOVF PRODH,W addWF IN11,f CONN1 MOVF IN3,W MOVWF MUL1 MOVLW D'10' MOVWF MUL2 CALL MUL8 MOVF PRODL,W addWF IN1,f BTFSC STATUS,C INCF IN11 CONN2 MOVF IN4,W ADDWF IN1,F BTFSC STATUS,C INCF IN11 btfss IN11,7 goto CONPLUS bcf IN11,7 comf IN11,f comf IN1,f incf IN1,f btfsc STATUS,C incf IN11,f CONPLUS ; MOVWF CRESULT ; movlw b'00111111' ; movwf LCD_DATA ; call LCD_W ; call D1S ; call D1S ; call LCD_CLR MOVF IN11,W movwf rcnth ; CALL DEBUG MOVF IN1,W ; addlw b'00100000' movwf rcntl ; CALL DEBUG ; movlw b'00111111' ; MOVWF CRESULT11 ; movwf LCD_DATA ; call LCD_W ; call D1S ; call D1S ; call D1S ; call D1S ; call D1S ; call D1S ; ; call LCD_CLR ; BTFSC STATUS,C ; CALL SERROR ; GOTO CONVERT_END CONEND RETURN ;--------------------------------------------------------------------- ;DEBUG CODE ;--------------------------------------------------------------------- #if 1 DEBUG movwf temp movlw d'8' movwf counter loopDB btfss temp,7 goto show00 movlw b'00110001' ;show 1 movwf LCD_DATA call LCD_W goto lpDebug show00 movlw b'00110000' ;show 0 movwf LCD_DATA call LCD_W lpDebug call D1MS BCF STATUS,C rlf temp,f decfsz counter goto loopDB call D1S RETURN #endif ;--------------------------------------------------------------------- ;8,16 bit multiplication from PICLIST ;--------------------------------------------------------------------- ;***************************************************************************************** ; Unsigned multiply routine ; Multiplies of any size can easily be made from the macros - for this code, only MUL16X16 ; is made ; ; The approach here is linear code for speed at the expense of RAM and registers ; Adapted from : http://www.piclist.org/techref/microchip/math/mul/8x8u.htm ;***************************************************************************************** ; Add16AB macro - add AH:AL to BH:BL, result goes to BH:BL Add16AB MACRO AH,AL,BH,BL movfw AL addwf BL,f movfw AH btfsc STATUS,C incfsz AH,w addwf BH,f ENDM ;***************************************************************************************** ; Macro for adding & right shifting - used once per bit by mulmac mult MACRO bit,A,H,L ;A=multiplier,H:L=result, other arg in W btfsc A,bit addwf H,f rrf H,f rrf L,f ENDM ; End of macro ;***************************************************************************************** ; 8x8-->16 multiply macro A * B --> H:L ; Invokes mult macro above mulmac MACRO A,B,H,L ; H:L = A*B clrf H clrf L movf B,W ; move the multiplicand to W reg. bcf STATUS,C ; Clear the carry bit in the status Reg. mult 0,A,H,L mult 1,A,H,L mult 2,A,H,L mult 3,A,H,L mult 4,A,H,L mult 5,A,H,L mult 6,A,H,L mult 7,A,H,L ENDM ; ; NOEXPAND ;***************************************************************************************** ; MUL16x16U ; AARG0:1 * BARG0:1 --> AARG0:3 ; Invokes the three macros above ; 164 prog words, 168 inst cycles, 10 registers (6 for call/return arguments + 4) ; Uses TEMP0:3 also. BARG0:1 unchanged on return ;***************************************************************************************** MUL16 ; 32 bit result is first calculated into T0:T1:A2:A3 ; When done, T0:1 is moved to A0:1 so the final result is in A0:3 ; Register names can be changed at will, and any register can be located ; anywhere - order is not important. mulmac MUL16HH, MUL16LH, TEMP0, TEMP1 ;T0:1 <--A0*B0 mulmac MUL16HL, MUL16LL, PROD16LH, PROD16LL ;A2:3 <--A1*B1 mulmac MUL16HL, MUL16LH, TEMP2, TEMP3 ;T2:3 <--A1*B0 Add16AB TEMP2, TEMP3, TEMP1, PROD16LH ; Add T2:3 to T1:A2, carry into T0 btfsc STATUS,C ; nb: this relies on the _C bit being incf TEMP0,f ; correct after the Add16AB macro mulmac MUL16HH, MUL16LL, TEMP2, TEMP3 ;T2:3 <--A0*B1 Add16AB TEMP2, TEMP3, TEMP1, PROD16LH ; Add T2:3 to T1:A2, carry into T0 btfsc STATUS,C incf TEMP0,f movfw TEMP1 ;Move T0:1 to A0:1 movwf PROD16HL ;to finish movfw TEMP0 movwf PROD16HH return ;--------------------------------------------------------------------- ;8 bit multiplication ;--------------------------------------------------------------------- MUL8 mulmac MUL1,MUL2,PRODH,PRODL return ;--------------------------------------------------------------------- ;8 bit multiplication ;--------------------------------------------------------------------- ;MUL8 CLRF PRODL ; CLRF PRODH ; CLRF TMPMULH ;MUL_LP ; MOVF MUL1,W ; ADDWF PRODL ; BTFSC STATUS,C ; INCF PRODH ; DECFSZ MUL2 ; GOTO MUL_LP ; RETURN ;--------------------------------------------------------------------- ;16 BIT MULTIPLICATION ;--------------------------------------------------------------------- ;MUL16 CLRF PROD16HH ; CLRF PROD16HL ; CLRF PROD16LH ; CLRF PROD16LL ;MUL16LP ; MOVF MUL16HL,W ; MOVWF MUL1 ; MOVF MUL16LL,W ; MOVWF MUL2 ; CALL MUL8 ; MOVF PRODL,W ; ADDWF PROD16LL,F ; MOVF PRODH,W ; ADDWF PROD16LH,F ; ; ; MOVF MUL16HL,W ; MOVWF MUL1 ; MOVF MUL16LH,W ; MOVWF MUL2 ; CALL MUL8 ; ; MOVF PRODL,W ; ADDWF PROD16LH,F ; MOVF PRODH,W ; ADDWF PROD16HL,F ; ; MOVF MUL16HH,W ; MOVWF MUL1 ; MOVF MUL16LL,W ; MOVWF MUL2 ; CALL MUL8 ; ; MOVF PRODL,W ; ADDWF PROD16LH,F ; BTFSC STATUS,C ; INCF PROD16HL ; ; MOVF PRODH,W ; ADDWF PROD16HL,F ; BTFSC STATUS,C ; INCF PROD16HH ; MOVF MUL16HH,W ; MOVWF MUL1 ; MOVF MUL16LH,W ; MOVWF MUL2 ; CALL MUL8 ; ; MOVF PRODL,W ; ADDWF PROD16HL,F ; BTFSC STATUS,C ; INCF PROD16HH ; MOVF PRODH,W ; ADDWF PROD16HH,F ; ; RETURN ;--------------------------------------------------------------------- ;eprom read ;--------------------------------------------------------------------- dread ; BSF STATUS, RP1 ; ; BCF STATUS, RP0 ;Bank 2 ; MOVF addi, W ;Write address ; MOVLW h'01' ;Write address clrf STATUS MOVF addi, W ;Data to BSF STATUS, RP1 ; MOVWF EEADR ;to read from BSF STATUS, RP0 ;Bank 3 BCF EECON1, EEPGD ;Point to Data memory BSF EECON1, RD ;Start read operation BCF STATUS, RP0 ;Bank 2 MOVF EEDATA, W ;W = EEDATA clrf STATUS movwf edata return ;--------------------------------------------------------------------- ;LCD INITIALIZATION ;--------------------------------------------------------------------- LCD_INI MOVLW H'06' CALL LCD_I CALL D1MS MOVLW H'0E' CALL LCD_I CALL D1MS MOVLW H'14' CALL LCD_I CALL D1MS MOVLW H'38' CALL LCD_I CALL D1MS MOVLW H'01' CALL LCD_I CALL D1MS MOVLW H'02' CALL LCD_I CALL D1MS RETURN ;--------------------------------------------------------------------- LCD_W BSF lcdrs BSF lcden MOVF LCD_DATA,w MOVWF lcdport CALL D1MS BCF lcden BCF lcdrs ; BSF PORTE,0 ; BSF PORTE,1 ; MOVF LCD_DATA ; MOVWF PORTD ; CALL D1MS ; BCF PORTE,1 ; BCF PORTE,0 RETURN ;--------------------------------------------------------------------- LCD_I BCF lcdrs BSF lcden MOVWF lcdport CALL D1MS BCF lcden ; BCF PORTE,0 ; BSF PORTE,1 ; MOVWF PORTD ; CALL D1MS ; BCF PORTE,1 RETURN ;--------------------------------------------------------------------- LCD_CLR MOVLW H'01' CALL LCD_I CALL D1MS MOVLW H'02' CALL LCD_I CALL D1MS RETURN ;--------------------------------------------------------------------- LCD_NX MOVLW H'C0' CALL LCD_I call D1MS MOVLW B'00001110' CALL LCD_I call D1MS RETURN ;--------------------------------------------------------------------------------------------- ; DELAY: ;--------------------------------------------------------------------------------------------- D1MS MOVLW D'250' ;CHANGE TO 250 FOR 20MHz MOVWF d1msvar LOOPS2 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 GOTO $+1 DECFSZ d1msvar GOTO LOOPS2 RETURN D0.5S MOVLW D'125' MOVWF d.5msvar LOOPS1 CALL D1MS CALL D1MS CALL D1MS CALL D1MS DECFSZ d.5msvar GOTO LOOPS1 RETURN D1S MOVLW D'250' MOVWF d1svar LOOPM CALL D1MS CALL D1MS CALL D1MS CALL D1MS DECFSZ d1svar GOTO LOOPM RETURN DMS_V MOVF vmsvar,W MOVWF VMSD LOOPVM CALL D1MS DECFSZ VMSD GOTO LOOPVM RETURN DS_V LOOPVS CALL D1S DECFSZ VS_D GOTO LOOPVS RETURN dstep movlw d'25' movwf vmsvar loopstep NOP decfsz vmsvar goto loopstep return ;--------------------------------------------------------------------- page1 macro BCF PCLATH,4 BSF PCLATH,3 endm ; return ;--------------------------------------------------------------------- page0 BCF PCLATH,4 BCF PCLATH,3 return ;--------------------------------------------------------------------- ;Bank 1 code ;--------------------------------------------------------------------- ; ORG H'800' ;--------------------------------------------------------------------- ;eprom write ;--------------------------------------------------------------------- dwrite clrf STATUS BSF STATUS, RP1 ; BSF STATUS, RP0 ;Bank 3 BTFSC EECON1, WR ;Wait for GOTO $-1 ;write to finish clrf STATUS MOVf addi,w ;Address to BsF STATUS, RP1 ;Bank 2 MOVWF EEADR ;write to clrf STATUS MOVF edata, W ;Data to ; BCF STATUS, RP0 ;Bank 2 BSF STATUS, RP1 ; MOVWF EEDATA ;write BSF STATUS, RP0 ;Bank 3 BCF EECON1, EEPGD ;Point to Data memory BSF EECON1, WREN ;Enable writes ;Only disable interrupts ; BCF INTCON, GIE ;if already enabled, ;otherwise discard MOVLW 0x55 ;Write 55h to MOVWF EECON2 ;EECON2 MOVLW 0xAA ;Write AAh to MOVWF EECON2 ;EECON2 BSF EECON1, WR ;Start write operation ;Only enable interrupts ; BSF INTCON, GIE ;if using interrupts, ;otherwise discard BCF EECON1, WREN ;Disable writes CLRF STATUS return ;--------------------------------------------------------------------- bitmask movwf index ;save index 0..7 ; incf index,f ;can remove index in case of memory shortage clrf temp2 ;initial mask bsf STATUS,C ; movlw b'00000001' ; movwf temp2 bitmask_lp rlf temp2,f ;shift mask bit decfsz index ;decrement index goto bitmask_lp ;loop if not finish movf temp2,w return ;exit ;--------------------------------------------------------------------- END