;************************************************************** ;* ;* Pinbelegung ;* ---------------------------------- ;* PORTA: 0 - Spule 1 b2 ;* 1 - spule 1 b1 ;* 2 - spule 2 a2 ;* 3 - spule 2 a1 ;* 4 - Servo Signalgeber ;* 5 - ;* 6 - ;* 7 - ;* Display Tasterturplatine ;* PORTB: 0 - ;* 1 - LCD Display RW Spalte 5 ;* 2 - LCD Display RS spalte 9 ;* 3 - LCD Display E ;* 4 - LCD Display D4 reihe 1 ;* 5 - LCD Display D5 reihe 2 ;* 6 - LCD Display D6 reihe 3 ;* 7 - LCD Display D7 reihe 4 ;************************************************************** ; Includedatei für den 16F628 einbinden #include ERRORLEVEL -302 ;Bankwechselwarnungen nicht angeben ; Configuration festlegen ; Power on Timer, kein Watchdog,Reset, interner Takt RA6 i/O, __CONFIG _PWRTE_ON & _WDT_OFF &_MCLRE_ON & _INTOSC_OSC_NOCLKOUT & _BODEN_OFF & _LVP_OFF ; Konstanten ; Variablennamen vergeben loops equ 0x22 ; Zeit die Ablaufen soll loops2 equ 0x23 ; Zeitkonstante für 1ms loops3 equ 0x24 ;eitkonstante für 0,1ms servotime equ 0x25 ; Zeit des High Signals für den Servo Temp equ 0x26 ;rechen Speicher loops4 equ 0x27 loops5 equ 0x28 loops6 equ 0x29 w_temp equ 0x30 status_temp equ 0x31 Schritt equ 0x32 PORTB_Temp equ 0x33 richtung equ 0x34 ;Bezeichner für Tastertur abfrage ;************************************************************************** #define reihe1 PORTB,4 #define reihe2 PORTB,5 #define reihe3 PORTB,6 #define reihe4 PORTB,7 #define spalte5 PORTB,1 #define spalte9 PORTB,2 ;************************************************************** ;*********Programm beginn nach Reset oder power on************* ;************************************************************** org 0 goto InitPIC ;************************************************************** ;**********Interruptbereich************************************ ;************************************************************** org 4 bcf INTCON,GIE ; Interupt aus ;________Retten schreiben______________________________________ movwf w_temp swapf STATUS,w bcf STATUS, RP0 ; status_temp in Bank 0 movwf status_temp ;______________________________________________________________ ;**************************************************************** CALL wait4ms movF servotime,w ;Servotime in Temp abspeichern movwf Temp bsf PORTA,7 ;Signal ausgabe an CALL Signal ;Highsignal länge bcf PORTA,7 ;Signal ausgabe aus incf Schritt,f ;_____________Rettung lesen_____________________________________ swapf status_temp,w movwf STATUS swapf w_temp,f swapf w_temp,w bcf INTCON,T0IF ; Interupt TM0 an retfie ;************************************************************** ;******************PIC Initialisieren************************** ;************************************************************** ; InitPIC ; Port B auf Ausgabe stellen bsf CMCON,CM0 ;PORTA auf Digital umschalten bsf CMCON,CM1 bsf CMCON,CM2 bsf STATUS, RP0 ; Bank 1 movlw B'11110000' ; PortB alle outputs movwf TRISB movlw B'00000000' ; PortA alle outputs movwf TRISA bcf OPTION_REG, NOT_RBPU ;Pull up Widerstände an bsf OPTION_REG,PS2 bsf OPTION_REG,PS0 bcf OPTION_REG,T0CS bcf OPTION_REG,T0SE bcf STATUS, RP0 ; Bank 0 clrf PORTA clrf PORTB clrf servotime bsf INTCON,T0IE ;interrupt von Timer0 erlauben CALL mitte bsf INTCON,GIE ; Interupt an goto Tabfr ;***************************************************** ;**Tasten abfrage für dreh richtungsbestimmung******** ;***************************************************** Tabfr ;************************************************************************** bcf spalte5 ;Abfrage der Menütasten BTFSS reihe1 CALL mitte ;Menütaste gedrückt ;BTFSS reihe2 ;CALL back ;Zurücktaste gedrückt ;BTFSS reihe3 ;CALL OK ; OK taste gedrückt ;BTFSC reihe4 ;CALL Taste4 ;************************************************** bsf spalte5 nop bcf spalte9 ;Abfrage der Pfeiltasten BTFSS reihe1 CALL rechts ;Pfeilrechts gedrückt BTFSS reihe2 CALL runter ;Pfeilrunter gedrückt BTFSS reihe3 CALL hoch ;Pfeilhoch gedrückt BTFSS reihe4 CALL links ;Pfeillinks gedrückt GOTO Tabfr ;***************************************************** ;Schrittmotor Steuern********************************* ;***************************************************** ;***************************************************** ;***************************************************** ;***************************************************** hoch bcf INTCON,GIE ; Interupt aus movlw B'00001001' movwf PORTA CALL wait100 movlw B'00001010' movwf PORTA CALL wait100 movlw B'00000110' movwf PORTA CALL wait100 movlw B'00000101' movwf PORTA CALL wait100 bsf INTCON,GIE ; Interupt an return ;***************************************************** runter bcf INTCON,GIE ; Interupt aus movlw B'00000101' movwf PORTA CALL wait100 movlw B'00000110' movwf PORTA CALL wait100 movlw B'00001010' movwf PORTA CALL wait100 movlw B'00001001' movwf PORTA CALL wait100 bsf INTCON,GIE ; Interupt an return ;***************************************************** drehen_v addwf PCL, f ;PCL+W retlw B'00001001' retlw B'00001010' retlw B'00000110' retlw B'00000101' Clrf Schritt return ;***************************************************** drehen_r addwf PCL, f ;PCL+W retlw B'00000101' retlw B'00000110' retlw B'00001010' retlw B'00001001' Clrf Schritt return ;************************************************** ; Warteschleifen ;***************************************************** ; Warteschleife 250 ms wait250 movlw D'250' ; 250 ms Pause movwf loops4 goto wai1 ; Warteschleife 100 ms wait100 movlw D'10' ; 100 ms Pause movwf loops goto wai ;Warte schleife 18 MS wait18 movlw D'18' movwf loops goto wai wait4ms movlw D'5' movwf loops goto wai ; Warteschleife, Anzahl der Millisekunden steht in loops wai movlw .110 ; Zeitkonstante für 1ms movwf loops2 Wai2 nop ; nop nop nop nop nop decfsz loops2, F ; 1 ms vorbei? goto Wai2 ; nein, noch nicht decfsz loops, F ; alle ms vorbei? goto wai ; nein, noch nicht retlw 0 ; das Warten hat ein Ende wai1 movlw .110 ; Zeitkonstante für 1ms movwf loops3 Wai3 nop ; nop nop nop nop nop decfsz loops3, F ; 1 ms vorbei? goto Wai3 ; nein, noch nicht decfsz loops4, F ; alle ms vorbei? goto wai1 ; nein, noch nicht retlw 0 ; das Warten hat ein Ende ;********************************************************* ;*************Warteschleife für 0,1ms********************* ;********************************************************* ; rechts clrf servotime movlw D'22' movwf servotime return mitte clrf servotime movlw D'12' movwf servotime return links clrf servotime movlw D'5' movwf servotime return Signal movlw .11 ; Zeitkonstante für 0,1ms movwf loops3 Wai01 nop ; nop nop nop nop nop decfsz loops3, F ; 0,1 ms vorbei? goto Wai01 ; nein, noch nicht decfsz Temp, F ; alle ms vorbei? goto Signal ; nein, noch nicht retlw 0 ; das Warten hat ein Ende END