Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Which part of this code actually counts the sensor pulses?

Status
Not open for further replies.
I've been trying to modify code for a circuit I found on a Russian website to fit my needs and I need some help. The circuit is a 3 digit speedometer with a 6 digit odometer/5 digit resettable trip counter. As designed the circuit uses a speed sensor that produces 6 pulses per meter and advances the counter accordingly. The main odometer has 6 digits "000000" with a 1 km resolution and the resettable trip counter has 5 digits "000.00" with .01 km resolution. I've already figured out to move the decimal point in the trip counter to "0000.0" but my speed sensor is different. My speed sensor produces 8000 pulses per mile. I'm not sure what part of the code counts the sensor pulses and increments the counters accordingly.

Here's the circuit:

View attachment 66308

The speed sensor is the rectangle on the left side with the numbers 345.3843 inside. Per the diagram it is connected to pin 11 of the microcontroller but the text indicates there's an error and pins 11 and 21 should be swapped.
 
Here's the code

Code:
             ;******************************************

             ;*     Speedometer and odometer 16f876*

             ;******************************************

;=====================================================================================

; 10MHz crystal 6 pulses per meter

 list p = 16F876
 #include <P16F876.INC>

 __config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF


; Constants

RCSwitch equ 1    ; RC1
RCPower  equ 0    ; RC0
RCButton equ 3    ; RA3
RCPoint  equ 4    ; RA4

; Variable

; Active segment number

INDNO equ 0x20

; Buffer display odometer digits in the form of combinations of segments

IND01 equ 0x21
IND02 equ 0x22
IND03 equ 0x23
IND04 equ 0x24
IND05 equ 0x25
IND06 equ 0x26

; speedometer display buffer

INDS1 equ 0x27
INDS2 equ 0x28
INDS3 equ 0x29

; Main odometer counter

tot_prev equ 0x2A 
tor_k001 equ 0x2B
tot_k010 equ 0x2C
tot_k100 equ 0x2D
tot_001k equ 0x2E
tot_010k equ 0x2F
tot_100k equ 0x30
tot_001t equ 0x31
tot_010t equ 0x32
tot_100t equ 0x33

; additional trip counter

aux_prev equ 0x34
aux_k001 equ 0x35
aux_k010 equ 0x36
aux_k100 equ 0x37
aux_001k equ 0x38
aux_010k equ 0x39
aux_100k equ 0x3A

IPM      equ 0x3B

SCR_MODE equ 0x3C

BTN_MODE equ 0x3D

BTN_CNTR equ 0x3E

BTN_STAT equ 0x3F

cntr2    equ 0x40

iHCNT    equ 0x41

iLCNT    equ 0x42

cHCNT    equ 0x43

cLCNT    equ 0x44

PreDIG   equ 0x45

EspDIG   equ 0x46

DspDIG   equ 0x47

HspDIG   equ 0x48

; BTN_MODE - describes what happened to the button 

;   00 - button at top

;   01 - button is moving down

;   11 - Button is at bottom

;   10 - Button is moving up

; SCR_MODE - specifies the procedure FILL_VB, than fill the video buffer

;   0 - full mileage

;   1 - daily

;   2 - empty

;   3 - the word reset


; program

        org     0x00
        goto    START

; Recoding digits in the code 7-segment display

SEG7            ; in the counters is not the value itself, and (10 value)

  sublw d'010'  ; calculated value
  andlw 0x0F    ; just in case
  addwf PCL,f

;         Ebfdacg zero bit in the segment lights

  retlw b'00000011' ;  0
  retlw b'10111011' ;  1
  retlw b'00100101' ;  2
  retlw b'10100001' ;  3
  retlw b'10011001' ;  4
  retlw b'11000001' ;  5
  retlw b'01000001' ;  6
  retlw b'10110011' ;  7
  retlw b'00000001' ;  8
  retlw b'10000001' ;  9
  retlw b'11110111' ; 10
  retlw b'10111111' ; 11
  retlw b'11111011' ; 12
  retlw b'11101111' ; 13
  retlw b'01111111' ; 14
  retlw b'11011111' ; 15

; Calculation of bits including a discharge to the number of active anode

ANOD_C

  andlw 0x07    ;just in case
  addwf PCL,f
    			  ;  123 465 units at the bit level lights
  retlw b'00000000' ;  0
  retlw b'10000000' ;  1
  retlw b'01000000' ;  2
  retlw b'00100000' ;  3
  retlw b'00010000' ;  4
  retlw b'00000100' ;  5
  retlw b'00001000' ;  6
  retlw b'00000000' ;  7 


; Calculation of bits including a discharge to the number of active anode

ANOD_A

  andlw 0x03    ;just in case
  addwf PCL,f

; 321  units at the bit level 1 lights and hundreds of dozens of 2-3-units

  retlw b'00010000' ;  0
  retlw b'00010001' ;  1
  retlw b'00010010' ;  2
  retlw b'00010100' ;  3


START

        bcf     STATUS, RP0     ; Bank 0
        bcf     STATUS, RP1
        clrf    T2CON
        clrf    TMR0
        clrf    TMR2
        clrf    INTCON
        clrf    PORTA
        clrf    PORTB
        clrf    PORTC
        bsf     STATUS, RP0     ; Bank 1
        movlw   0x06            ; And on all legs tsirfu
        movwf   ADCON1
        movlw   b'00001000'
        movwf   TRISA           ; RA3 - button, the rest of the output
        movlw   b'00000001'
        movwf   TRISB           ; RB0 - the sensor, the other output
        movlw   b'00000001'
        movwf   TRISC           ; RC0 - the ignition, the rest of the output

; Include pull-up resistors, 
; TMR0 to the internal clock with prescaler 16 (4 ms in the figure)

		movlw   b'01000011'
		movwf   OPTION_REG	

; Include TIMER2

        clrf    PIE1
        movlw   d'249'          ; at 10 MHz, the frequency of the quartz clock = Fosc / 4 = 				        ;2.5 MHz, 0.4 ms
        movwf   PR2             ; period register TIMER2 = 250 clock = 100 ms per cycle
                                ;   Cycle = 100 s * 1 (PRE) * 1 (POST) = 100 ms
	  bcf     STATUS,RP0      ; Bank 0
        movlw   b'00000100'     ; none:7  (POST-1):6-3   On/Off:2  PRE: 1-0   
        movwf   T2CON           ;          b0000 = 1:1     1=On     b00 = 1
        clrf    PIR1
        bsf     PORTC, RCSwitch
        call    READ_EEPROM
        movlw   d'10'
        movwf   HspDIG
        movwf   DspDIG
        movwf   EspDIG
; ***
        movlw   1                  ; was 8
        movwf   PreDIG
        movlw   9
        movwf   INDNO
        clrf    TMR0
        bcf     INTCON,T0IF  ; reset the timer
        call    PROLOG
        clrf    BTN_MODE  
        clrf    SCR_MODE  
        call    FILL_VB   
        call    FILL_SPD
