🇩🇪
Zitat von: Ottmar in 15.08.2023, 20:10:16 CESTRoboCar Info 06Hallo Ottmar! Diese deine Einschätzung geht nicht wirklich fehl! Leider!
Hmm.. anscheinend befinde ich mich auf dem besten Weg ein dauerhaftes Selbstgespräch zu führen...
mfG Ottmar
Anmerkung:
Zahlen S... oder DS beziehen sich auf die Seite im Datenblatt
zum PIC16F1936
;---------------------------------------------------------------------
;--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
;All other EUSART control bits are assumed to be in 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.
;
; 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
;
;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 default state.
;
BANKSEL RCSTA ;RECEIVE STATUS bank3 S.299
; b7=1 SPEN Serial port enabled RX/DT autom set as PORT pins
; b6=0 RX Selects 8-bit reception
; b5=0 SREN asyncmode don't care
; b4=1 CREN enble async eceiver
; b3=0 ADDEN don't care in 8bit async mode
; b2=0 FERR Flag framing error
; b1=0 OERR Flag overrun error
; b0=0 RX9D don't care in 8 bit mode
movlw b'10010000'
movwf RCSTA
;
;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
btfss PIR1,RCIF ;=1? New Bluetooth command received?
GOTO main_rx_loop ;no, try it again
;
BANKSEL RCREG ;bank3
movf RCREG,w ;copy received command
BANKSEL 0
movwf tmpRCREG ;containss now received Ascii code
MODULES IN INIT PROJECT ROBOCAR2023
03_INIT_Robo2023.INC
OSCCON
PORTA L298_PORT
PORTB LCD_PORT
AD_PORT
PORTC SCI_PORT
US_PORT
PWM_PORT
T2CON
CCPR1L
CCPR2L
CCP1CON
PSTR1CON
PR2
PR4
CCPTMRS0
PIR1,TMR2IF
PIR3,TMR4IF
RCSTA
BAUDCON
SPBRGH
SPBRGL
ADCON0
ADCON1
FVRCON
CALL Lcd_Init
CALL Lcd_Ready
PRESET VARIABLES
T6CON
TMR6
INTCON
;----------------------------------------
SUBROUTINES IN PROJECT RoboCar2023
04_DRIVE_Robo2023.INC
Eval_Cmd ;Calling up the subprograms for evaluating
; the possible Rx commands
Cmd_Lights
cmd_eval_front ;frontlights on
cmd_eval_front0 :frontlights off
cmd_eval_back
cmd_eval_back0
cmd_eval_park
cmd_eval_park0
cmd_eval_horn
cmd_eval_horn0
cmd_eval_extra
cmd_eval_extra0
Cmd_Extra ;switches headlights and taillights to flashing
cmd_extra_on
cmd_extra_high
cmd_extra_low
Cmd_Extra_OFF
Cmd_Drive
cmd_drive_F....
Cmd_Speed
cmd_speed_0...10
;----------------------------------------
05_US_Robo2023.INC
US_Measure ;US-Burst, TMR1,runtime measurement
US_Distance ;convert TMR1 to BCD4:0
Obstacle_Left ;Obstacle closer than 15cm on the left?
Obstacle_Right ;Obstacle closer than 15cm on the right?
Bin32_Dez
;MULT16x16 ;unused
;
07_LCD_Robo2023.INC
table_debug ;eg. dt LINE1+.0,"Rx:. Vdd ..,..V", 80h
LcdOut_Table ;Read table, display Mask in LCD
Out_Menue_Control ;Output of the parameters in the LCD
out_vdd
out_info1_info2
Out_Vdd_MCU
Out_Vdd_Drive
Out_DC1_DC2
Out_Rx ;control actual bluetooth command
Out_US_Distance
Out_Obstacle_Left ;Set a flag if there is an obstacle
Out_Obstacle_Right
;
LeadZero_Lcd removes leading zeros 004,72 -> 4,72
BCD_2Bit_Mult10
Bin16_Dez
Bin8_Dez_1
OutBinReg ;Debugging
Mult10_8Bit
;----------------------------------------
16F1936_RoboCar2023.ASM
=======================
; Projekt: Control of RobotCar via Bluetooth
; MCU: PIC1F1936 (28Pin)
; Info: Program Memory Words Used: 1294
; Average duration of a program cycle
; with LCD ca. 38ms (for program development)
; without LCD (final) around ca. 2.7-4ms
; fosc=8MHz
#INCLUDE <02_HEADER_RoboCar2023.INC> ;Labels, definitions, constants, etc
#INCLUDE <03_INIT_Robo2023.INC> Initialization of all required
;registers, ports, PWM, EUSART, LCD, etc
main;
CALL Debug_Menue ;Creates the LCd menu for function
;testing and troubleshooting
main_loop:
CALL US_Measure ;Send/receive US-Burst/Echo
CALL US_Distance ;Calculates the distance from US-runtime
CALL Obstacle_Dodge ;Calculates required avoidance of obstacles
btfsc Flags,EXTRA ;=1 execute functions when waiting for rx cmd
CALL Cmd_Extra ;Switching of special functions light, horn
;
main_rx_loop: ;waiting for bluetooth command
btfss PIR1,RCIF ;=1? New data received with USART?
GOTO main_rx_loop ;no, try it again
;CALL Rx_Error ;Error checking RCSTA,FERR:OERR (disabled)
BANKSEL RCREG ;bank3
movf RCREG,w ;copy received command
BANKSEL 0
movwf tmpRCREG ;contains received Ascii code
;
CALL Out_RX ;display received Bluetooth-command (cmd)
CALL Eval_Cmd ;evaluate/execute command ->04_DRIVE_Robo
GOTO main_loop
;----------------------------------------
#INCLUDE <04_DRIVE_Robo2023.INC> ;Drive control subprograms
#INCLUDE <05_US_Robo2023.INC> ;ultrasonic distance measurement
#INCLUDE <07_LCD_Robo2023.INC> ;LCD output, binary BCD conversion, etc
#INCLUDE <HD44780_2WIRE.INC> ;initialization, DDRAM, DATA
END
;-----------------------------------------
SECTIONS IN FILE 02_HEADER_ROBOCAR2023.INC
; --SUPPRESSED WARNINGS
; --MCUDEFINITION / CONFIGURATION
; --VARIABLES DEFINITIONS
; LABELS & CONSTANTS
; --L298_PORT (PORTA)
; --LCD_PORT (PORTB)
; --AD_PORT (PORTB)
; --SCI_PORT EUSART (PORTC)
; --US_PORT (PORTC)
; --PWM_PORT (PORTC)
; --DDRAM ADDRESSES for output in debug menu
; LCD-PROPERTIES
; RESET VECTOR
; INTERRUPT VEKTOR
ISR
isr_tmr6
;----------------------------------------