;------------------------------------------------------------------------------- ; FILE: Synchronous Serial ; AUTH: Ed's Projects ; DATE: 22/08/2016 ; DESC: Bit-banging serial data to and from an external EEPROM ;------------------------------------------------------------------------------- LIST P=16F628A, R=DEC ; All numbers Decimal format unless otherwise stated. include ; Define configurations, registers, etc. __config _CP_OFF & _CPD_OFF & _LVP_OFF & _BOREN_ON & _MCLRE_OFF & _PWRTE_ON & _WDTE_OFF & _HS_OSC ;------------------------------------------------------------------------------- ;----------------------------- Port Definitions ------------------------------ ;------------------------------------------------------------------------------- ; PortA - Output - RA1 - Pin 18 - Serial Clock Out ; PortA - Output - RA0 - Pin 17 - Serial Data In/Out ; PortB - Output - RB2 - Pin 8 - LCD serial Output ; PortB - Input - RB1 - Pin 7 - Keypad serial Input ;------------------------------------------------------------------------------- ;-------------------------------- Variables ---------------------------------- ;------------------------------------------------------------------------------- cblock h'20' temp temp3 temp4 Command ; Command and address Adr1 ; Address 1 EEPROM Adr2 ; Address 2 EEPROM Datnum ; Number of data bytes datatemp ; Temporary bytes to be sent or received offset ; PCL offset lookup table temp2 cmdind ; Command Indicator cmdtemp ; Command Contents tempdig ; Temporary digit converter ackerr ; No acknowledge endc ;------------------------------------------------------------------------------- ;----------------------------- Define Symbols -------------------------------- ;------------------------------------------------------------------------------- #define CLK PORTA, 1 #define SDA PORTA, 0 ;------------------------------------------------------------------------------- ;------------------------------- Program Code -------------------------------- ;------------------------------------------------------------------------------- ORG 0 ;------------------------------------------------------------------------------- ;-------------------------- Initialisation of Ports -------------------------- ;------------------------------------------------------------------------------- Init bsf STATUS,RP0 bcf STATUS,RP1 ; Bank 1 Selected clrf VRCON ; Set Vref to off movlw b'00000110' movwf TRISB clrf TRISA bcf STATUS,RP0 ; Bank 0 Selected movlw d'7' movwf CMCON ; Turn off comparators clrf PORTA clrf PORTB ;------------------------------------------------------------------------------- ;-------------------------- Serial Initialisation ---------------------------- ;------------------------------------------------------------------------------- bsf STATUS, RP0 ; Bank 1 selected bsf TXSTA, BRGH ; Set high baud rate movlw d'64' ; 19200 baud rate at 4MHz movwf SPBRG bcf TXSTA, SYNC ; Set to asynchronous mode bsf TXSTA, TXEN ; Enable Transmit bcf STATUS, RP0 ; Bank 0 Selected bsf RCSTA, SPEN ; Enable Serial Port bsf RCSTA, CREN ; Turns on receive movf RCREG, w movf RCREG, w movf RCREG, w ;------------------------------------------------------------------------------- ;-------------------------------- Initialisaton ------------------------------ ;------------------------------------------------------------------------------- bsf SDA movlw d'8' call delay1 ; Wait 2 second movlw d'5' movwf temp Initprot bsf CLK goto $+1 nop bcf CLK nop decfsz temp, f goto Initprot movlw d'50' movwf FSR movlw d'1' movwf temp meow movf temp, w movwf INDF incf FSR, f incf temp, f movf FSR, w xorlw d'112' btfss STATUS, Z goto meow ;------------------------------------------------------------------------------- ;-------------------------------- Main Program ------------------------------- ;------------------------------------------------------------------------------- Start clrf ackerr call chr1 ; Read command and chip address call chr2 ; Read address 1 and 2 call chr3 ; "N" number ; Check if read or write command clrf temp btfsc Command, 0 bsf temp, 0 btfsc Command, 1 bsf temp, 1 btfsc Command, 2 bsf temp, 2 btfsc Command, 3 bsf temp, 3 movf temp, w xorlw d'0' btfsc STATUS, Z ; Write command check goto Write movf temp, w xorlw d'2' btfsc STATUS, Z ; Read command check goto Read movf temp, w xorlw d'4' btfsc STATUS, Z ; Set User Zone - write goto Write movf temp, w xorlw d'6' btfsc STATUS, Z ; System Read goto Read call ERRMESS movlw d'20' call delay1 ; Wait 5 second goto Start ;------------------------------------------------------------------------------- ;------------------------ Read command and chip address ---------------------- ;------------------------------------------------------------------------------- chr1 call Mess1 ; Asks for command and address btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr1 movf temp, w addlw d'0' btfsc STATUS, Z ; Only number 1 or 0 can be accepted goto ch1zero xorlw d'1' btfss STATUS, Z ; Only number 1 or 0 can be accepted goto chr1 movlw d'10' movwf Command movlw d'254' call Transmit movlw d'164' ; Cursor address 36 call Transmit movlw d'49' call Transmit ; send number 1 to LCD goto chr1h ch1zero clrf Command movlw d'254' call Transmit movlw d'164' ; Cursor address 36 call Transmit movlw d'48' call Transmit ; send number 1 to LCD chr1h btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr1h movf temp, w addwf Command, f movf temp, w addlw d'48' call Transmit chr1a btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr1a movf temp, w addlw d'0' btfsc STATUS, Z ; Only number 1 or 0 can be accepted goto ch1zeroa xorlw d'1' btfss STATUS, Z ; Only number 1 or 0 can be accepted goto chr1a movlw d'10' movwf temp2 movlw d'254' call Transmit movlw d'228' ; Cursor address 100 call Transmit movlw d'49' call Transmit ; send number 1 to LCD goto chr1i ch1zeroa clrf temp2 movlw d'254' call Transmit movlw d'228' ; Cursor address 100 call Transmit movlw d'48' call Transmit ; send number 1 to LCD chr1i btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr1i movf temp, w addwf temp2, f movf temp, w addlw d'48' call Transmit btfsc temp2, 0 bsf Command, 4 btfsc temp2, 1 bsf Command, 5 btfsc temp2, 2 bsf Command, 6 btfsc temp2, 3 bsf Command, 7 chr1j btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfss cmdind, 0 goto chr1j movf cmdtemp, w xorlw "A" btfss STATUS, Z goto chr1 clrf cmdind return ;------------------------------------------------------------------------------- ;------------------------- Read address 1 and address 2 ---------------------- ;------------------------------------------------------------------------------- chr2 clrf Adr1 call Mess2 ; Asks for addresses btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2 movf temp, w addlw d'253' btfsc STATUS, C ; Make sure no more than 200 goto chr2 movlw d'254' call Transmit movlw d'164' ; Cursor address 36 call Transmit movf temp, w addlw d'48' call Transmit movf temp, w call dig3 addwf Adr1, f chr2a btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2a movf temp, w addlw d'48' call Transmit movf temp, w call dig2 addwf Adr1, f chr2b btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2b movf temp, w addlw d'48' call Transmit movf temp, w call dig1 addwf Adr1, f chr2c clrf Adr2 btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2c movf temp, w addlw d'253' btfsc STATUS, C ; Make sure no more than 200 goto chr2 movlw d'254' call Transmit movlw d'228' ; Cursor address 100 call Transmit movf temp, w addlw d'48' call Transmit movf temp, w call dig3 addwf Adr2, f chr2d btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2d movf temp, w addlw d'48' call Transmit movf temp, w call dig2 addwf Adr2, f chr2e btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr2e movf temp, w addlw d'48' call Transmit movf temp, w call dig1 addwf Adr2, f chr2f btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfss cmdind, 0 goto chr2f movf cmdtemp, w xorlw "A" btfss STATUS, Z goto chr2 clrf cmdind return ;------------------------------------------------------------------------------- ;------------------------------- Read "N" Number ----------------------------- ;------------------------------------------------------------------------------- chr3 clrf Datnum call Mess3 ; Asks for "N" number btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr3 movf temp, w addlw d'253' btfsc STATUS, C ; Make sure no more than 200 goto chr3 movlw d'254' call Transmit movlw d'165' ; Cursor address 37 call Transmit movf temp, w addlw d'48' call Transmit movf temp, w call dig3 addwf Datnum, f chr3a btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr3a movf temp, w addlw d'48' call Transmit movf temp, w call dig2 addwf Datnum, f chr3b btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfsc cmdind, 0 goto chr3b movf temp, w addlw d'48' call Transmit movf temp, w call dig1 addwf Datnum, f chr3d btfss PIR1, RCIF ; Check if serial received goto $-1 movf RCREG, w call checkcmd btfss cmdind, 0 goto chr3d movf cmdtemp, w xorlw "A" btfss STATUS, Z goto chr3 clrf cmdind return ;------------------------------------------------------------------------------- ;------------------------- Check if a command entered ------------------------ ;------------------------------------------------------------------------------- checkcmd movwf temp xorlw "A" btfsc STATUS, Z goto cmd movf temp, w xorlw "B" btfsc STATUS, Z goto cmd movf temp, w xorlw "C" btfsc STATUS, Z goto cmd movf temp, w xorlw "D" btfsc STATUS, Z goto cmd movf temp, w xorlw "*" btfsc STATUS, Z goto cmd movf temp, w xorlw "#" btfsc STATUS, Z goto cmd clrf cmdind return cmd bsf cmdind, 0 movf temp, w movwf cmdtemp return ;------------------------------------------------------------------------------- ;-------------------------- Command + Address String ------------------------- ;------------------------------------------------------------------------------- Cmdstr bsf SDA goto $+1 bsf CLK goto $+1 bcf SDA goto $+1 bcf CLK goto $+1 ; Start movf Command, w movwf datatemp call Send call ACK btfsc ackerr, 0 ; Reset if no acknowledge return movf Adr1, w movwf datatemp call Send call ACK btfsc ackerr, 0 ; Reset if no acknowledge return movf Adr2, w movwf datatemp call Send call ACK btfsc ackerr, 0 ; Reset if no acknowledge return movf Datnum, w movwf datatemp call Send call ACK return Cmdend bcf SDA goto $+1 bsf CLK goto $+1 bsf SDA goto $+1 bcf CLK goto $+1 bcf SDA ; End return ;------------------------------------------------------------------------------- ;----------------------------------- Write ----------------------------------- ;------------------------------------------------------------------------------- Write call Cmdstr btfsc ackerr, 0 ; Reset if no acknowledge goto Mess8 movf Datnum, w xorlw d'0' btfsc STATUS, Z goto wrtlbl1 ; Check if "N" is zero movlw d'50' ; First RAM register to use movwf FSR nextbyte movf INDF, w movwf datatemp call Send call ACK btfsc ackerr, 0 ; Check if no acknowledge goto Mess8 incf FSR, f movf FSR, w xorlw d'112' ; End of bank 0 RAM ? btfsc STATUS, Z call nextram decfsz Datnum, f goto nextbyte wrtlbl1 call Cmdend call ACKPOL call Mess5 movlw d'8' call delay1 goto Start nextram movlw d'160' ; Start of FSR in bank 1 movwf FSR return ;------------------------------------------------------------------------------- ;---------------------------- Acknowledge Polling ---------------------------- ;------------------------------------------------------------------------------- ACKPOL clrf ackerr bsf SDA goto $+1 bsf CLK goto $+1 bcf SDA goto $+1 bcf CLK goto $+1 ; Start movf Command, w movwf datatemp call Send call ACK btfsc ackerr, 0 ; Loop again if no acknowledge goto ACKPOL call Cmdend return ;------------------------------------------------------------------------------- ;------------------------------------ Read ----------------------------------- ;------------------------------------------------------------------------------- Read call Cmdstr btfsc ackerr, 0 ; Reset if no acknowledge goto Mess8 movf Datnum, w xorlw d'0' btfsc STATUS, Z goto Mess7 movlw d'50' ; First RAM register to use movwf FSR nextread call Receive movf datatemp, w movwf INDF incf FSR, f movf FSR, w xorlw d'112' ; End of bank 0 RAM ? btfsc STATUS, Z call chkram decfsz Datnum, f goto rdlbl goto $+3 rdlbl call OUTACK goto nextread bsf SDA goto $+1 bsf CLK goto $+1 nop bcf CLK goto $+1 bcf SDA call Cmdend call Mess6 movlw d'8' call delay1 goto Start chkram movlw d'160' ; Start of FSR in bank 1 movwf FSR return ;------------------------------------------------------------------------------- ;-------------------------------- Acknowledge In ------------------------------ ;------------------------------------------------------------------------------- ACK bsf STATUS, RP0 bsf TRISA, 0 bcf STATUS, RP0 goto $+1 bsf CLK goto $+1 nop btfsc SDA bsf ackerr, 0 goto $+1 nop bcf CLK bsf STATUS, RP0 bcf TRISA, 0 bcf STATUS, RP0 return ;------------------------------------------------------------------------------- ;----------------------------------- Send ------------------------------------ ;------------------------------------------------------------------------------- Send ; Data is accepted on clock falling edge bcf SDA btfsc datatemp, 7 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 6 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 5 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 4 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 3 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 2 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 1 bsf SDA nop bsf CLK goto $+1 nop bcf CLK nop bcf SDA btfsc datatemp, 0 bsf SDA nop bsf CLK goto $+1 nop bcf CLK return ;------------------------------------------------------------------------------- ;----------------------------------- Receive --------------------------------- ;------------------------------------------------------------------------------- Receive ; Data is clocked out on clock falling edge bcf CLK bsf STATUS, RP0 bsf TRISA, 0 bcf STATUS, RP0 ; Input mode set goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 7 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 6 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 5 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 4 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 3 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 2 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 1 bcf CLK goto $+1 nop bsf CLK nop btfsc SDA bsf datatemp, 0 bcf CLK goto $+1 nop bsf STATUS, RP0 bcf TRISA, 0 bcf STATUS, RP0 ; Output mode set return ;------------------------------------------------------------------------------- ;------------------------------ Out Acknowledge ------------------------------ ;------------------------------------------------------------------------------- OUTACK bcf SDA goto $+1 bsf CLK goto $+1 nop bcf CLK goto $+1 return ;------------------------------------------------------------------------------- ;------------------------------- LCD Messages -------------------------------- ;------------------------------------------------------------------------------- Mess1 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess1a movf offset, w call Mess1b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess1a return Mess1b movlw LOW Mess1lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess1lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess1lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess1lookup DT " Press A to Confirm ", " Command ", " ", " Chip Address " Mess2 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess2a movf offset, w call Mess2b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess2a return Mess2b movlw LOW Mess2lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess2lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess2lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess2lookup DT " Press A to Confirm ", " Address 1 - ", " ", " Address 2 - " Mess3 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess3a movf offset, w call Mess3b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess3a return Mess3b movlw LOW Mess3lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess3lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess3lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess3lookup DT " Press A to Confirm ", " Data Quantity - ", " ", " " ERRMESS movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess4a movf offset, w call Mess4b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess4a return Mess4b movlw LOW Mess4lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess4lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess4lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess4lookup DT " Command ERROR ", " ", " ", " " Mess5 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess5a movf offset, w call Mess5b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess5a return Mess5b movlw LOW Mess5lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess5lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess5lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess5lookup DT " Write Complete ", " ", " ", " " Mess6 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess6a movf offset, w call Mess6b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess6a return Mess6b movlw LOW Mess6lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess6lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess6lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess6lookup DT " Read Complete ", " ", " ", " " Mess7 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess7a movf offset, w call Mess7b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess7a return Mess7b movlw LOW Mess7lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess7lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess7lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess7lookup DT " No Read Number ", " ", " ", " " Mess8 movlw d'254' call Transmit movlw d'1' call Transmit movlw d'4' call delay2 ; Wait 4ms clrf offset Mess8a movf offset, w call Mess8b ; fetch a character call Transmit incf offset, f movf offset, w xorlw d'80' btfss STATUS, Z goto Mess8a movlw d'8' call delay1 goto Start Mess8b movlw LOW Mess8lookup ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH Mess8lookup; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW Mess8lookup ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table Mess8lookup DT " EEPROM busy ", " ", " Try Again ", " " ;------------------------------------------------------------------------------- ;------------------------------ Transmit Check ------------------------------- ;------------------------------------------------------------------------------- Transmit bsf STATUS, RP0 ; Bank 1 btfss TXSTA, TRMT goto $-1 bcf STATUS, RP0 ; Bank 0 movwf TXREG return ;------------------------------------------------------------------------------- ;-------------------------------- Delay Loops -------------------------------- ;------------------------------------------------------------------------------- delay1 movwf temp4 loopy2 movlw d'250' movwf temp3 loopy movlw d'250' movwf temp initloop goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns nop ;200ns decfsz temp, f ;200ns goto initloop ;400ns decfsz temp3, f goto loopy ;250ms total decfsz temp4, f goto loopy2 ;Multiples of 250ms return delay2 movwf temp3 loop3 movlw d'250' movwf temp loop4 goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns goto $+1 ;400ns nop ;200ns decfsz temp, f ;200ns goto loop4 ;400ns decfsz temp3, f goto loop3 ;Multiples of 1ms return ;------------------------------------------------------------------------------- ;----------------------- Convert character to variable ----------------------- ;------------------------------------------------------------------------------- dig3 movwf temp3 ; number of 100's clrf temp dig3a movf temp3, w xorlw d'0' btfsc STATUS, Z goto dig3b decf temp3, f movf temp, w addlw d'100' movwf temp goto dig3a dig3b movf temp, w return dig2 movwf temp3 ; number of 10's clrf temp dig2a movf temp3, w xorlw d'0' btfsc STATUS, Z goto dig2b decf temp3, f movf temp, w addlw d'10' movwf temp goto dig2a dig2b movf temp, w return dig1 movwf temp3 ; number of 1's clrf temp dig1a movf temp3, w xorlw d'0' btfsc STATUS, Z goto dig1b decf temp3, f movf temp, w addlw d'1' movwf temp goto dig1a dig1b movf temp, w return end