; ***
        movlw  d'23'            ; was d'37' to 30 pulses / meter
        movwf iHCNT
; ***
        movlw d'112'          ; was d'128' for 30 pulses / meter
        movwf iLCNT
        clrf    cHCNT
        movlw   1
        movwf   cLCNT
 
MAIN_LOOP

; Check the power

        btfss   PORTC,RCPower; circumvent the shutdown, if a
        goto    PowerDown

PowerRise

; Dimensional check the timer

        btfsc   PIR1,TMR2IF  ; if 0 (no signal from TIMER2), by bypassing
        call    DO_TICK      ; and if one, then go to increase the counter

; Check the sensor

        btfsc   INTCON,INTF  ; if 0 (no signal from the sensor), by bypassing
        call    DO_INCR      ; and if one, then go to increase the counter


; Duplicate state of the sensor

;        btfsc   PORTB,0
;        bsf     PORTA,5
;        btfss   PORTB,0
;        bcf     PORTA,5


; Check the timer for dynamic display

        btfss   INTCON,T0IF  ; if the timer has finished counting, you're going to change 			           ;the discharge
	  goto    MAIN_LOOP    ;  otherwise repeat the test in a loop


; And all that below, performed a time of 1.6 ms (at 10MHz)

        call    ChkButton    ; treatment of buttons
        call    ChAnod       ; shift indicator bits

        bcf     INTCON,T0IF  ; reset the timer
        goto    MAIN_LOOP


; Check button, and respond

ChkButton

        rlf     BTN_MODE,f    ; BTN_MODE every time we shift by one bit to the left
        bcf     BTN_MODE,0    ; and 0y Write the bits
        btfss   PORTA, RCButton  ;   0 if the button at the top
        bsf     BTN_MODE,0       ;   1, if the bottom
        movf    BTN_MODE,w      ; then cut out the lower two bits
        andlw   3             ; and from them select the treatment option
        addwf   PCL,f         ;
        goto    Btn_UpUp      ;  00 - button was, and remains at the top (always depressed)
        goto    Btn_UpDn      ;  01 - moved from the top down (pressed)
        goto    Btn_DnUp      ;  10 - moved from the bottom up (released)
        goto    Btn_DnDn      ;  11 - has been and remains at the bottom (continuously pressed)


Btn_UpDn ; PRESS

        clrf    BTN_CNTR      ; when you click
        clrf    BTN_STAT      ; zero out counters retention time
        goto    Btn_UpUp

Btn_DnDn ; HOLD 		continue to increase the counter

        incfsz  BTN_CNTR,f    ; when the counter reached the count of 256 (0.4 seconds)
        goto    TestSTATUS
        incf    BTN_STAT,f    ; modify the code response to the rise of the buttons

TestSTATUS                    ; depending on the retention time

        btfss   BTN_STAT,2    ;  0, 1, 2, 3 (0.4 to 0.8 to 1.2 to 1.6 sec)
        goto    Btn_UpUp
        decf    BTN_STAT,f    ; if the code has reached four, then return it to the three
        bsf     SCR_MODE,1    ; one, change the display mode data in the display
        call    FILL_VB       ; now for the WHOLE screen NOTHING
        goto    Btn_UpUp      ; for daily on-screen word RESET

Btn_DnUp ; RELEASED   

        btfss   SCR_MODE,1    ; if there was a short jab
        goto    SwitchMode    ; we're going to switch the display mode

TestReset 

        bcf     SCR_MODE,1    ; one for a long Kicks
        btfss   SCR_MODE,0    ;  back normal mode indicator FULL / DAILY
        goto    ODOmode       
        movf    IPM,w         ; and for the daily addition
        movwf   aux_prev      ; did reset the bits in the 000.00
        movlw   d'10'
        movwf   aux_100k
        movwf   aux_010k
        movwf   aux_001k
        movwf   aux_k100
        movwf   aux_k010
        movwf   aux_k001
        goto    ODOmode

SwitchMode                    ; indicator FULL mode switching / DAILY

        movlw   1
        xorwf   SCR_MODE,f        

ODOmode                       ; restoration of the buffer indicator

        call    FILL_VB

Btn_UpUp                      ; if the button is always on top, there's nothing else to do

        return

FILL_SPD    ; portable numbers skrosti previous measurement in the video buffer

  movf    HspDIG,w
  call    SEG7       ; withdrawal of hundreds of
  movwf   INDS1      ;   
  movf    DspDIG,w
  call    SEG7       ; withdrawal of tens of
  movwf   INDS2
  movf    EspDIG,w   ; the output units are always
  call    SEG7
  movwf   INDS3
  call    CLR_LEAD0  ; pay off leading zeros
  return

; Filling the video buffer code segments

FILL_VB

  movfw  SCR_MODE    ; choose, than fill the buffer indicator
  andlw  b'00000011' ; depending on the value of SRC_MODE
  addwf  PCL,f
  goto   Fill_ODOM
  goto   Fill_TRIP
  goto   Fill_NONE
  goto   Fill_TEXT

Fill_ODOM            ; fill the buffer

  movfw tot_100t     ; figures the total range
  call  SEG7
  movwf IND01
  movfw tot_010t
  call  SEG7
  movwf IND02
  movfw tot_001t
  call  SEG7
  movwf IND03
  movfw tot_100k
  call  SEG7
  movwf IND04
  movfw tot_010k
  call  SEG7
  movwf IND05
  movfw tot_001k
  call  SEG7
  movwf IND06
  return

Fill_TRIP            ; numbers daily run

  movlw b'01001101'  ;  MSB "t"
  movwf IND01
  movfw aux_100k
  call  SEG7
  movwf IND02
  movfw aux_010k
  call  SEG7
  movwf IND03
  movfw aux_001k
  call  SEG7
  movwf IND04
  movfw aux_k100
  call  SEG7
  movwf IND05
  movfw aux_k010
  call  SEG7
  movwf IND06
  bcf   IND04,0     ; Decimal point after digit 5

Fill_TEXT           ; word CLEAr

			   ;ebfdacg   zero lights the segment

  movlw b'11111111'
  movwf IND01
  movlw b'01000111' ;  C
  movwf IND02
  movlw b'01001111' ;  L 
  movwf IND03
  movlw b'01000101' ;  E
  movwf IND04
  movlw b'00010001' ;  A
  movwf IND05
  movlw b'01111101' ;  r
  movwf IND06
  return

Fill_NONE           ; put out all the bits

  movlw b'11111111' ;   a prolonged retention
  movwf IND01       ;   button in the full path
  movwf IND02
  movwf IND03
  movwf IND04
  movwf IND05
  movwf IND06
  return

ChAnod

