ON 20101001@8:30:27 PM at page: On a web page you were interested in at: http://pet310.massmind.org/Techref/member/AT-planet-T9/index.htm# James Newton[JMN-EFP-786] I have agreed to maintain this page. ON 20101001@8:34:21 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40452.8571759259 Andries Tip[AT-planet-T9] Says /Techref/member/AT-planet-T9/safeeeprom.htm EEPROM write with majority check for PIC 16F676 ON 20101001@8:48:42 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40452.8671412037 Andries Tip[AT-planet-T9] Says /Techref/member/AT-planet-T9/test.htm test ON 20101001@8:50:08 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40452.8681481481 Andries Tip[AT-planet-T9] Says /Techref/member/AT-planet-T9/test.htm test ON 20101001@8:51:34 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/safeeeprom.htm#40452.8691319444 Andries Tip[AT-planet-T9] Code:
LIST    P=16F676                ; DIRECTIVE TO DEFINE PROCESSOR

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

; VARIABLES USED IN BANK 0 (HEX 20-5F), ALSO ACCESSABLE FROM FROM BANK 1 (HEX A0-DF)

EEPROMCOUNT       EQU        0X49       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMADDR        EQU        0X50       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMDATA        EQU        0X51       ; USED IN THE FIVE-FOLD EEPROM SAVE
MAJORITY          EQU        0x52       ; USED IN THE EEPROM LOAD SUBROUTINE TO CALCULATE THE RESULT OF THE MAJORITY CHECK 

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

EEPROM_SAVE_5   BANK1                   ; WRITE ONE BYTE FIVE-FOLD INTO PIC INTERNAL EEPROM
                MOVLW    D'5'           ; PREPARE FIVE-FOLD SAVE
                MOVWF    EEPROMCOUNT    ;
EESAVE_5_LOOP   BTFSC    EECON1,WR      ; EACH EEPROM BYTE WRITE CAN TAKE UP TO 6 MILLISECONDS, DID WE FINISH ANY PREVIOUS WRITE ? 
                GOTO     EESAVE_5_LOOP  ; NO, NOT YET, WAIT A BIT MORE
                MOVF     EEPROMADDR,W   ; YES, MAKE SURE THE EEPROM ADDRESS AND DATA BYTES HOLD THE RIGHT VALUE,
                MOVWF    EEADR          ; THE STATUS OF THESE BYTES AFTER A WRITE IS UNKNOWN (AND UNDOCUMENTED)
                MOVF     EEPROMDATA,W   ;
                MOVWF    EEDATA         ;
                BSF      EECON1,WREN    ; ENABLE EEPROM WRITES
;               BCF      INTCON,GIE     ; DISABLE INTERRUPTS < ARE ALREADY DISABLED >
                MOVLW    H'55'          ; WRITE UNLOCK CODE 1
                MOVWF    EECON2         ; UNLOCK WRITE
                MOVLW    H'AA'          ; WRITE UNLOCK CODE 2
                MOVWF    EECON2         ; UNLOCK WRITE
                BSF      EECON1,WR      ; ACTIVATE WRITE
                BCF      EECON1,WREN    ; DISABLE EEPROM WRITES
;               BSF      INTCON,GIE     ; RE-ENABLE INTERRUPTS < WILL BE ENABLED ELSEWHERE >
                INCF     EEPROMADDR,F   ; SELECT NEXT WRITE ADDRESS
                DECFSZ   EEPROMCOUNT,F  ; DID WE WRITE ALL FIVE BYTES ?
                GOTO     EESAVE_5_LOOP  ; NO, GO WRITE NEXT BYTE

                RETURN                  ; DONE

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

