Hi leute,
Ich hab da so meine Probleme mit Cases.
Ich möchte eine RGB Lampe über einen Taster in verschiedenen Programmen laufen lassen.
Dazu hab ich mir ein Taster an den Int1 vom mega 16 angeschlossen.
Wenn ich das Programm auf mein AVR brenne funktioniert alles:
Code:
$regfile = "m16def.dat"
Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7
Config Lcd = 16 * 1a
Config Portd.5 = Output
Config Int1 = Falling
Enable Interrupts
Enable Int1
On Int1 Int0set
Dim T As Word
Declare Sub Progr1
Declare Sub Progr2
Declare Sub Progr3
Declare Sub Progr4
Declare Sub Progr5
Declare Sub Progr6
Do
Select Case T
Case 1
Gosub Progr1
Case 2
Gosub Progr2
Case 3
Gosub Progr3
Case 4
Gosub Progr4
Case 5
Gosub Progr5
Case 6
Gosub Progr6
End Select
Loop
Int0set:
T = T + 1
Waitms 50
Return
Progr1:
Cls
Lcd "case 1"
Cursor Off
Waitms 10
Return
Progr2:
Cls
Lcd "case 2"
Cursor Off
Waitms 10
Return
Progr3:
Cls
Lcd "case 3"
Cursor Off
Waitms 10
Return
Progr4:
Cls
Lcd "case 4"
Cursor Off
Waitms 10
Return
Progr5:
Cls
Lcd "case 5"
Cursor Off
Waitms 10
Return
Progr6:
T = 1
Wenn ich das programm brenne funktioniert die erste SUB aber beim nächsten klick funktionierT nichts mehr:
Code:
$regfile = "m16def.dat"
$crystal = 1000000
Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7
Config Lcd = 16 * 1a
Config Portd.5 = Output
Config Int1 = Falling
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 1
Config Timer0 = Pwm , Pwm = On , Compare Pwm = Clear Down , Prescale = 1
Config Timer2 = Pwm , Pwm = On , Compare Pwm = Clear Up , Prescale = 1
Ddrb.3 = 1
Start Adc
Enable Interrupts
Enable Int1
Enable Timer2
Enable Timer0
On Int1 Int0set
Dim T As Word
Dim W As Word
Dim R As Word
Dim G As Word
Dim B As Word
Declare Sub Progr1
Declare Sub Progr2
Declare Sub Progr3
Cls
Lcd "Wait for INT1"
Do
Select Case T
Case 1
Gosub Progr1
Case 2
Gosub Progr2
Case 3
Gosub Progr3
End Select
Waitms 10
Loop
End
Int0set:
T = T + 1
Waitms 50
Return
Sub Progr1:
For R = 0 To 255 Step 1
W = Getadc(0) / 50
Ocr1a = R
Waitms W
Next
For R = 255 To 0 Step -1
W = Getadc(0) / 50
Ocr1a = R
Waitms W
Next
' Return
End Sub
Sub Progr2:
For G = 0 To 255 Step 1
W = Getadc(0) / 50
Ocr1b = G
Waitms W
Next
For G = 255 To 0 Step -1
W = Getadc(0) / 50
Ocr1b = G
Waitms W
Next
End Sub
Progr3:
T = 1
Return
wenn ich sub progr2 so schreibe :
Code:
Sub Progr2:
Cls
Lcd "case 2"
Cursor Off
Waitms 10
Return
end sub
gehts weider wie gewünscht.
Bin ich blind oder ist der atmel überfordert ?
Grüße Jakob
Lesezeichen