Ovo mi radi
Code:
DEFINE LCD_RSBIT 1 ' RS na D1
DEFINE LCD_EREG PORTD ' E na PORTD
DEFINE LCD_EBIT 0 ' E na D0
DEFINE LCD_BITS 4 ' LCD 4 bit mode
DEFINE LCD_LINES 2 ' 2 linije LCD display
ct0 var word 'total number of counts
t1hi var ct0.byte1 'high byte of timer1
t1lo var ct0.byte0 'low byte of timer1
ctime var word 'counting time
ctime = 1000 'CPS 1000mS gate time
Pause 500 'allow LCD to startup
lcdout $fe,1
Goto main 'bypass subroutines
getcount:
t1con = 7 'set timer 1 on, external clock, non sync = bit0 =1, bit1 =1, bit2 =1
tmr1h = 0 'clear timer 1 high byte
tmr1l = 0 'clear timer 1 low byte
pir1 = 0 'clear overflow flag
pause ctime 'wait
t1con = 0 'stop timer 1 , bit0 =0
t1lo = tmr1l
t1hi = tmr1h
ct0 = ct0 * 60 ' Per minute
lcdout $FE,1, "RPM ",dec5 ct0, " o/min"
Return
Main:
gosub getcount
goto main
end
ovde nesto ne valja?
Code:
clear
ansel = 0
DEFINE LCD_DREG PORTD ' LCD se nalazi na portu D
DEFINE LCD_DBIT 4 ' Data bits D4..D7
DEFINE LCD_RSREG PORTD ' RS na PORTD
DEFINE LCD_RSBIT 1 ' RS na D1
DEFINE LCD_EREG PORTD ' E na PORTD
DEFINE LCD_EBIT 0 ' E na D0
DEFINE LCD_BITS 4 ' LCD 4 bit mode
DEFINE LCD_LINES 2 ' 2 linije LCD display
DEFINE OSC 4
Capture VAR PIR1.2 ' CCP1 capture flag
Overflow VAR PIR1.0 ' Timer1 overflow flag
RPM var word
period var Word
CCP1CON = %00000110 ' Enable the CCP1 capture, every 4th rising edge
pause 200
lcdout $fe,1
looop:
t1con = 7
'T1CON = %00100000 ' TMR1 prescale=1:2 Timer OFF
'11 = 1:8 prescale value
'10 = 1:4 prescale value
'01 = 1:2 prescale value
'00 = 1:1 prescale value
TMR1H = 0 ' Zero the Timer
TMR1L = 0
capture = 0
Start:
IF capture = 0 Then
goto Start ' Wait here for the first capture
endif
T1CON.0 = 1 ' Start the Timer
capture = 0 ' Reset the capture flag
CaptureLoop:
IF capture = 0 Then
goto CaptureLoop ' Wait here until captured
endif
period.lowbyte = CCPR1L ' Store the captured value in
period.highbyte = CCPR1H ' period variable
period = period / 2
RPM = 10000
RPM = RPM * RPM ' 100,000,000
RPM = DIV32 period ' 100,000,000 / RevCount
RPM = RPM * 60 ' Per minute
RPM = DIV32 400
RPM = (RPM /10)*25'+25
pause 100
lcdout $FE,$88,"RPM=",dec4 rpm , " ", Period
gosub cleartimer1
GoTo looop ' Do it forever
ClearTimer1:
IF (capture = 0) Then
goto cleartimer1 ' Wait for beginning of next period
endif
TMR1L = 0 ' Clear Timer1 low register
TMR1H = 0 ' Clear Timer1 high register
capture = 0 ' Clear capture flag
overflow = 0 ' Clear overflow flagReturn
return
end
[Ovu poruku je menjao electron2008 dana 03.12.2012. u 17:36 GMT+1]