;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Author : Faruk Fetahovic ; ; Date : ; ; Version: 0,1 ; ; Title: digitaler chronometer ; ; ; ; Description: ; ;Dieses Programm soll verschieden Aufgaben erledigen ; ;Per Taster soll die Zeit gespeichert werden die gerade aktuell ist ; ;bei wiederholten drücken des Tasters soll diese Zeit weider gespeichert werden ; ;LED2 soll ebenfalls aufleuchten ; ;Per Tasten kann die Zeit eingestellt werden ; ;Umschalten zw. UTC und LOC --> LED1 aufleuchten ;************************************************************** ;* Anzeige : SS:MM ;* Pinbelegung ;* ---------------------------------- ;* ;* PORTC: 0 --------------------- A Y0 ;* 1 --------------------- B Y1 ;* 2 --------------------- C Y2 ;* Y3 ;* Y4 ;* PORTC: 5 --------------------- G1 Y5 ;* GND -- G2A Y6 ;* GND -- G2B Y7 ;* 4 LED1 ;* ;* CA4 -----------------------------------------+ ;* CA3 -----------------------------+ I ;* CA2 -----------------+ I I ;* CA1 -----+ I I I ;* I I I I ;* PORTB:0 Segment G AAAAA AAAAA AAAAA AAAAA ;* 1 Segment F F B F B F B F B ;* 2 Segment E F B F B F B F B ;* 3 Segment D GGGGG GGGGG GGGGG GGGGG ;* 4 Segment C E C E C E C E C ;* 5 Segment B E C E C E C E C ;* 6 Segment A DDDDD DDDDD DDDDD DDDDD ;* 7 LED2 ;* AAAAA AAAAA AAAAA AAAAA ;* F B F B F B F B ;* F B F B F B F B ;* GGGGG GGGGG GGGGG GGGGG ;* E C E C E C E C ;* E C E C E C E C ;* DDDDD DDDDD DDDDD DDDDD ;* I I I I ;* CA8 -----+ I I I ;* CA7 -----------------+ I I ;* CA6 -----------------------------+ I ;* CA5 -----------------------------------------+ ;* ; ; RA0 = Taster5 ; RA1 = Taster1 ; RA2 = Taster2 ; RA3 = Taster3 ; RA4 = Taster4 ; ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; list p=16f876a ; list directive to define processor #include ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The labels following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***********VARIABLE DEFINITIONS********* ;STATUS equ 03h ;TRISA equ 85h ;TRISB equ 86h ;TRISC equ 87h ;PORTA equ 05h ;PORTB equ 06h ;PORTC equ 07h ;ADCON1 equ 9Fh w_copy Equ 0x20 ; Backup für Akkuregister s_copy Equ 0x21 ; Backup für Statusregister p_copy equ 0x22 ; Backup für PcLath Register ;loops_wait equ 0x3D ; timer1 für wait ;loops_wait2 equ 0x3E ; timer2 für wait ar equ 0x27 ; Timer2 equ 0x28 ; Vorteiler von 50 Hz auf 10 Hz sek1 equ 0x23 sek2 equ 0x24 min1 equ 0x25 min2 equ 0x26 std1 equ 0x29 std2 equ 0x2A Digit equ 0x2B ; Ziffernzähler PCLATH_TEMP equ 0x23 STATUS_TEMP equ 0x24 W_TEMP equ 0x25 #define T1 PORTA, 1 #define T2 PORTA, 2 #define T3 PORTA, 3 #define T4 PORTA, 4 #define T5 PORTA, 0 ;******************************************************** ; Einsprungpunkt org 0 goto Init ;******************************************************** ; Interrupt Service Routine ;************************************************************** ; die Interuptserviceroutine org 4 intvec bcf INTCON, GIE ; disable Interupt movwf w_copy ; w retten swapf STATUS, w ; STATUS retten clrf STATUS movwf s_copy movf PCLATH, w ; PCLATH retten movwf p_copy clrf PCLATH ; Bank 0 movlw D'131' ; 256-125=131 ((1MHz : 32 ): 125 = 250 Hz) movwf TMR0 ; Intrupt servic routine Int_serv bsf PORTA, 0 ; Ziffer1 aus bsf PORTA, 1 ; Ziffer2 aus bsf PORTA, 2 ; Ziffer3 aus bsf PORTA, 3 ; Ziffer4 aus decf Digit,f ; Ziffernzähler verringern ;Digit=4: anzeigen Ziffer 4 ;Digit=3: anzeigen Ziffer 3 ;Digit=2: anzeigen Ziffer 2 ;Digit=1: anzeigen Ziffer 1 ;Digit=0: andere Aktionen, keine Anzeige btfsc STATUS, Z goto Int_0 ; Z-Flag=1 ergo Digit=0 movfw Digit movwf ar decf ar, f btfsc STATUS, Z goto Int_1 ; Digit=1 decf ar, f btfsc STATUS, Z goto Int_2 ; Digit=2 decf ar, f btfsc STATUS, Z goto Int_3 ; Digit=3 goto Int_4 ; Digit=4 Int_0 movlw 5 movwf Digit btfsc T3 goto Int_end ; Stop-Taste gedrückt decf Timer2, f ; von 5 bis 0 zählen (50 Hz / 5 = 10 Hz) btfss STATUS, Z goto Int_end ; Timer2 <> 0 movlw 5 movwf Timer2 incf sek1, f ; 1/10 Sekunden erhöhen movlw D'10' subwf sek1, w btfss STATUS, Z goto Int_end ; 1/10 Sekunden <> 10 clrf sek1 incf sek2, f ; 1/10 Sekunden erhöhen movlw D'60' subwf sek2, w btfss STATUS, Z goto Int_end ; 1 Sekunden <> 10 clrf sek2 incf min1, f ; 10 Sekunden erhöhen movlw D'10' subwf min1, w btfss STATUS, Z goto Int_end ; 10 Sekunden <> 6 clrf min1 incf min2, f ; 1 Minuten erhöhen movlw D'6' subwf min2, w btfss STATUS, Z goto Int_end ; 1 Minuten <> 10 clrf min2 incf std1, f movlw D'10' subwf std1, w btfss STATUS, Z goto Int_end clrf std1 incf std2, f goto Int_end Int_1 movfw min1 ; Wert der 1. Ziffer call Segmente movwf PORTB ; Segmente einschalten call CA4 ; 1. Ziffer einschalten goto Int_end Int_2 movfw min2 ; Wert der 2. Ziffer call Segmente movwf PORTB ; Segmente einschalten bcf CA3 ; 2. Ziffer einschalten goto Int_end Int_3 movfw std1 ; Wert der 3. Ziffer call Segmente movwf PORTB ; Segmente einschalten bcf CA2 ; 3. Ziffer einschalten goto Int_end Int_4 movfw std2 ; Wert der 4. Ziffer call Segmente movwf PORTB ; Segmente einschalten bcf CA1 ; 4. Ziffer einschalten goto Int_end Int_end swapf s_copy, w ; STATUS zurück movwf STATUS swapf w_copy, f ; w zurück mit flags swapf w_copy, w bcf INTCON, T0IF ; Interupt-Flag löschen bsf INTCON, GIE ; enable Interupt retfie Int_end movf PCLATH_TEMP, W SWAPF STATUS_TEMP,W swapf s_copy, w ; STATUS zurück movwf STATUS swapf w_copy, f ; w zurück mit flags swapf w_copy, w SWAPF W_TEMP,F SWAPF W_TEMP,W bcf INTCON, T0IF ; Interupt-Flag löschen bsf INTCON, GIE ; enable Interupt retfie ;****************7-Segment-Tabelle*************** Segmente addwf PCL, f retlw B'0000001' ; 0 retlw B'1100111' ; 1 retlw B'0010010' ; 2 retlw B'0000110' ; 3 retlw B'1100100' ; 4 retlw B'0100101' ; 5 retlw B'0100001' ; 6 retlw B'0001101' ; 7 retlw B'0000000' ; 8 retlw B'0000101' ; 9 CA1 bcf PORTA,5 bcf PORTC,2 bcf PORTC,3 bsf PORTC,5 return CA2 bcf PORTA,5 bcf PORTC,2 bsf PORTC,3 bsf PORTC,5 return CA3 bcf PORTA,5 bsf PORTC,2 bcf PORTC,3 bsf PORTC,5 return CA4 bcf PORTA,5 bsf PORTC,2 bsf PORTC,3 bsf PORTC,5 return CA5 bsf PORTA,5 bcf PORTC,2 bcf PORTC,3 bsf PORTC,5 return CA6 bsf PORTA,5 bcf PORTC,2 bsf PORTC,3 bsf PORTC,5 return CA7 bsf PORTA,5 bsf PORTC,2 bcf PORTC,3 bsf PORTC,5 return CA8 bsf PORTA,5 bsf PORTC,2 bsf PORTC,3 bsf PORTC,5 return ;****************initialisierung************************** Init ; PIC16F87x alle ADC-Eingänge auf digital I/O umschalten bcf STATUS, RP0 bcf STATUS, RP1 clrf PORTA bsf STATUS, RP0 ; auf Bank 1 umschalten ; movlw 0x06 ; movwf ADCON1 ; PCFG3=1 ; BSF ADCON1, PCFG2 ; PCFG2=1 ; BSF ADCON1, PCFG1 ; PCFG1=1 ; BSF ADCON1, PCFG0 ; PCFG0=1 movlw B'011111' movwf TRISA movlw B'00000000' movwf TRISB movlw B'00000011' movwf TRISC BCF STATUS, RP0 btfsc T3 goto stopp ;***************stoppuhr****************************** stopp ;****************Zeit 0 einstellen******************** clrf sek1 clrf sek2 clrf min1 clrf min2 clrf std1 clrf std2 movlw 5 movwf Digit ;****************250 Hz Timer Interrupt einstellen (Flakern verhindern)**** bsf STATUS, RP0 ; auf Page 1 umschalten bcf STATUS, RP1 movlw B'10000100' ; internet Takt wird gezählt, Vorteiler Timer0 = 32:1 movwf OPTION_REG movlw D'131' ; 255-131=250 ((1MHz : 32) : 250 = 100 kHz) bcf STATUS, RP0 ; auf Page 0 zurückschalten movwf TMR0 movlw 5 movwf Timer2 ; 50Hz --> 10Hz Teiler bsf INTCON, T0IE ; Interrupts im Timer0 erlauben bsf INTCON, GIE ; allgemein Interrupt erlauben endlos goto endlos ;eine endlosschleife