EEPROM_READ                             ; THE VALUES ARE STORED IN PIC INTERNAL EEPROM. DUE TO POWER FAILURE DURING SAVES OR DUE TO
                                        ; OTHER CAUSES THE STORED VALUES MAY BECOME ERRORNOUS. TO MAKE SURE WE GET THE RIGHT VALUES
                                        ; WE STORE THEM IN FIVE-FOLD. USING A MAJORITY CHECK WE CAN CIRCUMVENT FALSE BYTES.
                                        ; WE WANT AT LEAST THREE OUT OF FIVE (MAJORITY CHECK):

                                        ; TRUTH TABLE:                         KARNAUGH MAP:
                                        ;                                
                                        ;          EDCBA        Y                           DE       DE       DE       DE
                                        ; 0        00000        0                 CBA       00       01       10       11
                                        ; 1        00001        0                
                                        ; 2        00010        0                 000        0        0        0        0
                                        ; 3        00011        0                 001        0        0        0        1
                                        ; 4        00100        0                 010        0        0        0        1
                                        ; 5        00101        0                 011        0        1        1        1
                                        ; 6        00110        0                 100        0        0        0        1
                                        ; 7        00111        1                 101        0        1        1        1
                                        ; 8        01000        0                 110        0        1        1        1
                                        ; 9        01001        0                 111        1        1        1        1
                                        ; 10       01010        0                
                                        ; 11       01011        1
                                        ; 12       01100        0
                                        ; 13       01101        1
                                        ; 14       01110        1
                                        ; 15       01111        1
                                        ; 16       10000        0
                                        ; 17       10001        0            BOOLEAN EQUATIONS:
                                        ; 18       10010        0                
                                        ; 19       10011        1            RESULT = A AND B AND C
                                        ; 20       10100        0                          OR
                                        ; 21       10101        1                     (A OR B OR C) AND D AND E
                                        ; 22       10110        1                          OR
                                        ; 23       10111        1                     (A OR B) AND NOT(A XOR B XOR C) AND (D OR E) 
                                        ; 24       11000        0
                                        ; 25       11001        1
                                        ; 26       11010        1
                                        ; 27       11011        1
                                        ; 28       11100        1
                                        ; 29       11101        1
                                        ; 30       11110        1
                                        ; 31       11111        1        

                BANK1                   ; READ BYTE FROM PIC INTERNAL EEPROM, USE MAJORITY CHECK ONE THE FIVE-FOLD VALUE 
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION, CURRENT ADDRESS: A
                BTFSC    EECON1,RD      ; MAKE SURE THE READ HAS FINISHED, SEEMS TO BE A PROBLEM ON SOME PIC'S
                GOTO     $-1            ;
                COMF     EEDATA,W       ; W = NOT(A)
                INCF     EEADR,F        ; SELECT NEXT READ ADDRESS: B
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B)  
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B XOR C)
                MOVWF    MAJORITY       ; R = NOT(A XOR B XOR C)
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = D 
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = D OR E
                ANDWF    MAJORITY,F     ; R = (D OR E) AND NOT(A XOR B XOR C)
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                ANDWF    MAJORITY,F     ; R = (A OR B) AND (D OR E) AND NOT(A XOR B XOR C)
                DECF     EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B OR C
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D AND E
                IORWF    MAJORITY,F     ; R = ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B AND C
                IORWF    MAJORITY,W     ; W = (A AND B AND C) OR ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))

                RETURN                  ; DONE, RETURN WITH VALUE IN W REGISTER

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

ON 20101001@8:52:46 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/safeeeprom.htm#40452.8699768518 Andries Tip[AT-planet-T9] Code:
LIST    P=16F676                ; DIRECTIVE TO DEFINE PROCESSOR

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

; VARIABLES USED IN BANK 0 (HEX 20-5F), ALSO ACCESSABLE FROM FROM BANK 1 (HEX A0-DF)

EEPROMCOUNT       EQU        0X49       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMADDR        EQU        0X50       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMDATA        EQU        0X51       ; USED IN THE FIVE-FOLD EEPROM SAVE
MAJORITY          EQU        0x52       ; USED IN THE EEPROM LOAD SUBROUTINE TO CALCULATE THE RESULT OF THE MAJORITY CHECK 

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

EEPROM_SAVE_5   BANK1                   ; WRITE ONE BYTE FIVE-FOLD INTO PIC INTERNAL EEPROM
                MOVLW    D'5'           ; PREPARE FIVE-FOLD SAVE
                MOVWF    EEPROMCOUNT    ;
