Registriert seit: 22. Sep 2006
57 Beiträge
|
AW: Probleme Empfang TComPort DataPacket
8. Mär 2012, 16:06
Hier auch noch der Code vom Mega8 mit Bascom:
Delphi-Quellcode:
'--------------------------------------------------------------
' mega8.bas
' mega8 sample file
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 16000000
$baud = 38400
Declare Sub Setelv(byval L As Byte)
Config Int0 = Falling
Config Portb = Output
Config Portd = Output
Portb = 11111000
Config Timer1 = Timer , Prescale = 256 'Konfiguriere Timer1
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
On Urxc Rec_isr
On Int0 Int0_irq
On Timer1 Isr_von_timer1
Enable Interrupts
Enable Urxc
Enable Int0
Enable Timer1
Timer1 = 3036
Dim B As Bit '1 = Befehl über RS323 empfangen
Dim Buffer(10) As Byte 'Datenbytes des Befehls
Dim E As Byte '1 = Laufband Ab; 2 = Laufband Auf
Dim F As Byte '1 = Laufband langsammer; 2 = Laufband schneller
Dim P As Byte 'SollSpeed
Dim S As Byte 'IstSpeed
Dim V As Byte 'SollSteigung
Dim Z As Byte 'Datenbyte Zähler
Dim I As Word 'Schleifenzähler
Dim T As Word 'IstSteigung
Dim W As Word 'SteigungsDigits
T = Getadc(0)
If T > 230 Then
Portb.4 = 0
E = 1
W = 230
End If
If T < 220 Then
Portb.3 = 0
E = 2
W = 230
End If
'--------------------------------------------------------------------
' Main
'--------------------------------------------------------------------
Main:
Do
If B = 1 Then
If Buffer(1) = &H66 Then
If Buffer(10) = &H66 Then
Select Case Buffer(2)
Case &H00 : Set Portb.2
Case &H10 :
Print "SCHNELLSTART"
P = Buffer(3)
F = 1
Case &H20 :
Print "LANGSAMSTART"
P = Buffer(3)
F = 2
Case &H30 : Call Setelv(buffer(3))
Case &HFF : Reset Portb.2
End Select
End If
End If
Reset B
End If
T = Getadc(0)
If T < 220 Then
Portb.4 = 1
Portb.3 = 0
E = 2
W = 230
End If
If T > 875 Then
Portb.3 = 1
Portb.4 = 0
E = 1
W = 865
End If
If E > 0 Then
If E = 1 Then
If T = W Or T < W Then
Portb.4 = 1
E = 0
Print "ABSTOP"
End If
Else
If T = W Or T > W Then
Portb.3 = 1
E = 0
Print "AUFSTOP"
End If
End If
End If
If F > 0 Then
Incr S
If F = 1 Then
Portb.1 = 1
For I = 1 To 12000
Next
Portb.1 = 0
For I = 1 To 5000
Next
Else
Portb.0 = 1
For I = 1 To 12000
Next
Portb.0 = 0
For I = 1 To 5000
Next
End If
If S = P Then
If F = 2 Then
Print "LANGSAMSTOP"
Else
Print "SCHNELLSTOP"
End If
F = 0
S = 0
End If
End If
Loop
End
'--------------------------------------------------------------------
Rec_isr:
Incr Z
Buffer(z) = Udr
If Z = 10 Then
Set B
Z = 0
End If
Return
Int0_irq:
Set Portb.2
Print "PAUSE"
Return
Isr_von_timer1: 'ISR von Timer1
Timer1 = 3036
Print "AD" ; T
Toggle Portd.6
Return
Sub Setelv(byval L As Byte)
W = L * 43
W = W + 230
T = Getadc(0)
If V > L And T > 230 Then
Portb.4 = 0
V = L
E = 1
Print "ABSTART"
End If
If V < L And T < 865 Then
Portb.3 = 0
V = L
E = 2
Print "AUFSTART"
End If
End Sub
Gruß Wal
Es gibt viel zu tun, sitzen wir's aus ! 0(°~°)0
|