;************************************************************************************* ;Projekt: PIC-gesteuerter Würfel ;Funktion: Zufällige Zahl von Eins bis Sechs ausgeben ;Autor: Philipp Hess ;***************************Variablen************************************************* Takt equ .4000000 Zaehler equ 0x23 Counter1 equ 0x24 Counter2 equ 0x25 Counter3 equ 0x26 ;************************************************************************************* Konfiguration: errorlevel -302 list p=12F675 #include __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _INTRC_OSC_NOCLKOUT & _CPD_OFF & _PWRTE_ON & _MCLRE_OFF Start banksel CMCON ; Bankauswahl CMCON movlw B'00000111' ; Analog-Komparator aus movwf CMCON ; Komparator Steuerregister banksel TRISIO ; Bankauswahl TRISIO movlw B'11101000' ; Defintion der IO-Ports movwf TRISIO ; " " " banksel GPIO ; Bankauswahl GPIO clrf GPIO ; Löschen der Vorgeschichte Lauflicht movlw B'11010110' ; Würfelzahl 1 movwf GPIO ; Ausgabe call Verzoegerung_1s ; Zeitschleife 1s movlw B'11010101' ; Würfelzahl 2 movwf GPIO call Verzoegerung_1s movlw B'11010100' ; Würfelzahl 3 movwf GPIO call Verzoegerung_1s movlw B'11010001' ; Würfelzahl 4 movwf GPIO call Verzoegerung_1s movlw B'11010000' ; Würfelzahl 5 movwf GPIO call Verzoegerung_1s movlw B'11000001' ; Würfelzahl 6 movwf GPIO call Verzoegerung_1s movlw B'11000000' ; Alle LED's an (=7) movwf GPIO call Verzoegerung_1s movlw B'11010111' ; Alle LED's aus (=0) movwf GPIO Main btfsc GPIO, GP5 ; Neigungswinkelschalter ueberpruefen goto Main ; Wenn der Schalter nicht betätigt wurde, startet der Würfel nicht Laden movlw B'00000110' ; Wert ins W-Register laden movwf Zaehler ; W-Register in Zaehler-Speicherzelle schreiben Herunterzaehlen btfsc GPIO,GP5 ; Tasterstand überprüfen goto Funktionstest ; Sprung zu "Funktionstest" decfsz Zaehler,F ; Speicherzelle "Zaehler" dekrementieren goto Herunterzaehlen ; Sprung nach Schleifenanfang goto Laden ; Wenn Zaehler =0, Sprung zu "Laden" ;******************************************************************************************* Funktionstest btfss GPIO,GP5 ; Tasterstand überprüfen goto Funktionstest ; Sprung nach Schleifenanfang call Verzoegerung_2s ; Zeitschleife 2s Würfelausgabe movlw B'11010110' ; Würfelzahl 1 movwf GPIO ; Ausgabe call Verzoegerung_250ms ; Zeitschleife 250ms movlw B'11010101' ; Würfelzahl 2 movwf GPIO call Verzoegerung_250ms movlw B'11010100' ; Würfelzahl 3 movwf GPIO call Verzoegerung_250ms movlw B'11010001' ; Würfelzahl 4 movwf GPIO call Verzoegerung_250ms movlw B'11010000' ; Würfelzahl 5 movwf GPIO call Verzoegerung_250ms movlw B'11000001' ; Würfelzahl 6 movwf GPIO call Verzoegerung_250ms movlw B'11000000' ; Alle LED's an (=7) movwf GPIO call Verzoegerung_1s movf Zaehler,W ; Wert Zaehler-Speicherzelle ins W-Register addlw -1 ; Addiere -1 call Tab1 ; Rufe Unterprogramm "Tab1" auf movwf GPIO ; Ausgabe an GPIO goto Tastentest ; Sprung zu "Tastentest" ;************************************************************************************** Tastentest call Verzoegerung_2s call Verzoegerung_3s ; Zeitschleife 5s goto Löschen ; Sprung zu "Löschen" Auswahl btfss GPIO, GP5 ; Tasterstand überprüfen goto Neuer_Ladevorgang ; Sprung zu "Neuer_Ladevorgang" goto Löschen ; Sprung zu "Löschen" Neuer_Ladevorgang movlw B'00000110' ; Wert ins W-Register laden movwf Zaehler ; W-Register in Zaehler-Speicherzelle schreiben Neu_Würfeln btfss GPIO, GP5 ; Tasterstand überprüfen goto Decrement ; Sprung zu "Decrement" goto Funktionstest ; Sprung zu "Funktionstest" Decrement call Tab1 ; Rufe Unterprogramm "Tab1" auf decfsz Zaehler, F ; Speicherzelle "Zaehler" dekrementieren goto Neu_Würfeln ; Sprung zu "Neu_Würfeln" goto Neuer_Ladevorgang ; Sprung zu "Neuer_Ladevorgang" Löschen movlw B'11010111' ; Wert ins W-Register laden movwf GPIO ; Alle LED's aus goto Main ; Sprung zu "Laden" Tab1 addwf PCL, F DT 0xFE, 0xFD, 0xFC, 0xF9, 0xF8, 0xE9 return ;************************************************************************************** Verzoegerung_250ms: movlw D'60' movwf Counter1 movlw D'67' movwf Counter2 movlw D'1' movwf Counter3 nop nop call Verzoegerung_mittel_5 call Verzoegerung_lang_5 return Verzoegerung_mittel_5: Verz_mittel_1_5: decfsz Counter1,F goto Verz_mittel_1_5 Verz_mittel_2_5: decfsz Counter1,F goto Verz_mittel_2_5 nop decfsz Counter2,F goto Verz_mittel_2_5 return Verzoegerung_lang_5: Verz_lang_1_5: decfsz Counter1,F goto Verz_lang_1_5 nop decfsz Counter2,F goto Verz_lang_1_5 nop Verz_lang_2_5: decfsz Counter1,F goto Verz_lang_2_5 nop decfsz Counter3,F goto Verz_lang_1_5 return Verzoegerung_1s: ; Zeitschleife 1s movlw D'0' movwf Counter1 movlw D'11' movwf Counter2 movlw D'5' movwf Counter3 nop call Verzoegerung_mittel call Verzoegerung_lang return Verzoegerung_mittel: Verz_mittel_1: decfsz Counter1,F goto Verz_mittel_1 Verz_mittel_2: decfsz Counter1,F goto Verz_mittel_2 nop decfsz Counter2,F goto Verz_mittel_2 return Verzoegerung_lang: Verz_lang_1: decfsz Counter1,F goto Verz_lang_1 nop decfsz Counter2,F goto Verz_lang_1 nop Verz_lang_2: decfsz Counter1,F goto Verz_lang_2 nop decfsz Counter3,F goto Verz_lang_1 return ;************************************************************************************+ Verzoegerung_2s: ; Zeitschleife 2s movlw D'3' movwf Counter1 movlw D'24' movwf Counter2 movlw D'10' movwf Counter3 nop call Verzoegerung_mittel_1 call Verzoegerung_lang_1 return Verzoegerung_mittel_1: Verz_mittel_1_1: decfsz Counter1,F goto Verz_mittel_1_1 Verz_mittel_2_1: decfsz Counter1,F goto Verz_mittel_2_1 nop decfsz Counter2,F goto Verz_mittel_2_1 return Verzoegerung_lang_1: Verz_lang_1_1: decfsz Counter1,F goto Verz_lang_1_1 nop decfsz Counter2,F goto Verz_lang_1_1 nop Verz_lang_2_1: decfsz Counter1,F goto Verz_lang_2_1 nop decfsz Counter3,F goto Verz_lang_1_1 return ;************************************************************************************** Verzoegerung_3s: ; Zeitschleife 3s movlw D'8' movwf Counter1 movlw D'36' movwf Counter2 movlw D'15' movwf Counter3 call Verzoegerung_mittel_1_1 call Verzoegerung_lang_1_1 return Verzoegerung_mittel_1_1: Verz_mittel_1_1_1: btfss GPIO, GP5 goto Auswahl decfsz Counter1,F goto Verz_mittel_1_1_1 Verz_mittel_2_1_1: btfss GPIO, GP5 goto Auswahl decfsz Counter1,F goto Verz_mittel_2_1_1 nop decfsz Counter2,F goto Verz_mittel_2_1_1 return Verzoegerung_lang_1_1: Verz_lang_1_1_1: btfss GPIO, GP5 goto Auswahl decfsz Counter1,F goto Verz_lang_1_1_1 nop decfsz Counter2,F goto Verz_lang_1_1_1 nop Verz_lang_2_1_1: btfss GPIO, GP5 goto Auswahl decfsz Counter1,F goto Verz_lang_2_1_1 nop decfsz Counter3,F goto Verz_lang_1_1_1 return ;************************************************************************************** END