Help with Tachometer Code

Status
Not open for further replies.

Nrets

New Member
I'm trying to modify a simple program to work with 7 segment displays and with a 16f628a.

The original code is commented in German, and the program was written for a 16f874.

I don't understand how this code ever reaches the 'Main'? It seems to me that this will never happen. Am I missing something?

Code:
; Programm fur digitale Drehzahlanzeige V1.0 mit 16F874
; (C) Johannes Walk
;
; Für PIC16F874
; Osc: Quartz, HS, 20MHz 30pF
; Mit Funktionstest und SPIKE-Unterdrückung
; Eingang: 100k auf 5,1V-ZD (0,5W) und 10nF gen GND in PORTA,0
; Ausgänge: ab PORTA,1 32 OUT's aufsteigend
; Anzeige: ab 0 RPM in 250 RPM-Schritten, aufsteigend, Balkenanz.
 
 LIST  P=PIC16F874
 
; Include file
 
 include <p16f874.inc>
 
DZ00 equ 0x70
DZ01 equ 0x71
DZ02 equ 0x72
DZ03 equ 0x73
TIMEREG1 equ 0x60
EINGREG  equ 0x61
 
 goto Definitionen
 
TEST
 clrf TIMEREG1
tests1
 call TESTT
 btfss PORTE,2
 goto tests1
tests2
 call TESTT
 btfsc PORTE,2
 goto tests2
 call RESET
 call DISPLAY
 RETURN
 
TESTT
 clrwdt
 btfss INTCON,2 ; Bit für TMR0-Überlauf, 1 wenn passiert
 RETURN
 bcf INTCON,2
 decfsz TIMEREG1,f
 RETURN
 movlw 0x60
 movwf TIMEREG1
 call ROTATE
 call DISPLAY
 RETURN
 
TIMER
 clrwdt
 btfss INTCON,2 ; Bit für TMR0-Überlauf, 1 wenn passiert
 RETURN
 bcf INTCON,2
 decfsz TIMEREG1,f
 RETURN
 movlw 0x92 ;3D=61(20MHz), Teilerfaktor für 0,05 sec (20,01Hz)
 movwf TIMEREG1
 call DISPLAY ; Wenn die Zeit rum ist: RESET...
 call RESET
 call ROTATE
 RETURN
 
EINGANG
 btfsc PORTA,0
 goto e01
e00 ;Eingang=0
 bcf EINGREG,0
 RETURN
e01 ;Eingang=1
 btfss EINGREG,0
 call FLANK
 bsf EINGREG,0
 RETURN
 
FLANK
 call ROTATE
 RETURN
 
ROTATE
 RLF DZ00,f
 bsf DZ00,0
 RLF DZ01,f
 RLF DZ02,f
 RLF DZ03,f
 RETURN
 
RESET
 clrf DZ00
 clrf DZ01
 clrf DZ02
 clrf DZ03
 RETURN
 
DISPLAY
 clrf PORTA
 btfss DZ00,0
 bsf PORTA,1
 btfss DZ00,1
 bsf PORTA,2
 btfss DZ00,2
 bsf PORTA,3
 btfss DZ00,3
 bsf PORTA,4
 btfss DZ00,4
 bsf PORTA,5
 clrf PORTB
 btfss DZ00,5
 bsf PORTB,0
 btfss DZ00,6
 bsf PORTB,1
 btfss DZ00,7
 bsf PORTB,2
 btfss DZ01,0
 bsf PORTB,3
 btfss DZ01,1
 bsf PORTB,4
 btfss DZ01,2
 bsf PORTB,5
 btfss DZ01,3
 bsf PORTB,6
 btfss DZ01,4
 bsf PORTB,7
 clrf PORTC
 btfss DZ01,5
 bsf PORTC,0
 btfss DZ01,6
 bsf PORTC,1
 btfss DZ01,7
 bsf PORTC,2
 btfss DZ02,0
 bsf PORTC,3
 btfss DZ02,1
 bsf PORTC,4
 btfss DZ02,2
 bsf PORTC,5
 btfss DZ02,3
 bsf PORTC,6
 btfss DZ02,4
 bsf PORTC,7
 clrf PORTD
 btfss DZ02,5
 bsf PORTD,0
 btfss DZ02,6
 bsf PORTD,1
 btfss DZ02,7
 bsf PORTD,2
 btfss DZ03,0
 bsf PORTD,3
 btfss DZ03,1
 bsf PORTD,4
 btfss DZ03,2
 bsf PORTD,5
 btfss DZ03,3
 bsf PORTD,6
 btfss DZ03,4
 bsf PORTD,7
 clrf PORTE
 btfss DZ03,5
 bsf PORTE,0
 btfss DZ03,6
 bsf PORTE,1
 btfss DZ03,7
 bsf PORTE,2
 RETURN
 
Definitionen ;   Allg. Grunddefinitionen
 clrw
 clrwdt
 BANKSEL TMR0
 clrf PORTA
 clrf PORTB
 clrf PORTC
 clrf PORTD
 clrf PORTE
 BANKSEL OPTION_REG
 movlw b'00000000'
 movwf ADCON0
 movlw b'00000111'
 movwf ADCON1
 movlw b'00000001'
 movwf TRISA
 movlw b'00000000'
 movwf TRISB
 movlw b'00000000'
 movwf TRISC
 movlw b'00000000'
 movwf TRISD
 movlw b'00000000'
 movwf TRISE
 clrf INTCON
 movlw b'00000011'
 movwf OPTION_REG
 clrwdt
 BANKSEL TMR0
 clrf PORTA
 clrf PORTB
 clrf PORTC
 clrf PORTD
 clrf PORTE
 clrf DZ00
 clrf DZ01
 clrf DZ02
 clrf DZ03
 clrf TIMEREG1
 call TEST
 
Main
 clrwdt
 call TIMER
 call EINGANG
 goto Main
 
 END
 
The code is unusual in that there is no ORG statement. There is a goto Definitionen at the start and the code there executes and falls through to main. There really should be a org 0x000 just before the goto Definitionen statement.
 
You will have big problems trying to convert that code to work on a 628. The 874 is a 28 pin device, the 628 is 18 pins.

To write a rev counter for a 628 would be possible but that code is not the place to start.

Mike.
 
You will have big problems trying to convert that code to work on a 628. The 874 is a 28 pin device, the 628 is 18 pins.

To write a rev counter for a 628 would be possible but that code is not the place to start.

Mike.

He has so many pins because he's using so many LEDs. I'm not going to be using the LEDs the way he did, I just need the counting code, then I'll convert it into a number somehow and multiplex 7 Segment displays (buy maybe this won't work because I'll need an interrupt, then the timing code is useless). I'd rather start with a small piece of inadequate code and add on to it, than try to tear apart much more complex code.
 
Hi for code for 16f628 tachometer look at
**broken link removed**

Regards
Les

EDIT:

I've seen this build but the ASM file is not available, which sucks if I want to make modifications.
 
Last edited:
The code is unusual in that there is no ORG statement. There is a goto Definitionen at the start and the code there executes and falls through to main. There really should be a org 0x000 just before the goto Definitionen statement.

How does it fall through to main? I don't see where it would ever hit main?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…