;Service display (after each complete cycle of the reference clock 1.6 ms x 6 bits = 100 Hz)

        movlw   IND01-1
        movwf   FSR
        movlw   0x03
        andwf   PORTC,f      ; switched off discharge
        movlw   0xF8
        andwf   PORTA,f
        bsf     PORTA, RCPoint

        movlw   9            ; the calculation of the following numbers of Discharge
        decfsz  INDNO,f      ; cyclically
        movfw   INDNO        ; 9 8 7 6 5 4 3 2 1 and around 9 8 7 6 5 ...
        movwf   INDNO

        addwf   FSR,f        ; load combination of cathodes
        movfw   INDF         ; to the next level
        movwf   PORTB

        movfw   INDNO
        sublw   6
        btfss   STATUS,C
        goto    ANOD_SPD

        btfss   INDF,0         ; if the sign of "point of need" is reset, then turn round
        bcf     PORTA, RCPoint ; include point

        movfw   INDNO
        call    ANOD_C
        iorwf   PORTC,f        ; include the following anode discharge
        return

ANOD_SPD

        call    ANOD_A
        iorwf   PORTA,f        ; include the following anode discharge
        return

; Came from the tick timer dimensional (was 100 ms)

DO_TICK

  bcf     PIR1,TMR2IF        ; reset interrupt flag
  decfsz  cLCNT,f
  return

; Over another small counter

  movf    cHCNT,f            ; a big check to the counter
  btfsc   STATUS,Z           ; if cHCNT = 0
  goto    ResetCNTS          ; it goes counter to initialize a new count

  movf    iLCNT,w
  decfsz  cHCNT,f            ; cHCNT=cHCNT-1
  movlw   0                  ; if <> 0 then cLCNT = 256
  movwf   cLCNT              ;  =0,  =iLCNT
  return

ResetCNTS

  movf    iHCNT,w            
  movwf   cHCNT              ; cHCNT=iHCNT
  clrf    cLCNT              ; cLCNT=256
  call    FILL_SPD
; call    FILL_VB
; Reset for the new measurement

  movlw   d'10'              
  movwf   HspDIG
  movwf   DspDIG
  movwf   EspDIG

; ***

  movlw   1                  ; was 8
  movwf   PreDIG
  return

; Increment counters

DO_INCR              ; 1 2 3 4 5 6 7 8 9 10

  movlw  d'10'       ; 10 bits for a full run 999,999 kilometers (see). 999 m + IPM (not                        	               ; visible)
  movwf  cntr2
  movlw  tot_prev-1      
  call   CH_CNTR     ; 123 45 June 7
  movlw  7           ; 7 bits to 999 km daily .99 (visible) 9m + IPM (not visible)
  movwf  cntr2
  movlw  aux_prev-1      
  call   CH_CNTR

  movlw  4           ; first three digits speedometer
  movwf  cntr2
  movlw  PreDIG-1
  movwf  FSR
; ***
  movlw  1              ;  was 8
  call   CH_LOOP

  call   FILL_VB     ; updated the code in the cathode buffer indicator
; call   FILL_SPD
  bcf    INTCON,INTF ; dropped the flag of external interrupt
  return

CH_CNTR

  movwf  FSR
  movf   IPM,w       ; pre-Meter IPM (impacts per meter)

CH_LOOP

  incf   FSR,f
  decfsz INDF,f
  return

  movwf  INDF
  movlw  d'10'       ; for all the other bits of the counter
  decfsz cntr2,f
  goto   CH_LOOP
  return

PowerDown

  call WRITE_EEPROM  ; record counts in non-volatile memory
                     ; And the word ENTRY in the buffer indicator
                     ; Ebfdacg zero bit in the segment lights
  movlw b'01111101'  ;  r
  movwf IND01
  movlw b'00000101'  ;  e
  movwf IND02
  movlw b'01101101'  ;  c
  movwf IND03
  movlw b'01101001'  ;  o
  movwf IND04
  movlw b'01111101'  ;  r
  movwf IND05
  movlw b'00101001'  ;  d 
  movwf IND06

SDeadLoop

  movlw  D'255'
  movwf  cntr2
  bcf    INTCON,T0IF  ; reset the timer

DeadLoop

  btfss  INTCON,T0IF
  goto   DeadLoop   
  call   ChAnod
  decfsz cntr2,f
  goto   DeadLoop-1

; goto SDeadLoop

  btfsc  PORTC,RCPower  ; if power is not restored (0), bypassing the return
  goto   PWRRestoted    ; restored if (1), then return 

; All power disconnect

  bcf    PORTC,RCSwitch
  goto   SDeadLoop

PWRRestoted

  call   FILL_VB    
  bsf    PORTC,RCSwitch ; will again include
  goto   PowerRise

READ_EEPROM  ; load counters from the nonvolatile memory

   movlw  d'18'
   movwf  cntr2
   movlw  tot_prev
   movwf  FSR

RD_LOOP

   movfw  FSR
   addlw  -tot_prev

   bsf   STATUS,RP1  ; Bank 2 - 0 at the entrance to the bank
   movwf EEADR
   bsf   STATUS,RP0  ; Bank 3
   bcf   EECON1,EEPGD
   bsf   EECON1,RD
   bcf   STATUS,RP0  ; Bank 2
   movfw EEDATA

   bcf    STATUS,RP1 ; Bank 0
   movwf  INDF
   incf   FSR,f
   decfsz cntr2,f
   goto   RD_LOOP
   return

WRITE_EEPROM  ; saving counters to non-volatile memory

   movlw  d'17'
   movwf  cntr2       ; cntr2 = 15
   movlw  tot_prev
   movwf  FSR         ; FSR = @ tot_prev = RAM address registers

WR_LOOP

   movfw  FSR
   addlw  -tot_prev   ; W = 0, 1, ... , 14 = EEPROM address registers

; Procedure records in EEPROM bytes

   bsf    STATUS,RP1  ; Bank 2 
   movwf  EEADR       ; Transferring W in EEADR
   bcf    STATUS,RP1  ; Bank 0
   movfw  INDF        ; We bring in W register the contents of RAM
   bsf    STATUS,RP1  ; Bank 2
   movwf  EEDATA      ; From W at EEDATA
   bsf    STATUS,RP0  ; Bank 3
   bcf    EECON1,EEPGD; select the EEPROM
   bsf    EECON1,WREN ; Allow entry
   movlw  h'55'       ; ** Required **
   movwf  EECON2      ; ** procedure **
   movlw  h'AA'       ; ** without **
   movwf  EECON2      ; ** Comments **
   bsf    EECON1,WR   ; command to start recording
   btfsc  EECON1,WR   ; loop, waiting for the completion of recording
   goto   $-1         ; repeat
   bcf    EECON1,WREN
   bcf    STATUS,RP1
   bcf    STATUS,RP0  ; bank 0   

   incf   FSR,f       ; FSR = @tot_prev +1, +2, ..., + 15
   decfsz cntr2,f
   goto   WR_LOOP     ; repeat 17 times
   return