EESAVE_5_LOOP   BTFSC    EECON1,WR      ; EACH EEPROM BYTE WRITE CAN TAKE UP TO 6 MILLISECONDS, DID WE FINISH ANY PREVIOUS WRITE ? 
                GOTO     EESAVE_5_LOOP  ; NO, NOT YET, WAIT A BIT MORE
                MOVF     EEPROMADDR,W   ; YES, MAKE SURE THE EEPROM ADDRESS AND DATA BYTES HOLD THE RIGHT VALUE,
                MOVWF    EEADR          ; THE STATUS OF THESE BYTES AFTER A WRITE IS UNKNOWN (AND UNDOCUMENTED)
                MOVF     EEPROMDATA,W   ;
                MOVWF    EEDATA         ;
                BSF      EECON1,WREN    ; ENABLE EEPROM WRITES
;               BCF      INTCON,GIE     ; DISABLE INTERRUPTS < ARE ALREADY DISABLED >
                MOVLW    H'55'          ; WRITE UNLOCK CODE 1
                MOVWF    EECON2         ; UNLOCK WRITE
                MOVLW    H'AA'          ; WRITE UNLOCK CODE 2
                MOVWF    EECON2         ; UNLOCK WRITE
                BSF      EECON1,WR      ; ACTIVATE WRITE
                BCF      EECON1,WREN    ; DISABLE EEPROM WRITES
;               BSF      INTCON,GIE     ; RE-ENABLE INTERRUPTS < WILL BE ENABLED ELSEWHERE >
                INCF     EEPROMADDR,F   ; SELECT NEXT WRITE ADDRESS
                DECFSZ   EEPROMCOUNT,F  ; DID WE WRITE ALL FIVE BYTES ?
                GOTO     EESAVE_5_LOOP  ; NO, GO WRITE NEXT BYTE

                RETURN                  ; DONE

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

EEPROM_READ                             ; THE VALUES ARE STORED IN PIC INTERNAL EEPROM. DUE TO POWER FAILURE DURING SAVES OR DUE TO
                                        ; OTHER CAUSES THE STORED VALUES MAY BECOME ERRORNOUS. TO MAKE SURE WE GET THE RIGHT VALUES
                                        ; WE STORE THEM IN FIVE-FOLD. USING A MAJORITY CHECK WE CAN CIRCUMVENT FALSE BYTES.
                                        ; WE WANT AT LEAST THREE OUT OF FIVE (MAJORITY CHECK):

                                        ; TRUTH TABLE:                         KARNAUGH MAP:
                                        ;                                
                                        ;          EDCBA        Y                           DE       DE       DE       DE
                                        ; 0        00000        0                 CBA       00       01       10       11
                                        ; 1        00001        0                
                                        ; 2        00010        0                 000        0        0        0        0
                                        ; 3        00011        0                 001        0        0        0        1
                                        ; 4        00100        0                 010        0        0        0        1
                                        ; 5        00101        0                 011        0        1        1        1
                                        ; 6        00110        0                 100        0        0        0        1
                                        ; 7        00111        1                 101        0        1        1        1
                                        ; 8        01000        0                 110        0        1        1        1
                                        ; 9        01001        0                 111        1        1        1        1
                                        ; 10       01010        0                
                                        ; 11       01011        1
                                        ; 12       01100        0
                                        ; 13       01101        1
                                        ; 14       01110        1
                                        ; 15       01111        1
                                        ; 16       10000        0
                                        ; 17       10001        0            BOOLEAN EQUATIONS:
                                        ; 18       10010        0                
                                        ; 19       10011        1            RESULT = A AND B AND C
                                        ; 20       10100        0                          OR
                                        ; 21       10101        1                     (A OR B OR C) AND D AND E
                                        ; 22       10110        1                          OR
                                        ; 23       10111        1                     (A OR B) AND NOT(A XOR B XOR C) AND (D OR E) 
                                        ; 24       11000        0
                                        ; 25       11001        1
                                        ; 26       11010        1
                                        ; 27       11011        1
                                        ; 28       11100        1
                                        ; 29       11101        1
                                        ; 30       11110        1
                                        ; 31       11111        1        

                BANK1                   ; READ BYTE FROM PIC INTERNAL EEPROM, USE MAJORITY CHECK ONE THE FIVE-FOLD VALUE 
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION, CURRENT ADDRESS: A
                BTFSC    EECON1,RD      ; MAKE SURE THE READ HAS FINISHED, SEEMS TO BE A PROBLEM ON SOME PIC'S
                GOTO     $-1            ;
                COMF     EEDATA,W       ; W = NOT(A)
                INCF     EEADR,F        ; SELECT NEXT READ ADDRESS: B
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B)  
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B XOR C)
                MOVWF    MAJORITY       ; R = NOT(A XOR B XOR C)
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = D 
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = D OR E
                ANDWF    MAJORITY,F     ; R = (D OR E) AND NOT(A XOR B XOR C)
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                ANDWF    MAJORITY,F     ; R = (A OR B) AND (D OR E) AND NOT(A XOR B XOR C)
                DECF     EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B OR C
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D AND E
                IORWF    MAJORITY,F     ; R = ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B AND C
                IORWF    MAJORITY,W     ; W = (A AND B AND C) OR ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))

                RETURN                  ; DONE, RETURN WITH VALUE IN W REGISTER

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

