Code:
'****************************************************************
'* Name : RPM.BAS *
'* Author : Christian Lerche *
'* Notice : Copyright (c) 2009 DSB El-teknik *
'* : All Rights Reserved *
'* Date : 28-05-2009 *
'* Version : 1.0 *
'* Notes : PIC16F913, Boden Off, WDT off, PWR off *
'* : *
'****************************************************************
'
' Includes
'
'
' Defines-----------------------------------------------------------------------
'
Define osc 10 ' Define oscillator XT 10 MHz
DEFINE ADC_BITS 10 ' Define A/D Converter 10 bit
DEFINE ADC_CLOCK 3 ' Define ADC clock source
DEFINE ADC_SAMPLEUS 50 ' Wait 50 µS before convert to digi
'
' INPUT / OUTPUT----------------------------------------------------------------
'
TRISA = 0 ' PORTA is output
TRISA.5 = 1 ' PORTA.5 is input
TRISB = 1 ' PORTB is input
TRISC = 0 ' PORTC is Output
TRISB.0 = 1 ' B0 / Int is count input
ADCON0 = %10010001 ' ADC On, right justified
ADCON1 = 0 ' ADC Freq = 625KHz
ASM ; Insert ASM
BANKSEL LCDCON ; LCD Configuration
CLRF LCDCON ; Turn off LCD Driver
ENDASM ; End of ASM
'
' Variables and constants-------------------------------------------------------
'
W1 VAR WORD ' W1 is 16 bit variable
W2 var word ' W2 is 16 bit variable
W3 var word ' W3 is 16 bit variable
B0 var byte ' B0 is 8 bit variable
'
' Main program------------------------------------------------------------------
'
Main:
ADCIN 4, W2 ' Read Freq-to-voltage device
W3 = W2 * 977 ' Freaky constant makes it work.
W1 = DIV32 100 ' Put the result in W1
GOSUB display4 ' Show RPM
GOTO Main ' Do forever
END ' For the compilers sake
'
' Subroutines-------------------------------------------------------------------
'
display4:
B0 = W1 / 1000 ' Find number of thousands
W1 = W1 // 1000 ' Remove thousands from W1
Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
PORTC = B0 ' Send segments to LED
PORTA = $01 ' Turn on fourth digit
Pause 1 ' Leave it on 1 ms
PORTA = $00 ' Turn off digit to prevent ghosting
B0 = W1 / 100 ' Find number of hundreds
W1 = W1 // 100 ' Remove hundreds from W1
Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
PORTC = B0 ' Send segments to LED
PORTA = $02 ' Turn on third digit
Pause 1 ' Leave it on 1 ms
PORTA = $00 ' Turn off digit to prevent ghosting
B0 = W1 / 10 ' Find number of tens
W1 = W1 // 10 ' Remove tens from W1
Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
PORTC = B0 ' Send segments to LED
PORTA = $04 ' Turn on second digit
Pause 1 ' Leave it on 1 ms
PORTA = $00 ' Turn off digit to prevent ghosting
B0 = W1 ' Get number of ones
Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
PORTC = B0 ' Send segments to LED
PORTA = $08 ' Turn on first digit
Pause 1 ' Leave it on 1 ms
PORTA = $00 ' Turn off digit to prevent ghosting
RETURN ' Return to caller!
I'm sorry that there is some comments that shouldn't be in the code. But I've made a lot of changes through time!!
Bookmarks