CLR_LEAD0

   movf   HspDIG,w
   sublw  d'10'
   btfss  STATUS,Z
   return
   movlw  b'11111111'
   movwf  INDS1
   movf   DspDIG,w
   sublw  d'10'
   btfss  STATUS,Z
   return
   movlw  b'11111111'
   movwf  INDS2
   return

PROLOG

        clrf    IND01
        clrf    IND02
        clrf    IND03
        clrf    IND04
        clrf    IND05
        clrf    IND06
        clrf    INDS1
        clrf    INDS2
        clrf    INDS3
        clrf    cLCNT
        movlw   3
        movwf   cHCNT

PRO_LOOP

        btfss   INTCON,T0IF  
	  goto    PRO_LOOP   
        call    ChAnod 
        bcf     INTCON,T0IF  ; reset the timer
        decfsz  cLCNT,f
        goto    PRO_LOOP
        decfsz  cHCNT,f
        goto    PRO_LOOP
        return

org 0x2100

; Numbers by default (remain in place! Order is important!)
; In the EEPROM are stored as a 10-s
; Full mileage
; ***
eet_prev de d'06'   ; preliminary invisible
eet_k001 de d'10'-0
eet_k010 de d'10'-0
eet_k100 de d'10'-0 ; bits are displayed below
eet_001k de d'10'-0 ; 1 mile
eet_010k de d'10'-0
eet_100k de d'10'-0
eet_001t de d'10'-5
eet_010t de d'10'-9
eet_100t de d'10'-0 ; 100 000 km

; Daily mileage
; ***
eea_prev de d'06'   ; preliminary invisible
eea_k001 de d'10'-0
eea_k010 de d'10'-0 ; 10 m
eea_k100 de d'10'-0
eea_001k de d'10'-0 ; 1 mile
eea_010k de d'10'-0
eea_100k de d'10'-0 ; 100 km

; And the number of pulses at 1 meter
; ***
eeIPM    de d'06'

end			  ; end of the program

I think what I need to modify in this area:

Code:
; Came from the tick timer dimensional (was 100 ms)

DO_TICK

  bcf     PIR1,TMR2IF        ; reset interrupt flag
  decfsz  cLCNT,f
  return

; Over another small counter

  movf    cHCNT,f            ; a big check to the counter
  btfsc   STATUS,Z           ; if cHCNT = 0
  goto    ResetCNTS          ; it goes counter to initialize a new count

  movf    iLCNT,w
  decfsz  cHCNT,f            ; cHCNT=cHCNT-1
  movlw   0                  ; if <> 0 then cLCNT = 256
  movwf   cLCNT              ;  =0,  =iLCNT
  return

ResetCNTS

  movf    iHCNT,w            
  movwf   cHCNT              ; cHCNT=iHCNT
  clrf    cLCNT              ; cLCNT=256
  call    FILL_SPD
; call    FILL_VB
; Reset for the new measurement

  movlw   d'10'              
  movwf   HspDIG
  movwf   DspDIG
  movwf   EspDIG

; ***

  movlw   1                  ; was 8
  movwf   PreDIG
  return

; Increment counters

DO_INCR              ; 1 2 3 4 5 6 7 8 9 10

  movlw  d'10'       ; 10 bits for a full run 999,999 kilometers (see). 999 m + IPM (not                        	               ; visible)
  movwf  cntr2
  movlw  tot_prev-1      
  call   CH_CNTR     ; 123 45 June 7
  movlw  7           ; 7 bits to 999 km daily .99 (visible) 9m + IPM (not visible)
  movwf  cntr2
  movlw  aux_prev-1      
  call   CH_CNTR

  movlw  4           ; first three digits speedometer
  movwf  cntr2
  movlw  PreDIG-1
  movwf  FSR
; ***
  movlw  1              ;  was 8
  call   CH_LOOP

  call   FILL_VB     ; updated the code in the cathode buffer indicator
; call   FILL_SPD
  bcf    INTCON,INTF ; dropped the flag of external interrupt
  return

CH_CNTR

  movwf  FSR
  movf   IPM,w       ; pre-Meter IPM (impacts per meter)

CH_LOOP

  incf   FSR,f
  decfsz INDF,f
  return

  movwf  INDF
  movlw  d'10'       ; for all the other bits of the counter
  decfsz cntr2,f
  goto   CH_LOOP
  return

Any suggestions?
 
Thinking this bit
Code:
; Check the sensor
 
        btfsc   INTCON,INTF  ; if 0 (no signal from the sensor), by bypassing
        call    DO_INCR      ; and if one, then go to increase the counter

Probably, but it must advance another counter by one after a set number of impulses from the sensor, correct?
 
Look at DO_INCR. It does several things not sure exactly what you want or why.

If you do not understand what it is doing it is time to start looking at opcodes.

I am either not man enough or foolish enough to program in PIC asm. Good luck.
 
...not sure exactly what you want or why...

Pretty sure I said what I was trying to do and why in my first post. I would have thought that someone on here had a decent enough understanding of code to explain it to me. Maybe I'd be better off using a whole bunch of counter IC's to build this since I can understand those.
 
I don't know any programming actually. I was going through some tutorials before I found this circuit. I figured it would be easier to try to modify this one than to start from scratch. Between the tutorials and messing around with this circuit I've figured a few things out but not everything.
 
Yes the code that actually counts the sensor pulses is:
; Check the sensor

btfsc INTCON,INTF ; if 0 (no signal from the sensor), by bypassing
call DO_INCR ; and if one, then go to increase the counter
You will want to increment the .01 mile display everytime the sensor sends 80 pulses.
Also you definitely need to change the schematic so that the sensor is fed into Pin 21(RB0).
 
Set up a variable call it newCnt and pre-load a value of decimal 80. Everytime the sensor produces a pulse decrement this counter. When the counter (newCnt) value is zero
then increment your value that displays the mileage.
 
I will try to write the small piece of code for you and tell you where to insert it in the code you have. It may take me a couple of days to get it done.
 
Replace the code labeled ;check the sensor with this
; Check the sensor

btfss INTCON,INTF ; if 0 (no signal from the sensor), by bypassing
goto Skipit ;jump over the next piece of code if no sensor signal
decfsz newCntr,1 ;wait for 80 sensor pulses before incrementing
call DO_INCR ; and if one, then go to increase the counter
Skipit: nop ; used as a way to skip over the added code

Also you need to modify the DO_INCR subroutine as shown

; Increment counters

DO_INCR ; 1 2 3 4 5 6 7 8 9 10

movlw d'10' ; 10 bits for a full run 999,999 kilometers (see). 999 m + IPM (not ; visible)
movwf cntr2
movlw tot_prev-1
call CH_CNTR ; 123 45 June 7
movlw 7 ; 7 bits to 999 km daily .99 (visible) 9m + IPM (not visible)
movwf cntr2
movlw aux_prev-1
call CH_CNTR