ON 20101001@9:06:06 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40452.8792361111 Andries Tip[AT-planet-T9] Says test ON 20101001@9:09:40 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40452.8792361111 Andries Tip[AT-planet-T9] removed post 40452.8792361111 |Delete ' test ' ON 20101001@9:10:47 PM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/safeeeprom.htm#40452.8824884259 Andries Tip[AT-planet-T9] Code:
LIST    P=16F676                ; DIRECTIVE TO DEFINE PROCESSOR

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

; VARIABLES USED IN BANK 0 (HEX 20-5F), ALSO ACCESSABLE FROM FROM BANK 1 (HEX A0-DF)

EEPROMCOUNT       EQU        0X49       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMADDR        EQU        0X50       ; USED IN THE FIVE-FOLD EEPROM SAVE
EEPROMDATA        EQU        0X51       ; USED IN THE FIVE-FOLD EEPROM SAVE
MAJORITY          EQU        0x52       ; USED IN THE EEPROM LOAD SUBROUTINE TO CALCULATE THE RESULT OF THE MAJORITY CHECK 

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

EEPROM_SAVE_5   BANK1                   ; WRITE ONE BYTE FIVE-FOLD INTO PIC INTERNAL EEPROM
                MOVLW    D'5'           ; PREPARE FIVE-FOLD SAVE
                MOVWF    EEPROMCOUNT    ;
EESAVE_5_LOOP   BTFSC    EECON1,WR      ; EACH EEPROM BYTE WRITE CAN TAKE UP TO 6 MILLISECONDS, DID WE FINISH ANY PREVIOUS WRITE ? 
                GOTO     EESAVE_5_LOOP  ; NO, NOT YET, WAIT A BIT MORE
                MOVF     EEPROMADDR,W   ; YES, MAKE SURE THE EEPROM ADDRESS AND DATA BYTES HOLD THE RIGHT VALUE,
                MOVWF    EEADR          ; THE STATUS OF THESE BYTES AFTER A WRITE IS UNKNOWN (AND UNDOCUMENTED)
                MOVF     EEPROMDATA,W   ;
                MOVWF    EEDATA         ;
                BSF      EECON1,WREN    ; ENABLE EEPROM WRITES
;               BCF      INTCON,GIE     ; DISABLE INTERRUPTS < ARE ALREADY DISABLED >
                MOVLW    H'55'          ; WRITE UNLOCK CODE 1
                MOVWF    EECON2         ; UNLOCK WRITE
                MOVLW    H'AA'          ; WRITE UNLOCK CODE 2
                MOVWF    EECON2         ; UNLOCK WRITE
                BSF      EECON1,WR      ; ACTIVATE WRITE
                BCF      EECON1,WREN    ; DISABLE EEPROM WRITES
