RoboCar Info 01 EUSART_main =========================== EUSART (RS232 Datenempfang vom Bluetoothmodul HC-05) Initialisierung ;--EUSART Asynchronous Mode ;S.291 ;25.1.1.1 Enabling the Transmitter ;The EUSART transmitter is enabled for asynchronous operations ;by configuring the following three control bits: ;• TXEN = 1 ;• SYNC = 0 ;• SPEN = 1 ; ;25.1.2.1 Enabling the Receiver S.295 ;The EUSART receiver is enabled for asynchronous operation by ;configuring the following three control bits: ;• CREN = 1 ;• SYNC = 0 ;• SPEN = 1 ;All other EUSART control bits are assumed to be in ;their default state. ;Setting the CREN bit of the RCSTA register enables the receiver ;circuitry of the EUSART. Clearing the SYNC bit of the TXSTA ;register configures the EUSART for asynchronous operation. ;Setting the SPEN bit of the RCSTA register enables the EUSART. ;The programmer must set the corresponding TRIS bit to configure ;the RX/DT I/O pin as an input. ; BANKSEL TXSTA ;TRANSMIT STATUS AND CONTROL REGISTER S.298 ; clrf TXSTA ; bsf TXSTA,TXEN ;b5 Transmit enabled ; bcf TXSTA,SYNC ;b4 Asynchronous mode ; bsf TXSTA,BRGH ;b2 " in low speed ; BANKSEL RCSTA ;RECEIVE STATUS AND CONTROL REGISTER S.299 clrf RCSTA ;bank3 bsf RCSTA,SPEN ;b7 0/1 Receive/(send & config TX-pin as output) bsf RCSTA,CREN ;b4 Enables receiver ;All other EUSART control bits are assumed to be in their ;default state. ;Setting the TXEN bit of the TXSTA register enables the transmitter ;circuitry of the EUSART. Clearing the SYNC bit of the TXSTA register ;configures the EUSART for asynchronous operation. Setting the ;SPEN bit of the RCSTA register enables the EUSART and automatically ;configures the TX/CK I/O pin as an output. If the TX/CK pin is ;shared with an analog peripheral, the analog I/O function must be ;disabled by clearing the corresponding ANSEL bit. ; ;25.1.2.8 Asynchronous Reception Set-up: ;1.Initialize the SPBRGH, SPBRGL register pair and the BRGH and ; BAUDCON,BRG16 bits to achieve the desired baud rate ; (see Section 25.3 “EUSART Baud Rate Generator (BRG)”). BANKSEL BAUDCON ;bank3 BAUD RATE CONTROL REGISTER S.300 bcf BAUDCON,BRG16 ;b3 8-bit Baud Rate Generator ; BANKSEL SPBRGH ;bank3 movlw 0 ;0x0019 (d'25' Baudrate=9600 vgl. S.301 movwf SPBRGH movlw .25 movwf SPBRGL ;2.Clear the ANSEL bit for the RX pin (if applicable). ;3.Enable the serial port by setting the SPEN bit. The SYNC bit ; must be clear for asynchronous operation. ;4.If interrupts are desired, set the RCIE bit of the PIE1 ; register and the GIE and PEIE bits of the INTCON register. ;5.If 9-bit reception is desired, set the RX9 bit. ;6.Enable reception by setting the CREN bit. ;7.The RCIF interrupt flag bit will be set when a character is ; transferred from the RSR to the receive buffer. An interrupt ; will be generated if the RCIE interrupt enable bit was also set. ;8.Read the RCSTA register to get the error flags and, if 9-bit ; data reception is enabled, the ninth data bit. ;9.Get the received 8 Least Significant data bits from the receive ; buffer by reading the RCREG register. ;10.If an overrun occurred, clear the OERR flag by clearing the ; CREN receiver enable bit. ; ;------------------------- ; Hauptprogramm ;------------------------- main_loop: ;1.Bluetooth-Command aus USART lesen btfss PIR1,RCIF ;=1? New data received with USART? GOTO main_loop ;no, try it again ;2.Store received command in variable tmpRCREG BANKSEL RCREG movf RCREG,w ;copy received command to WREG BANKSEL 0 movwf tmpRCREG ;copy command to working variable ; movlw LINE1+.4 ;display tmpRCREG in LCD CALL Out_Command ;Send DDRAM_Addr, Char (06_Robo_LCD.INC) ;----------------------------------------------------------------- ;Ab hier beginnt die Auswertung des empfangenen Befehls, Umsetzung ;in Fahrtrichtung und Fahrgeschwindigkeit, ;DC4, DC5 enthalten den Wert für duty cycle von PWM4 (linke ;Antriebsseite und PWM5 (rechte Antriebseite) ;Befehle für Fahrtrichtung: F forward, B backward, S stop ; R nach rechts,L nach links, N neutral ; + schneller - langsamer ;Zur Vereinfachung der Abfragen werden die Fahrbefehle, welche ja ;als ASCII-Code vorliegen, zuerst ausgewertet und in Flags umgesetzt, ;was die weitere Verarbeitung im Programm erheblich vereinfacht. ;z.B, FlagsYX,7:0, enhält u.a. Fahrtrichtung (F,S,B)und Hindernisse. ;------------------------------------------------------------------ ;3.check: should DC4,DC5 be increased/decreased? CALL Speed_UP_DOWN ;check tmpRCREG = "+" incr. "-" decr speed btfsc Flags,NOSPEED ;Flags,b6=1? GOTO main_loop ;YES speed increased/decreased successfully ; mainrx_y: ;4.checks whether a valid Y-control character was received CALL RX_Check_Y ;ptüfe gültiges Y-comandd (F,S,B)? btfss STATUS,Z ;Z=1, YES command = F or S or B auswerten GOTO mainrx_x ;Z=0, NO check for L,N,R ; CALL RX_Ctrl_Y ;Y-KOMANNDO AUSWERTEN movlw LINE2+.4 CALL Out_Command ;display prozessed Y-Commandd GOTO mainrx_forw ; mainrx_forw: ;6.motors for forward and cornering btfsc FlagsYX,FORW ;b1 CALL Drive_Forw ;Toggle motors for FORWARD/cornering ; main_rx_stop: ;7.Switch motors for stop and cornering btfsc FlagsYX,STOP ;b2 CALL Drive_Stop ;Toggle motors for STOP/cornering ; ;8.motors for reverse and cornering btfsc FlagsYX,BACKW ;b3 CALL Drive_Backw ;Toggle motors for BACKWARD/cornering ; ;8.DC for motors left drive movf tmpDC4,w BANKSEL CCPR4L movwf CCPR4L ;DC Drive4 (linke Seite) BANKSEL 0 ; ;10.DC for motors right drive movf tmpDC5,w BANKSEL CCPR5L ;DC Drive5 (rechte Seite) movwf CCPR5L BANKSEL 0 ; movlw LINE2+.8 ;Ausgabe tmpDC4 dez movwf LcdAddr movf tmpDC4,w CALL Bin8_Dez_1 ; movlw LINE2+.13 ;Ausgabe tmpDC5 dez. movwf LcdAddr movf tmpDC5,w CALL Bin8_Dez_1 ; main_end: GOTO main_loop