movlw 4 ; first three digits speedometer
movwf cntr2
movlw PreDIG-1
movwf FSR
; ***
movlw 1 ; was 8
call CH_LOOP

call FILL_VB ; updated the code in the cathode buffer indicator
; call FILL_SPD
bcf INTCON,INTF ; dropped the flag of external interrupt
movlw d'80' ;reload the new counter
movwf newCntr
return

Finally you need to set up this new variable named newCntr and preload it with a value of 80 decimal
First create a new variable at location 0x49
put this code right after HspDIG equ 0x48
newCntr equ 0x49

then preload it before MAIN_LOOP as shown

movlw d'80'
movwf newCntr
MAIN_LOOP

Hope this helps!
 
  • Like
Reactions: 3v0
Replace the code labeled ;check the sensor with this
; Check the sensor

btfss INTCON,INTF ; if 0 (no signal from the sensor), by bypassing
goto Skipit ;jump over the next piece of code if no sensor signal
decfsz newCntr,1 ;wait for 80 sensor pulses before incrementing
call DO_INCR ; and if one, then go to increase the counter
Skipit: nop ; used as a way to skip over the added code

Also you need to modify the DO_INCR subroutine as shown

; Increment counters

DO_INCR ; 1 2 3 4 5 6 7 8 9 10

movlw d'10' ; 10 bits for a full run 999,999 kilometers (see). 999 m + IPM (not ; visible)
movwf cntr2
movlw tot_prev-1
call CH_CNTR ; 123 45 June 7
movlw 7 ; 7 bits to 999 km daily .99 (visible) 9m + IPM (not visible)
movwf cntr2
movlw aux_prev-1
call CH_CNTR

movlw 4 ; first three digits speedometer
movwf cntr2
movlw PreDIG-1
movwf FSR
; ***
movlw 1 ; was 8
call CH_LOOP

call FILL_VB ; updated the code in the cathode buffer indicator
; call FILL_SPD
bcf INTCON,INTF ; dropped the flag of external interrupt
movlw d'80' ;reload the new counter
movwf newCntr
return

Finally you need to set up this new variable named newCntr and preload it with a value of 80 decimal
First create a new variable at location 0x49
put this code right after HspDIG equ 0x48
newCntr equ 0x49

then preload it before MAIN_LOOP as shown

movlw d'80'
movwf newCntr
MAIN_LOOP

Hope this helps!

Thanks man! Again I really appreciate you taking the time to help me. I going to try to mess it around with the circuit this weekend and I'll let you know what happens.
 
Finally got a chance to make the changes. Unfortunately there was no change in the circuit's operation :(

To test, I made a separate counter to count the pulses from my logic pulser. Before I made the changes to the code I put a 0.5Hz signal to the input of the counter and the speedo/odo circuit . After 60 pulses the odometer display changed from "000.00" to "000.01" and after I reprogrammed with the changed code it was exactly the same. I'm going to try to e-mail the original author to see if he can help.

I appreciate your efforts circuitspecialists.
 
On the off chance I put stuff in the wrong place...

Code:
 ;******************************************

             ;*     2 ? 1 ????-???-???? PIC 16F873     *

             ;******************************************

;=====================================================================================



; ????? 10 ???

; Hopefully this works for 8000 pulses/mile





 list p = 16F876
 #include <P16F876.INC>
 

 __config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF



; ?????????



RCSwitch equ 1    ; RC1

RCPower  equ 0    ; RC0

RCButton equ 3    ; RA3

RCPoint  equ 4    ; RA4



; ??????????

; ????? ????????? ????????

INDNO equ 0x20



; ????? ??????? ????????, ??????? ? ???? ?????????? ?????????

IND01 equ 0x21

IND02 equ 0x22

IND03 equ 0x23

IND04 equ 0x24

IND05 equ 0x25

IND06 equ 0x26

; ????? ??????? ??????????

INDS1 equ 0x27

INDS2 equ 0x28

INDS3 equ 0x29



; ???????? ??????? ??????? ???????

tot_prev equ 0x2A 

tor_k001 equ 0x2B

tot_k010 equ 0x2C

tot_k100 equ 0x2D

tot_001k equ 0x2E

tot_010k equ 0x2F

tot_100k equ 0x30

tot_001t equ 0x31

tot_010t equ 0x32

tot_100t equ 0x33



; ?????????????? ??????? ????????? ???????

aux_prev equ 0x34

aux_k001 equ 0x35

aux_k010 equ 0x36

aux_k100 equ 0x37

aux_001k equ 0x38

aux_010k equ 0x39

aux_100k equ 0x3A



IPM      equ 0x3B

SCR_MODE equ 0x3C

BTN_MODE equ 0x3D

BTN_CNTR equ 0x3E

BTN_STAT equ 0x3F



cntr2    equ 0x40

iHCNT    equ 0x41

iLCNT    equ 0x42

cHCNT    equ 0x43

cLCNT    equ 0x44



PreDIG   equ 0x45

EspDIG   equ 0x46

DspDIG   equ 0x47

HspDIG   equ 0x48
newCntr  equ 0x49


; BTN_MODE - ?????????, ??? ????????? ? ??????? 

;   00 - ?????? ????????? ? ?????

;   01 - ??????? (??? ????)

;   11 - ????????? ?????

;   10 - ?????????? (??? ?????)



; SCR_MODE - ????????? ????????? FILL_VB, ??? ????????? ??????????

;   0 - ?????? ??????

;   1 - ????????

;   2 - ?????

;   3 - ????? ?????



; ?????????

        org     0x00

        goto    START



; ????????????? ????? ? ??? 7-??????????? ??????????

SEG7            ; ? ????????? ?? ???? ????????, ? (10-????????)

  sublw d'010'  ; ????????? ????????

  andlw 0x0F    ; ?? ?????? ??????

  addwf PCL,f

;         ebfdacg      ???? ? ???? ???????? ???????

  retlw b'00000011' ;  0

  retlw b'10111011' ;  1

  retlw b'00100101' ;  2

  retlw b'10100001' ;  3

  retlw b'10011001' ;  4

  retlw b'11000001' ;  5

  retlw b'01000001' ;  6

  retlw b'10110011' ;  7

  retlw b'00000001' ;  8

  retlw b'10000001' ;  9

  retlw b'11110111' ; 10

  retlw b'10111111' ; 11

  retlw b'11111011' ; 12

  retlw b'11101111' ; 13

  retlw b'01111111' ; 14

  retlw b'11011111' ; 15



; ?????????? ???? ????????? ??????? ?? ?????? ????????? ?????

ANOD_C

  andlw 0x07    ;?? ?????? ??????

  addwf PCL,f

