2007年12月07日
program tacometer02
const TMR1H_Ini = 62
const TMR1L_Ini = 0
dim taco_pulse as byte
dim txt as string[3]
dim ilumi_cnt as byte
'===============================================================================
' decode ascii-char -> 7segment-LED
'===============================================================================
Sub procedure led7seg_decode3( dim ascii_char as byte )
SetBit (PORTB,4)
Select case ascii_char
case " "
ClearBit(PORTD,1) 'A
ClearBit(PORTD,0) 'B
ClearBit(PORTB,2) 'C
ClearBit(PORTB,1) 'D
ClearBit(PORTB,0) 'E
ClearBit(PORTD,2) 'F
ClearBit(PORTC,3) 'G
case "0"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
SetBit (PORTB,0) 'E
SetBit (PORTD,2) 'F
ClearBit(PORTC,3) 'G
case "1"
ClearBit(PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
ClearBit(PORTB,1) 'D
ClearBit(PORTB,0) 'E
ClearBit(PORTD,2) 'F
ClearBit(PORTC,3) 'G
case "2"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
ClearBit(PORTB,2) 'C
SetBit (PORTB,1) 'D
SetBit (PORTB,0) 'E
ClearBit(PORTD,2) 'F
SetBit (PORTC,3) 'G
case "3"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
ClearBit(PORTB,0) 'E
ClearBit(PORTD,2) 'F
SetBit (PORTC,3) 'G
case "4"
ClearBit(PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
ClearBit(PORTB,1) 'D
ClearBit(PORTB,0) 'E
SetBit (PORTD,2) 'F
SetBit (PORTC,3) 'G
case "5"
SetBit (PORTD,1) 'A
ClearBit(PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
ClearBit(PORTB,0) 'E
SetBit (PORTD,2) 'F
SetBit (PORTC,3) 'G
case "6"
SetBit (PORTD,1) 'A
ClearBit(PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
SetBit (PORTB,0) 'E
SetBit (PORTD,2) 'F
SetBit (PORTC,3) 'G
case "7"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
ClearBit(PORTB,1) 'D
ClearBit(PORTB,0) 'E
SetBit (PORTD,2) 'F
ClearBit(PORTC,3) 'G
case "8"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
SetBit (PORTB,0) 'E
SetBit (PORTD,2) 'F
SetBit (PORTC,3) 'G
case "9"
SetBit (PORTD,1) 'A
SetBit (PORTD,0) 'B
SetBit (PORTB,2) 'C
SetBit (PORTB,1) 'D
ClearBit(PORTB,0) 'E
SetBit (PORTD,2) 'F
SetBit (PORTC,3) 'G
case else
End select
End sub
'===============================================================================
' decode ascii-char -> 7segment-LED
'===============================================================================
Sub procedure led7seg_decode4( dim ascii_char as byte )
SetBit (PORTB,5)
Select case ascii_char
case " "
ClearBit(PORTC,5) 'A
ClearBit(PORTC,4) 'B
ClearBit(PORTC,7) 'C
ClearBit(PORTD,4) 'D
ClearBit(PORTD,5) 'E
ClearBit(PORTC,6) 'F
ClearBit(PORTD,3) 'G
case "0"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
SetBit (PORTD,5) 'E
SetBit (PORTC,6) 'F
ClearBit(PORTD,3) 'G
case "1"
ClearBit(PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
ClearBit(PORTD,4) 'D
ClearBit(PORTD,5) 'E
ClearBit(PORTC,6) 'F
ClearBit(PORTD,3) 'G
case "2"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
ClearBit(PORTC,7) 'C
SetBit (PORTD,4) 'D
SetBit (PORTD,5) 'E
ClearBit(PORTC,6) 'F
SetBit (PORTD,3) 'G
case "3"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
ClearBit(PORTD,5) 'E
ClearBit(PORTC,6) 'F
SetBit (PORTD,3) 'G
case "4"
ClearBit(PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
ClearBit(PORTD,4) 'D
ClearBit(PORTD,5) 'E
SetBit (PORTC,6) 'F
SetBit (PORTD,3) 'G
case "5"
SetBit (PORTC,5) 'A
ClearBit(PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
ClearBit(PORTD,5) 'E
SetBit (PORTC,6) 'F
SetBit (PORTD,3) 'G
case "6"
SetBit (PORTC,5) 'A
ClearBit(PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
SetBit (PORTD,5) 'E
SetBit (PORTC,6) 'F
SetBit (PORTD,3) 'G
case "7"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
ClearBit(PORTD,4) 'D
ClearBit(PORTD,5) 'E
SetBit (PORTC,6) 'F
ClearBit(PORTD,3) 'G
case "8"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
SetBit (PORTD,5) 'E
SetBit (PORTC,6) 'F
SetBit (PORTD,3) 'G
case "9"
SetBit (PORTC,5) 'A
SetBit (PORTC,4) 'B
SetBit (PORTC,7) 'C
SetBit (PORTD,4) 'D
ClearBit(PORTD,5) 'E
SetBit (PORTC,6) 'F
SetBit (PORTD,3) 'G
case else
End select
End sub
'===============================================================================
' Turn Off
'===============================================================================
Sub procedure turn_off
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
End sub
'===============================================================================
' Turn On
'===============================================================================
Sub procedure turn_on
led7seg_decode3(txt[2])
led7seg_decode4(txt[1])
End sub
'===============================================================================
' Interrupt from Timer1
'===============================================================================
Sub procedure interrupt
If PIR1.TMR1IF = 1 then
ByteToStr(taco_pulse, txt)
ilumi_cnt = 0
taco_pulse = 0
TMR1H = TMR1H_Ini
TMR1L = TMR1L_Ini
ClearBit(PIR1,TMR1IF)
SetBit(PIE1,TMR1IE)
End if
End sub
'*******************************************************************************
' Program main
'*******************************************************************************
main:
ClearBit(INTCON,GIE)
SetBit(PIE1,TMR1IE)
TMR1H = TMR1H_Ini
TMR1L = TMR1L_Ini
T1CON = 0
SetBit(T1CON,T1CKPS1)
SetBit(T1CON,T1CKPS0)
SetBit(T1CON,TMR1ON)
ClearBit(PIR1,TMR1IF)
SetBit(PIE1,TMR1IE)
SetBit(INTCON,PEIE)
SetBit(INTCON,GIE)
ADCON0 = 0
ADCON1 = %00000110
SetBit(CMCON, CM2)
SetBit(CMCON, CM1)
SetBit(CMCON, CM0)
TRISA = %00100000
TRISB = %11000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000
turn_off
taco_pulse = 0
ilumi_cnt = 0
WaitHigh:
Inc(ilumi_cnt)
If PORTB.6 = 0 then
If ilumi_cnt <> 8 then
turn_off
Else
turn_on
ilumi_cnt = 0
End if
Else
turn_on
End if
If PORTB.7 = 0 then
goto WaitHigh
End if
Inc(taco_Pulse)
WaitLow:
Inc(ilumi_cnt)
If PORTB.6 = 0 then
If ilumi_cnt <> 8 then
turn_off
Else
turn_on
ilumi_cnt = 0
End if
Else
turn_on
End if
If PORTB.7 = 1 then
goto WaitLow
End if
Inc(taco_Pulse)
goto WaitHigh
end.
Posted at 2007/12/07 00:29:24 | |
トラックバック(0) |
自作電装品 | 日記
2007年12月07日
字下げが消えちゃうからちょっとみにくいんですが、MikroBasicで記述しています。
program tacometer01
const TMR1H_Ini = 62
const TMR1L_Ini = 0
dim taco_pulse as byte
dim rpm as byte
dim wrpm as byte
dim ilumi_cnt as byte
dim ix as byte
'===============================================================================
' Display LED
'===============================================================================
Sub procedure TurnOn(dim rev as byte)
Select case PORTA.5
case 0
If rev > 3 then
SetBit(PORTB,5)
ENd If
If rev > 5 then
SetBit(PORTB,4)
ENd If
If rev > 7 then
SetBit(PORTB,3)
ENd If
If rev > 9 then
SetBit(PORTB,2)
SetBit(PORTB,1)
ENd If
If rev > 11 then
SetBit(PORTB,0)
ENd If
If rev > 13 then
SetBit(PORTD,7)
ENd If
If rev > 15 then
SetBit(PORTD,6)
ENd If
If rev > 17 then
SetBit(PORTD,5)
ENd If
If rev > 19 then
SetBit(PORTD,4)
SetBit(PORTC,7)
ENd If
If rev > 21 then
SetBit(PORTC,6)
ENd If
If rev > 23 then
SetBit(PORTC,5)
ENd If
If rev > 25 then
SetBit(PORTC,4)
ENd If
If rev > 27 then
SetBit(PORTD,3)
ENd If
If rev > 29 then
SetBit(PORTD,0)
SetBit(PORTC,3)
ENd If
If rev > 31 then
SetBit(PORTC,2)
ENd If
If rev > 33 then
SetBit(PORTC,1)
ENd If
If rev > 35 then
SetBit(PORTC,0)
ENd If
If rev > 37 then
SetBit(PORTE,2)
ENd If
If rev > 39 then
SetBit(PORTE,1)
SetBit(PORTE,0)
ENd If
case 1
If rev > 41 then
SetBit(PORTC,1)
ENd If
If rev > 43 then
SetBit(PORTC,2)
ENd If
If rev > 45 then
SetBit(PORTC,3)
ENd If
If rev > 47 then
SetBit(PORTD,0)
ENd If
If rev > 49 then
SetBit(PORTD,1)
SetBit(PORTD,2)
ENd If
If rev > 51 then
SetBit(PORTD,3)
ENd If
If rev > 53 then
SetBit(PORTC,4)
ENd If
If rev > 55 then
SetBit(PORTC,5)
ENd If
If rev > 57 then
SetBit(PORTC,6)
ENd If
If rev > 59 then
SetBit(PORTC,7)
SetBit(PORTD,4)
ENd If
If rev > 61 then
SetBit(PORTD,5)
ENd If
If rev > 63 then
SetBit(PORTD,6)
ENd If
If rev > 65 then
SetBit(PORTD,7)
ENd If
If rev > 67 then
SetBit(PORTB,0)
ENd If
If rev > 69 then
SetBit(PORTB,1)
SetBit(PORTB,2)
ENd If
If rev > 71 then
SetBit(PORTB,4)
ENd If
If rev > 73 then
SetBit(PORTB,5)
ENd If
If rev > 75 then
SetBit(PORTA,0)
ENd If
If rev > 77 then
SetBit(PORTA,1)
ENd If
If rev > 79 then
SetBit(PORTA,2)
SetBit(PORTA,3)
ENd If
End Select
End sub
'===============================================================================
' Turn Off LED
'===============================================================================
Sub procedure TurnOff
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
End sub
'===============================================================================
' Display LED
'===============================================================================
Sub procedure Display
If rpm <> wrpm then
wrpm = rpm
TurnOff
TurnOn(wrpm)
End If
End sub
'===============================================================================
' Interrupt from Timer1
'===============================================================================
Sub procedure interrupt
If PIR1.TMR1IF = 1 then
rpm = taco_pulse
taco_pulse = 0
TMR1H = TMR1H_Ini
TMR1L = TMR1L_Ini
ClearBit(PIR1,TMR1IF)
SetBit (PIE1,TMR1IE)
End if
End sub
'*******************************************************************************
' Program main
'*******************************************************************************
main:
ClearBit(INTCON,GIE)
SetBit (PIE1,TMR1IE)
TMR1H = TMR1H_Ini
TMR1L = TMR1L_Ini
T1CON = 0
SetBit (T1CON,T1CKPS1)
SetBit (T1CON,T1CKPS0)
SetBit (T1CON,TMR1ON)
ClearBit(PIR1,TMR1IF)
SetBit (PIE1,TMR1IE)
SetBit (INTCON,PEIE)
SetBit (INTCON,GIE)
ADCON0 = 0
ADCON1 = %00000110
SetBit(CMCON, CM2)
SetBit(CMCON, CM1)
SetBit(CMCON, CM0)
TRISA = %00100000
TRISB = %11000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000
TurnOff
taco_pulse = 0
rpm = 0
wrpm = 0
ilumi_cnt = 0
ix = 255
WaitHigh:
Display
If PORTB.7 = 0 then
goto WaitHigh
End if
Inc(taco_Pulse)
WaitLow:
Display
If PORTB.7 = 1 then
goto WaitLow
End if
Inc(taco_Pulse)
goto WaitHigh
end.
Posted at 2007/12/07 00:27:51 | |
トラックバック(0) |
自作電装品 | 日記