This paper presents a practical framework for the design and real-time implementation of a Power Management System (PMS) for microgrids based on Supervisory Control Theory (SCT) for discrete-event systems. A detailed step-by-step methodology is provided, which covers the entire process from defining discrete events, modeling microgrid components, synthesizing supervisory controllers, and realizing them in MATLAB (R2024b) Stateflow. This methodology is applied to a case study, where a decentralized supervisor controller is designed for a microgrid containing a Battery Energy Storage System (BESS), a generator set (Genset), a wind and a solar generation system, critical loads, and noncritical loads. Unlike previous works based on SCT, the proposed PMS addresses the following functionalities: (i) grid-connected and islanded operation; (ii) peak shaving; (iii) voltage support; (iv) load shedding. Finally, a CHIL testing is employed to validate the synthesized SCT-based PMS.