;         123465       ??????? ? ???? ???????? ??????

  retlw b'00000000' ;  0

  retlw b'10000000' ;  1

  retlw b'01000000' ;  2

  retlw b'00100000' ;  3

  retlw b'00010000' ;  4

  retlw b'00000100' ;  5

  retlw b'00001000' ;  6

  retlw b'00000000' ;  7 



; ?????????? ???? ????????? ??????? ?? ?????? ????????? ?????

ANOD_A

  andlw 0x03    ;?? ?????? ??????

  addwf PCL,f

;              321  ??????? ? ???? ???????? ??????  1-????? 2-??????? 3-???????

  retlw b'00010000' ;  0

  retlw b'00010001' ;  1

  retlw b'00010010' ;  2

  retlw b'00010100' ;  3



START

        bcf     STATUS, RP0     ; ???? 0

        bcf     STATUS, RP1

        clrf    T2CON

        clrf    TMR0

        clrf    TMR2

        clrf    INTCON

        clrf    PORTA

        clrf    PORTB

        clrf    PORTC

        bsf     STATUS, RP0     ; ???? 1

        movlw   0x06            ; ??? ???? ? ?? ?????

        movwf   ADCON1

        movlw   b'00001000'

        movwf   TRISA           ; RA3 - ??????, ????????? ?????

        movlw   b'00000001'

        movwf   TRISB           ; RB0 - ??????, ????????? ?????

        movlw   b'00000001'

        movwf   TRISC           ; RC0 - ?????????, ????????? ?????

; ???????? ????????????? ?????????, TMR0 ?? ?????????? ???? ? ????????????? 16 (4 ms ?? ?????)

		movlw   b'01000011'

		movwf   OPTION_REG	

; ???????? TIMER2

        clrf    PIE1

        movlw   d'249'          ; ??? ?????? 10 ??? ??????? clock = Fosc/4 = 2,5 ???  0,4 ???

        movwf   PR2             ; ??????? ??????? TIMER2 = 250 clock = 100 ??? ?? ????

                                ;   ???? = 100 ??? * 1(PRE) * 1 (POST) = 100 ??? 

		bcf     STATUS,RP0     ; ???? 0



        movlw   b'00000100'     ; none:7  (POST-1):6-3   On/Off:2  PRE: 1-0   

        movwf   T2CON           ;          b0000 = 1:1     1=On     b00 = 1



        clrf    PIR1



        bsf     PORTC, RCSwitch

        call    READ_EEPROM



        movlw   d'10'

        movwf   HspDIG

        movwf   DspDIG

        movwf   EspDIG

; ***

        movlw   1                  ; ???? 8

        movwf   PreDIG

        movlw   9

        movwf   INDNO



        clrf    TMR0

        bcf     INTCON,T0IF  ; ???????? ??????



        call    PROLOG

        clrf    BTN_MODE  

        clrf    SCR_MODE  

        call    FILL_VB   

        call    FILL_SPD



; ***

        movlw  d'23'            ; ???? d'37' ??? 30 ???/?

        movwf iHCNT

; ***

        movlw d'112'          ; ???? d'128'  ??? 30 ???/?

        movwf iLCNT



        clrf    cHCNT

        movlw   1

        movwf   cLCNT

     	movlw d'80'
	movwf newCntr

MAIN_LOOP



; Check the power

        btfss   PORTC,RCPower; ??????? ??????????, ???? 1

        goto    PowerDown

PowerRise

; Dimensional check the timer


        btfsc   PIR1,TMR2IF  ; ???? 0 (??? ??????? ?? TIMER2), ?? ?????

        call    DO_TICK      ; ? ???? 1, ?? ???? ??????????? ????????



; Check the sensor

      btfss INTCON,INTF 	; if 0 (no signal from the sensor), by bypassing
	goto Skipit 		;jump over the next piece of code if no sensor signal
	decfsz newCntr,1 		;wait for 80 sensor pulses before incrementing
	call DO_INCR 		; and if one, then go to increase the counter
	Skipit: nop 		; used as a way to skip over the added code



; ?????????????? ????????? ???????

;        btfsc   PORTB,0

;        bsf     PORTA,5

;        btfss   PORTB,0

;        bcf     PORTA,5



; ????????? ?????? ??? ???????????? ?????????

        btfss   INTCON,T0IF  ; ???? ?????? ???????? ??????, ?? ???? ?????? ??????

		goto    MAIN_LOOP    ;  ????? ????????? ???????? ? ?????



; ???, ??? ????, ??????????? 1 ??? ? 1,6 ?? (?? 10???)

        call    ChkButton    ; ????????? ?????

        call    ChAnod       ; ???????????? ???????? ??????????



        bcf     INTCON,T0IF  ; ???????? ?????? 

        goto    MAIN_LOOP







; ????????? ?????? ? ?????????????

ChkButton

        rlf     BTN_MODE,f    ; ?????? ??? BTN_MODE ???????? ?? 1 ??? ?????

        bcf     BTN_MODE,0    ; ? ? 0? ??? ???????

        btfss   PORTA, RCButton  ;   0, ???? ?????? ??????

        bsf     BTN_MODE,0       ;   1, ???? ?????

        movf    BTN_MODE,w      ; ????? ???????? ??????? ??? ????

        andlw   3             ; ? ?? ??? ???????? ??????? ?????????

        addwf   PCL,f         ;

        goto    Btn_UpUp      ;  00 - ?????? ???? ? ???????? ??????? (????????? ??????)

        goto    Btn_UpDn      ;  01 - ??????? ?????? ????  (??????)

        goto    Btn_DnUp      ;  10 - ??????? ????? ?????  (?????????)

        goto    Btn_DnDn      ;  11 - ???? ? ???????? ????? (????????? ???????)



Btn_UpDn ; ??????

        clrf    BTN_CNTR      ; ? ?????? ??????? ??????

        clrf    BTN_STAT      ; ???????? ???????? ??????? ?????????

        goto    Btn_UpUp

Btn_DnDn ; ??????????           ?????????? ??????????? ???????

        incfsz  BTN_CNTR,f    ; ????? ??????? ????????? ?? 256 (0,4???)

        goto    TestSTATUS

        incf    BTN_STAT,f    ; ??????? ??? ??????? ?? ?????? ??????

TestSTATUS                    ; ? ??????????? ?? ??????? ?????????

        btfss   BTN_STAT,2    ;  0, 1 , 2, 3   ( ?? 0,4   ?? 0,8   ?? 1,2  ?? 1,6 ???)

        goto    Btn_UpUp

        decf    BTN_STAT,f    ; ???? ??? ????? ?? 4, ?? ?????? ??? ? 3

        bsf     SCR_MODE,1    ; ??????? ????? ??????????? ?????? ?? ??????????

        call    FILL_VB       ; ?????? ??? ??????? ?? ?????? ??????

        goto    Btn_UpUp      ;        ??? ????????? ?? ?????? ????? ?????