;               BSF      INTCON,GIE     ; RE-ENABLE INTERRUPTS < WILL BE ENABLED ELSEWHERE >
                INCF     EEPROMADDR,F   ; SELECT NEXT WRITE ADDRESS
                DECFSZ   EEPROMCOUNT,F  ; DID WE WRITE ALL FIVE BYTES ?
                GOTO     EESAVE_5_LOOP  ; NO, GO WRITE NEXT BYTE

                RETURN                  ; DONE

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

EEPROM_READ                             ; THE VALUES ARE STORED IN PIC INTERNAL EEPROM. DUE TO POWER FAILURE DURING SAVES OR DUE TO
                                        ; OTHER CAUSES THE STORED VALUES MAY BECOME ERRORNOUS. TO MAKE SURE WE GET THE RIGHT VALUES
                                        ; WE STORE THEM IN FIVE-FOLD. USING A MAJORITY CHECK WE CAN CIRCUMVENT FALSE BYTES.
                                        ; WE WANT AT LEAST THREE OUT OF FIVE (MAJORITY CHECK):

                                        ; TRUTH TABLE:                         KARNAUGH MAP:
                                        ;                                
                                        ;          EDCBA        Y                           DE       DE       DE       DE
                                        ; 0        00000        0                 CBA       00       01       10       11
                                        ; 1        00001        0                
                                        ; 2        00010        0                 000        0        0        0        0
                                        ; 3        00011        0                 001        0        0        0        1
                                        ; 4        00100        0                 010        0        0        0        1
                                        ; 5        00101        0                 011        0        1        1        1
                                        ; 6        00110        0                 100        0        0        0        1
                                        ; 7        00111        1                 101        0        1        1        1
                                        ; 8        01000        0                 110        0        1        1        1
                                        ; 9        01001        0                 111        1        1        1        1
                                        ; 10       01010        0                
                                        ; 11       01011        1
                                        ; 12       01100        0
                                        ; 13       01101        1
                                        ; 14       01110        1
                                        ; 15       01111        1
                                        ; 16       10000        0
                                        ; 17       10001        0            BOOLEAN EQUATIONS:
                                        ; 18       10010        0                
                                        ; 19       10011        1            RESULT = A AND B AND C
                                        ; 20       10100        0                          OR
                                        ; 21       10101        1                     (A OR B OR C) AND D AND E
                                        ; 22       10110        1                          OR
                                        ; 23       10111        1                     (A OR B) AND NOT(A XOR B XOR C) AND (D OR E) 
                                        ; 24       11000        0
                                        ; 25       11001        1
                                        ; 26       11010        1
                                        ; 27       11011        1
                                        ; 28       11100        1
                                        ; 29       11101        1
                                        ; 30       11110        1
                                        ; 31       11111        1        

                BANK1                   ; READ BYTE FROM PIC INTERNAL EEPROM, USE MAJORITY CHECK ONE THE FIVE-FOLD VALUE 
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION, CURRENT ADDRESS: A
                BTFSC    EECON1,RD      ; MAKE SURE THE READ HAS FINISHED, SEEMS TO BE A PROBLEM ON SOME PIC'S
                GOTO     $-1            ;
                COMF     EEDATA,W       ; W = NOT(A)
                INCF     EEADR,F        ; SELECT NEXT READ ADDRESS: B
                BSF      EECON1,RD      ; PERFORM THE EEPROM READ OPERATION
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B)  
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                XORWF    EEDATA,W       ; W = NOT(A XOR B XOR C)
                MOVWF    MAJORITY       ; R = NOT(A XOR B XOR C)
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = D 
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = D OR E
                ANDWF    MAJORITY,F     ; R = (D OR E) AND NOT(A XOR B XOR C)
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                ANDWF    MAJORITY,F     ; R = (A OR B) AND (D OR E) AND NOT(A XOR B XOR C)
                DECF     EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                IORWF    EEDATA,W       ; W = A OR B OR C
                INCF     EEADR,F        ; NEXT ADDRESS: D
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D
                INCF     EEADR,F        ; NEXT ADDRESS: E
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = (A OR B OR C) AND D AND E
                IORWF    MAJORITY,F     ; R = ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))
                MOVLW    D'4'           ;
                SUBWF    EEADR,F        ; NEXT ADDRESS: A
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                MOVF     EEDATA,W       ; W = A
                INCF     EEADR,F        ; NEXT ADDRESS: B
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B
                INCF     EEADR,F        ; NEXT ADDRESS: C
                BSF      EECON1,RD      ;
                BTFSC    EECON1,RD      ;
                GOTO     $-1            ;
                ANDWF    EEDATA,W       ; W = A AND B AND C
                IORWF    MAJORITY,W     ; W = (A AND B AND C) OR ((A OR B OR C) AND D AND E) OR ((D OR E) AND NOT(A XOR B XOR C))

                RETURN                  ; DONE, RETURN WITH VALUE IN W REGISTER

