Hi, xbgamer!
Ich habe mal ein Zeitrelai mit dem AT90S2313 gebaut. Es hat 2 7-Segment Anzeigen und kann bis 99 sekunden eingestellt werden.
Im "Ruhezustand" sind die Anzeigen aus. Wenn die Taste SET betätigt wird, gehen die Anzeigen an und man kann bei betätigter SET-Taste mit "+" und "-" Tasten die Zeit einstellen. Sobald die SET-Taste losgelassen wird, wird die eingestellte Zeit In den EEPROM geschrieben. Beim Betätigen der START-Taste Geht die Anzeige an und der Countdown läuft runter bis null, solange die Zeit läuft ist ein Relai angezogen, danach geht die Anzeige wider aus.
Den Schaltplan und Die *.BAS Datei Lege ich bei.
Man Lernt am besten indem man den fertigen Code analysiert.
Code:'Zeitrelai 'Lebi '26.09.06 $regfile = "2313def.dat" $crystal = 3686400 Hauptprogramm: 'Sprungmarke fuer Huptprogramm 'Deklaration der SUBs fuer Tasten Declare Sub Pluspressed Declare Sub Minuspressed 'port config Ddrb = &B11111111 Ddrd = &B1000011 'pool up Portd = &B0111100 'Variablen Deklaration Dim Zeit As Byte , 1en As Byte , 10er As Byte , Ausgabebyte As Byte 'Konstanten Einstellen Const Del = 7 'Multiplex zeit fuer 7-SegmentAnzeige Const Lt = 57600 'Lade timer auf 57600 'Tasten Zuweisung Ustan Alias Pind.4 'Ustan=SET Minus Alias Pind.5 Plus Alias Pind.3 Pusk Alias Pind.2 'Pusk=START 'Timer einstellen On Timer1 A1 'Beim Teimerueberlauf(Interrupt) gehe zum merker A1 Config Timer1 = Timer , Prescale = 64 'Frequenz wird gurch 64 geteilt Load Timer1 , Lt '3686400/8=460800,460800/256=1800 interrupst pro Sekunde Enable Interrupts 'Hauptschleife Do 'Tasten werden permanent abgefragt 'wenn Taste "START" betaetigt, dann: 'Relai an, Lese die Zeitwariable aus dem EEPROM, springe zu Unterprogramm "Anzeige" If Pusk = 0 Then Set Portd.1 Readeeprom Zeit , 10 Gosub Anzeige End If 'wenn Taste "SET" Betaetigt, dann gehe zu Unterprogramm "Ustanovka/Einstellen" If Ustan = 0 Then Goto Ustanovka Loop 'Unterprogramm "Anzeige" Anzeige: 'Timer 1 aktivieren Enable Timer1 'Sekunden 10er Ausgabebyte = Zeit Mod 10 Portd.6 = 0 If Ausgabebyte = 0 Then Portb = &B00000011 If Ausgabebyte = 1 Then Portb = &B01101111 If Ausgabebyte = 2 Then Portb = &B10001001 If Ausgabebyte = 3 Then Portb = &B01001001 If Ausgabebyte = 4 Then Portb = &B01100101 If Ausgabebyte = 5 Then Portb = &B01010001 If Ausgabebyte = 6 Then Portb = &B00010001 If Ausgabebyte = 7 Then Portb = &B01101011 If Ausgabebyte = 8 Then Portb = &B00000001 If Ausgabebyte = 9 Then Portb = &B01000001 Portb.0 = 1 Waitms Del 'Sekunden 1er Ausgabebyte = Zeit / 10 Portd.6 = 1 If Ausgabebyte = 0 Then Portb = &B00000011 If Ausgabebyte = 1 Then Portb = &B01101111 If Ausgabebyte = 2 Then Portb = &B10001001 If Ausgabebyte = 3 Then Portb = &B01001001 If Ausgabebyte = 4 Then Portb = &B01100101 If Ausgabebyte = 5 Then Portb = &B01010001 If Ausgabebyte = 6 Then Portb = &B00010001 If Ausgabebyte = 7 Then Portb = &B01101011 If Ausgabebyte = 8 Then Portb = &B00000001 If Ausgabebyte = 9 Then Portb = &B01000001 Portb.0 = 0 Waitms Del If Zeit = 0 Then Goto A2 Goto Anzeige A2: Disable Timer1 Portd.6 = 1 Portb.0 = 1 Wait 1 Portd.6 = 0 Portb.0 = 0 Reset Portd.1 Goto Hauptprogramm A1: Load Timer1 , Lt Decr Zeit Return 'Unterprogramm "Einstellen" Ustanovka: Readeeprom Zeit , 10 Debounce Plus , 0 , Pluspressed , Sub And Ustan = 0 Debounce Minus , 0 , Minuspressed , Sub And Ustan = 0 'Anzeige beim Einstellen Ausgabebyte = Zeit Mod 10 Portd.6 = 0 If Ausgabebyte = 0 Then Portb = &B00000011 If Ausgabebyte = 1 Then Portb = &B01101111 If Ausgabebyte = 2 Then Portb = &B10001001 If Ausgabebyte = 3 Then Portb = &B01001001 If Ausgabebyte = 4 Then Portb = &B01100101 If Ausgabebyte = 5 Then Portb = &B01010001 If Ausgabebyte = 6 Then Portb = &B00010001 If Ausgabebyte = 7 Then Portb = &B01101011 If Ausgabebyte = 8 Then Portb = &B00000001 If Ausgabebyte = 9 Then Portb = &B01000001 Portb.0 = 1 Waitms Del Ausgabebyte = Zeit / 10 Portd.6 = 1 If Ausgabebyte = 0 Then Portb = &B00000011 If Ausgabebyte = 1 Then Portb = &B01101111 If Ausgabebyte = 2 Then Portb = &B10001001 If Ausgabebyte = 3 Then Portb = &B01001001 If Ausgabebyte = 4 Then Portb = &B01100101 If Ausgabebyte = 5 Then Portb = &B01010001 If Ausgabebyte = 6 Then Portb = &B00010001 If Ausgabebyte = 7 Then Portb = &B01101011 If Ausgabebyte = 8 Then Portb = &B00000001 If Ausgabebyte = 9 Then Portb = &B01000001 Portb.0 = 0 Waitms Del If Ustan = 0 Then Goto Ustanovka Goto Hauptprogramm Sub Pluspressed Incr Zeit If Zeit > 98 Then Zeit = 0 Writeeeprom Zeit , 10 End Sub Sub Minuspressed Decr Zeit If Zeit > 98 Then Zeit = 0 Writeeeprom Zeit , 10 End Sub







Zitieren

Lesezeichen