Btn_DnUp ; ?????????    

        btfss   SCR_MODE,1    ; ???? ??? ???????? ?????

        goto    SwitchMode    ;   ?? ???? ?? ???????????? ?????? ???????????

TestReset 

        bcf     SCR_MODE,1    ; ??? ???????? ?????

        btfss   SCR_MODE,0    ; ??????? ?????????? ????? ?????????? ??????/????????

        goto    ODOmode       

        movf    IPM,w         ; ? ??? ????????? ????? ????

        movwf   aux_prev      ; ??????? ????? ???????? ? 000.00

        movlw   d'10'

        movwf   aux_100k

        movwf   aux_010k

        movwf   aux_001k

        movwf   aux_k100

        movwf   aux_k010

        movwf   aux_k001

        goto    ODOmode

SwitchMode                    ; ???????????? ?????? ?????????? ??????/????????

        movlw   1

        xorwf   SCR_MODE,f        

ODOmode                       ; ?????????????? ?????? ??????????

        call    FILL_VB

Btn_UpUp                      ; ???? ?????? ????????? ?? ?????, ?? ?????? ?????? ?? ????

        return



FILL_SPD    ; ????????? ????? ??????? ??????????? ?????? ? ??????????

  movf    HspDIG,w

  call    SEG7       ; ????? ????? 

  movwf   INDS1      ;   

  movf    DspDIG,w

  call    SEG7       ; ????? ????????

  movwf   INDS2

  movf    EspDIG,w   ; ????? ?????? ??????

  call    SEG7

  movwf   INDS3

  call    CLR_LEAD0  ; ???????? ?????????? ????

  return



; ?????????? ??????????? ?????? ?????????

FILL_VB

  movfw  SCR_MODE    ; ????????, ??? ????????? ????? ??????????

  andlw  b'00000011' ; ? ??????????? ?? ???????? ?????????? SRC_MODE

  addwf  PCL,f

  goto   Fill_ODOM

  goto   Fill_TRIP

  goto   Fill_NONE

  goto   Fill_TEXT



Fill_ODOM            ; ????????? ?????

  movfw tot_100t     ; ??????? ??????? ???????

  call  SEG7

  movwf IND01

  movfw tot_010t

  call  SEG7

  movwf IND02

  movfw tot_001t

  call  SEG7

  movwf IND03

  movfw tot_100k

  call  SEG7

  movwf IND04

  movfw tot_010k

  call  SEG7

  movwf IND05

  movfw tot_001k

  call  SEG7

  movwf IND06

  return



Fill_TRIP            ; ??????? ????????? ???????

  movlw b'11111111'  ;  ??????? ?????? ??????

  movwf IND01

  movfw aux_100k

  call  SEG7

  movwf IND02

  movfw aux_010k

  call  SEG7

  movwf IND03

  movfw aux_001k

  call  SEG7

  movwf IND04

  movfw aux_k100

  call  SEG7

  movwf IND05

  movfw aux_k010

  call  SEG7

  movwf IND06

  bcf   IND04,0     ; ????????? ??????? "????? ?????" ??? ??????? ???????

  return



Fill_TEXT           ; ????? ?????

;         ebfdacg   ???? ????????

  movlw b'11111111'

  movwf IND01

  movlw b'01000111' ;  ?

  movwf IND02

  movlw b'01000001' ;  ? 

  movwf IND03

  movlw b'00010101' ;  ?

  movwf IND04

  movlw b'00000011' ;  0

  movwf IND05

  movlw b'01000111' ;  ?

  movwf IND06

  return



Fill_NONE           ; ???????? ??? ???????

  movlw b'11111111' ;   ??? ??? ?????????? ?????????

  movwf IND01       ;   ?????? ? ?????? ??????? ???????

  movwf IND02

  movwf IND03

  movwf IND04

  movwf IND05

  movwf IND06

  return



ChAnod

;???????????? ????????? (?????? ??? ????? ??????? ???????? ??????? ????? 1,6?? ? 6 ???????? = 100??)

        movlw   IND01-1

        movwf   FSR

        movlw   0x03

        andwf   PORTC,f      ; ????????? ??????

        movlw   0xF8

        andwf   PORTA,f

        bsf     PORTA, RCPoint



        movlw   9            ; ?????????? ?????? ?????????? ???????

        decfsz  INDNO,f      ; ??????????

        movfw   INDNO        ;   9 8 7 6 5 4 3 2 1  ? ?? ?????  9 8 7 6 5 ...

        movwf   INDNO



        addwf   FSR,f        ; ????????? ?????????? ???????

        movfw   INDF         ; ??? ?????????? ???????

        movwf   PORTB



        movfw   INDNO

        sublw   6

        btfss   STATUS,C

        goto    ANOD_SPD



        btfss   INDF,0         ; ???? ??????? "????? ?????" ???????, ?? ????? ?????????

        bcf     PORTA, RCPoint ; ???????? ?????



        movfw   INDNO

        call    ANOD_C

        iorwf   PORTC,f        ; ???????? ???? ?????????? ???????

        return



ANOD_SPD

        call    ANOD_A

        iorwf   PORTA,f        ; ???????? ???? ?????????? ???????    

        return



; ?????? ??? ?? ??????? ??????? (?????? 100 ???)

DO_TICK

  bcf     PIR1,TMR2IF        ; ???????? ???? ??????????

  decfsz  cLCNT,f

  return

  ; ?????????? ????????? ????????? ???????

  movf    cHCNT,f            ; ????????? ??????? ???????

  btfsc   STATUS,Z           ; ???? cHCNT=0

  goto    ResetCNTS          ;    ?? ???? ?????????????? ???????? ?? ????? ??????

  

  movf    iLCNT,w

  decfsz  cHCNT,f            ; cHCNT=cHCNT-1

  movlw   0                  ; ???? <>0, ?? cLCNT=256

  movwf   cLCNT              ;       =0,         =iLCNT

  return



ResetCNTS

  movf    iHCNT,w            

  movwf   cHCNT              ; cHCNT=iHCNT

  clrf    cLCNT              ; cLCNT=256

  call    FILL_SPD

;  call    FILL_VB

  ; ????????? ??? ?????? ??????

  movlw   d'10'              

  movwf   HspDIG

  movwf   DspDIG

  movwf   EspDIG

; ***

  movlw   1                  ; ???? 8

  movwf   PreDIG

  return



; Increment counters

