DCS Course
A comprehensive embedded system and PC interface for detecting light sources and object proximity using an MSP430 MCU.
- Layering: BSP → HAL → API/APP → main (FSM, interrupt-driven)
- I/O: UART 9600 bps
- Display: LCD 16×2
- Sensors: HC-SR04 (Ultrasonic) + two LDRs (Light Dependent Resistors)
- Motor: SG90 servo motor
| Pin | Function | Description |
|---|---|---|
| P1.0 | Analog Input (A0) | LDR1 Signal |
| P1.1 | UART | RXD |
| P1.2 | UART | TXD |
| P1.3 | Analog Input (A3) | LDR2 Signal |
| P1.4 | Digital Output | LCD Data D4 |
| P1.5 | Digital Output | LCD Data D5 |
| P1.6 | Digital Output | LCD Data D6 |
| P1.7 | Digital Output | LCD Data D7 |
| P2.0 | Digital Input | PB0 (LDR Calibration Button) |
| P2.1 | Digital Output | LCD Control Signal (E) |
| P2.2 | Timer A1 CCR1 | Ultrasonic Sensor Output (ECHO) |
| P2.3 | Digital Output | LCD Control Signal (RS) |
| P2.4 | Timer A1 CCR2 | PWM Out (Servo Motor Control) |
| P2.5 | Digital Output | LCD Control Signal (RW) |
| P2.6 | Timer A0 CCR1 | Ultrasonic Sensor Input (TRIG) |
| P2.7 | Digital Input | PB1 |
- Headers:
app.h,api.h,halGPIO.h,bsp_msp430x2xx.h - Sources:
bsp.c,halGPIO.c,api.c,main.c
- Main Entry:
main.py - Modules:
comm/,gui/,processing/,visualization/
app.h: Constants & memory map (Flash addresses, sizes), Enums (FSM states, ScanMode, FileType),FileEntrystructure, extern shared states.api.h: APP/API prototypes for detectors, measurements, file system operations, and calibration sequences.halGPIO.h: HAL prototypes for LCD, UART, ADC, Timers, PWM, Ultrasonic, Flash, circular RX buffer, and LPM helpers.bsp_msp430x2xx.h: BSP pin mapping, general macros, Timer/ADC/UART defines, and ISR vectors.
Low-level board bring-up and system helpers:
GPIOconfig,Timers_Init,ADC_config,UART_init- LPM and global IRQ utilities (
enterLPM,enable_interrupts)
Direct hardware layer and ISRs:
- LCD:
lcd_init,lcd_cmd,lcd_data,lcd_puts - UART:
UART_send_char,UartBuffer_Init/Put/Get - Timers/Ultrasonic: Blocking delays,
Ultrasonic_Start_Measurement - PWM/Servo:
pwmOutServoConfig,Set_Angle_PWM - ADC:
ADC_Enable,ADC_sample, channel configs - Flash: Timing, erase/write operations
- ISRs: Buttons (
PBs_handler), Timers (Timer_1_ISR,Timer0_A0_ISR_Handler), ADC (ADC_ISR)
High-level logic, runtime FSMs, Flash filesystem, scripts, and scanning:
- Scans & Sensing:
servo_scan,object_detector,telemeter,light_detector,light_object_detector - LDR Calibration:
run_calibration_sequence,write_all_calib_to_flash,send_calib_arr - Filesystem:
FileSystem_Init,Handle_UploadFile_Start,Handle_Upload_Byte, script interpreters (parse_and_execute_line)
Initialize layers, run RX loop, decode UART commands, and dispatch FSMs.
The PC-side provides a PySimpleGUI desktop application to control all modes, run calibration, manage files, process sensor data, and plot polar maps.
Key Functionalities:
- Serial Management: UART communication wrapped in
serial_manager.py. - GUI Modules: Isolated event loops for Objects, Telemeter, Lights, Combined, and File modes.
- Processing: Signal smoothing, valley/peak detection, filtering, and crosstalk cleaning (
process_light_scan_data). - Data Visualization: Matplotlib polar plots for detected objects and light sources.
- File Upload Protocol: Handles MCU handshake, checksum generation, and 64-byte chunked flashing.
Script Opcodes:
| Command | Hex | Command | Hex |
|---|---|---|---|
inc_lcd |
0x01 |
dec_lcd |
0x02 |
rra_lcd |
0x03 |
set_delay |
0x04 |
clear_lcd |
0x05 |
servo_deg |
0x06 |
servo_scan |
0x07 |
sleep |
0x08 |
Control Markers:
- Start-of-Script =
0xCC - Telemetry Header =
0xFE - End/Sleep =
0x7F - End-of-Scan =
FF FF FF
Handshakes & Commands:
- Handshake:
'P'→ MCU replies'A' - Objects:
'S'→ stream of (2B distance + 1B angle) per step; end markerFF FF FF - Lights:
'K'→ stream of (LDR1_lo, LDR1_hi, LDR2_lo, LDR2_hi, angle) - Combined:
'X'→ stream of (2B distance, 2B LDR1, 2B LDR2, 1B angle); end markerFF FF FF - Telemeter:
'T'+ angle byte → MCU returns (2B distance + 1B angle) - Files:
'L'(List),'U'(Upload),'R'(Run script),'V'(LCD view mode),'D'(Delete FS)
- Calibration:
'J'(Guided LDR capture),'Z'(Read back compressed array)
Note: Endianness is Little-Endian (first Low-Byte, second High-byte).
- Arkady Gerasimuk
- Adi Shlomo