;--------------------------------------------------------------------------------------------------------------------------------------
ON 20101002@11:17:07 AM at page: On a web page you were interested in at: http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40453.4702083333 Andries Tip[AT-planet-T9] Code: /Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop




ON 20101002@11:21:38 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=7



ON 20101002@11:29:55 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40453.4791087963
Andries Tip[AT-planet-T9] Code:
/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop




ON 20101002@11:32:05 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=9



ON 20101002@11:33:21 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=10



ON 20101002@11:33:39 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=11



ON 20101002@11:35:57 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=12



ON 20101002@11:36:50 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=13



ON 20101002@11:38:01 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=14



ON 20101002@11:39:06 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=15



ON 20101002@11:39:58 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=16



ON 20101002@11:58:22 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40453.4988657407
Andries Tip[AT-planet-T9] Code:
/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) 




ON 20101002@11:58:55 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=18



ON 20101002@11:59:25 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=19



ON 20101002@12:00:14 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=20



ON 20101002@12:01:30 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=0



ON 20101002@12:01:50 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=1



ON 20101002@12:02:31 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=2



ON 20101002@12:03:02 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=3



ON 20101002@12:03:35 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=4



ON 20101002@12:17:25 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=21



ON 20101002@12:22:23 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=22



ON 20101002@12:22:57 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=23



ON 20101002@12:25:48 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=24



ON 20101002@12:29:55 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=25



ON 20101002@12:30:19 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=26



ON 20101002@12:31:21 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=27



ON 20101002@12:31:59 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=28



ON 20101002@12:32:29 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop.htm&version=0



ON 20101002@12:34:40 PM at page:
On a web page you were interested in at:
http://www.piclist.com/techref/member/AT-planet-T9/index.htm#40453.5240740741
Andries Tip[AT-planet-T9] change Pages:
/Techref/microchip/timenint.htm
PIC long term timers without interrupts



ON 20101002@1:23:23 PM at page:
On a web page you were interested in at:
http://www.piclist.com/techref/member/AT-planet-T9/index.htm#40453.5579050926
Andries Tip[AT-planet-T9] change Pages:
/Techref/microchip/timenint.htm
PIC long term timers without interrupts



ON 20101002@1:53:39 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm#
James Newton[JMN-EFP-786] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop (without use of the pcl register) .htm&version=5



ON 20101002@1:57:53 PM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop.htm#
James Newton[JMN-EFP-786] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\High precision timed events without interrupts for 12-bit PIC (instruction cycle accurate) using a non-isochronous main loop.htm&version=1



ON 20101006@12:42:57 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#40457.0298263889
Andries Tip[AT-planet-T9] Code:
/Techref/member/AT-planet-T9/superpwm.htm




ON 20101006@12:50:52 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/superpwm.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\superpwm.htm&version=0



ON 20101006@1:01:44 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=32



ON 20101006@1:02:30 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/superpwm.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\superpwm.htm&version=1



ON 20101006@1:03:28 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/index.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\index.htm&version=33



ON 20101013@12:34:01 AM at page:
On a web page you were interested in at:
http://www.piclist.com/Techref/member/AT-planet-T9/superpwm.htm#
Andries Tip[AT-planet-T9] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=\Techref\member\AT-planet-T9\superpwm.htm&version=2