DO_INCR ; 1 2 3 4 5 6 7 8 9 10

	movlw d'10' 		; 10 bits for a full run 999,999 kilometers (see). 999 m + IPM (not ; visible)
	movwf cntr2
	movlw tot_prev-1
	call CH_CNTR 		; 123 45 June 7
	movlw 7			; 7 bits to 999 km daily .99 (visible) 9m + IPM (not visible)
	movwf cntr2
	movlw aux_prev-1
	call CH_CNTR

	movlw 4 		; first three digits speedometer
	movwf cntr2
	movlw PreDIG-1
	movwf FSR
	; ***
	movlw 1 		; was 8
	call CH_LOOP

	call FILL_VB 		; updated the code in the cathode buffer indicator
	;call FILL_SPD
	bcf INTCON,INTF 	; dropped the flag of external interrupt
	movlw d'80' 		;reload the new counter
	movwf newCntr
	return

CH_CNTR

  movwf  FSR

  movf   IPM,w       ; ??? ???????????????? ???????? ?????? IPM (impacts per meter)

CH_LOOP

  incf   FSR,f

  decfsz INDF,f

  return

  movwf  INDF

  movlw  d'10'       ; ??? ???? ????????? ???????? ????????

  decfsz cntr2,f

  goto   CH_LOOP

  return



PowerDown

  call WRITE_EEPROM  ; ?????????? ???????? ? ????????????????? ??????



; ????? ?????? ? ????? ??????????

;         ebfdacg  ???? ? ???? ???????? ???????

  movlw b'10100001' ;  3

  movwf IND01

  movlw b'00010001' ;  A

  movwf IND02

  movlw b'00010011' ;  ?

  movwf IND03

  movlw b'00001011' ;  ?

  movwf IND04

  movlw b'01000111' ;  ?

  movwf IND05

  movlw b'01001001' ;  ? 

  movwf IND06

  

SDeadLoop

  movlw  D'255'

  movwf  cntr2

  bcf    INTCON,T0IF  ; ???????? ??????

DeadLoop

  btfss  INTCON,T0IF

  goto   DeadLoop   

  call   ChAnod

  decfsz cntr2,f

  goto   DeadLoop-1



; goto SDeadLoop



  btfsc  PORTC,RCPower  ; ???? ??????? ?? ?????????????? (0), ?? ????? ????????

  goto   PWRRestoted    ; ???? ?????????????? (1), ?? ???????????? 

; ??? ????????? ???????

  bcf    PORTC,RCSwitch

  goto   SDeadLoop



PWRRestoted

  call   FILL_VB    

  bsf    PORTC,RCSwitch ; ???????? ????? ????????

  goto   PowerRise





READ_EEPROM  ; ???????? ????????? ?? ????????????????? ??????

   movlw  d'18'

   movwf  cntr2

   movlw  tot_prev

   movwf  FSR

RD_LOOP

   movfw  FSR

   addlw  -tot_prev



   bsf   STATUS,RP1  ; ???? 2  - ?? ????? ???? 0  

   movwf EEADR

   bsf   STATUS,RP0  ; ???? 3

   bcf   EECON1,EEPGD

   bsf   EECON1,RD

   bcf   STATUS,RP0  ; ???? 2

   movfw EEDATA

   

   bcf    STATUS,RP1 ; ???? 0

   movwf  INDF

   incf   FSR,f

   decfsz cntr2,f

   goto   RD_LOOP

   return





WRITE_EEPROM  ; ?????????? ????????? ? ????????????????? ??????



   movlw  d'17'

   movwf  cntr2       ; cntr2 = 15

   movlw  tot_prev

   movwf  FSR         ; FSR = @tot_prev    = ?????? ????????? RAM

WR_LOOP

   movfw  FSR

   addlw  -tot_prev   ; W = 0, 1, ... , 14 = ?????? ????????? EEPROM 



;  ????????? ?????? ????? ? EEPROM

   bsf    STATUS,RP1  ; ???? 2 

   movwf  EEADR       ; ????????? W ? EEADR

   bcf    STATUS,RP1  ; ???? 0

   movfw  INDF        ; ??????? ? W ?????????? ???????? RAM

   bsf    STATUS,RP1  ; ???? 2

   movwf  EEDATA      ; ?? W ? EEDATA

   bsf    STATUS,RP0  ; ???? 3

   bcf    EECON1,EEPGD; ???????? EEPROM

   bsf    EECON1,WREN ; ????????? ??????

   movlw  h'55'       ; ** ???????????? **

   movwf  EECON2      ; **   ?????????  **

   movlw  h'AA'       ; **      ???     **

   movwf  EECON2      ; ** ???????????? **

   bsf    EECON1,WR   ; ??????? ?????? ??????

   btfsc  EECON1,WR   ; ???? ???????? ?????????? ??????

   goto   $-1         ; ?????????

   bcf    EECON1,WREN

   bcf    STATUS,RP1

   bcf    STATUS,RP0  ; ???? 0   



   incf   FSR,f       ; FSR = @tot_prev +1, +2, ..., + 15

   decfsz cntr2,f

   goto   WR_LOOP     ; ????????? 17 ???



   return



CLR_LEAD0

   movf   HspDIG,w

   sublw  d'10'

   btfss  STATUS,Z

   return

   movlw  b'11111111'

   movwf  INDS1

   movf   DspDIG,w

   sublw  d'10'

   btfss  STATUS,Z

   return

   movlw  b'11111111'

   movwf  INDS2

   return



PROLOG

        clrf    IND01

        clrf    IND02

        clrf    IND03

        clrf    IND04

        clrf    IND05

        clrf    IND06

        clrf    INDS1

        clrf    INDS2

        clrf    INDS3

        clrf    cLCNT

        movlw   3

        movwf   cHCNT

PRO_LOOP

        btfss   INTCON,T0IF  

		goto    PRO_LOOP   

        call    ChAnod 

        bcf     INTCON,T0IF  ; ???????? ?????? 

        decfsz  cLCNT,f

        goto    PRO_LOOP

        decfsz  cHCNT,f

        goto    PRO_LOOP

    return





 org 0x2100



; ????? ?? ?????????  ( ??????? ?? ??????! ??????? ?????!)

; ? EEPROM ??? ???????? ? ???? 10-?



; ?????? ??????

; ***

eet_prev de d'06'   ; ??????????????? ??????????????

eet_k001 de d'10'-0

eet_k010 de d'10'-0

eet_k100 de d'10'-0 ; ???????????? ??????? ????

eet_001k de d'10'-0 ; 1 ??

eet_010k de d'10'-0

eet_100k de d'10'-0

eet_001t de d'10'-5

eet_010t de d'10'-9

eet_100t de d'10'-0 ; 100 000 ??



;???????? ??????

; ***

eea_prev de d'06'   ; ??????????????? ??????????????

eea_k001 de d'10'-0

eea_k010 de d'10'-0 ; 10 ?

eea_k100 de d'10'-0

eea_001k de d'10'-0 ; 1 ??

eea_010k de d'10'-0

eea_100k de d'10'-0 ; 100 ??



; ????? ????????? ?? 1 ????

; ***

eeIPM    de d'06'



  end				;????? ?????????
 
Status
Not open for further replies.

Latest threads

Back
Top