Code:
' Hardware PWM mit Timer1
$regfile = "m8def.dat"
$crystal = 73728000
Dim Var As Byte
'Dim Opto As Bit
'Config Pinc.5 = Output
'Config Pinc.4 = Output
Config Int0 = Falling
Config Timer1 = Timer , Prescale = 256
Const Timervorgabe = 36735 'Berechnung von einer 1s 36735=1s 7935=2s
Const Markierungenproscheibe = 6 '6 Impulse Papst 8 Impulse Scheibe
Const Messzeit = 1 'Messzeit in s
Dim Zaehlerirq0 As Long
Dim Impulseprosekunde As Long
Dim Impulseprominute As Long
Dim Umdrehungenprominute As Integer
Dim Y As Byte
Dim X As Byte
Dim A As Byte
Dim B As Byte
Dim C As Byte
Dim D(2) As Byte
Dim I As Integer At D Overlay
Config Spi = Soft , Dout = Pinb.3 , Ss = None , Clock = Pinb.5
Spiinit
'I = -32768
'I = 32767
I = 30000
A = &B00000000
'B = &B11011000
'C = &B11110000
'B = &B01111111 'Vollausschlag
'C = &B11111111 'Vollausschlag
B = &B10000000 '0V
C = &B00000000 '0V
'Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 1 , Clockrate = 4 , Noss = 1
'Spiinit
'Set Portb.2
'Waitms 1
'Spiout A , 1
'Waitms 1
'Spiout B , 1
'Waitms 1
'Spiout C , 1
'Waitms 1
'Reset Portb.2
'LCD Config
Config Lcd = 40 * 2
'Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.3 , Db6 = Portd.6 , Db7 = Portd.1 , E = Portd.5 , Rs = Portd.7
Config Lcdbus = 4
Config Lcdmode = Port
Initlcd
Cls
'Config Portb.1 = Output
'Config Portb.2 = Output
'Config Timer2 = Pwm , Compare Pwm = Clear Up , Prescale = 1 Pwm = On
Config Pinc.1 = Input 'Taster Schalter 1
Config Pinc.2 = Input 'Taster Schalter 2
Config Pind.2 = Input
Opto Alias Pind.2
Portd.2 = 1
Portc.1 = 1 'interner Pullup Schalter1
Portc.2 = 1
Var = 0
'Portb.0 = Opto
Zaehlerirq0 = 0
On Int0 Irq0
Enable Int0
On Timer1 Timer_irq
Enable Timer1
Enable Timer2
Enable Interrupts
'Locate 1 , 1
'Lcd "ich bin ein PULS"
Gosub Spi
'Goto 0 'Restart das Ding
Taster1 Alias Pinc.1
Taster2 Alias Pinc.2
Do
Locate 2 , 1
Lcd D(2) ; " " ; D(1)
Locate 1 , 8
Lcd I
If Taster1 = 0 Then
Gosub Countup
End If
If Taster2 = 0 Then
Gosub Countdown
End If
'If Opto = 0 Then
'Locate 1 , 1
'Lcd "0"
'Else
'Locate 1 , 1
'Lcd "1"
'End If
'Locate 2 , 1
'Lcd Impulseprosekunde
Impulseprominute = Impulseprosekunde * 60
Impulseprominute = Impulseprominute / Messzeit
Umdrehungenprominute = Impulseprominute / Markierungenproscheibe
Locate 1 , 1
Lcd Umdrehungenprominute
'Locate 2 , 10
'Lcd X
'Debounce Pinc.1 , 0 , Countup , Sub
'Debounce Pinc.2 , 0 , Countdown , Sub
'Locate 1 , 1
'Lcd "Pulsweite "
'Locate 2 , 1
'Lcd ; Var ; " Steps O:" ; Opto
'Nicht relevant 'Compare1a = Var '256 - Var
'Ocr2 = 255 - Var 'PWM 3 'Var
Loop
Countup:
I = I + 1000
Waitms 20
Gosub Spi
Return
Countdown:
I = I + 1000
Waitms 20
Gosub Spi
Return
Irq0:
Incr Zaehlerirq0
Return
Timer_irq:
Timer1 = Timervorgabe
Impulseprosekunde = Zaehlerirq0
Zaehlerirq0 = 0
Return
Spi:
Spiinit
Reset Portb.1
Spiout A , 1
Spiout D(2) , 1
Spiout D(1) , 1
Set Portb.1
Return
End
Lesezeichen