SlideShare a Scribd company logo
LECTURE 1
ECE 3567 Microcontroller Laboratory
Spring 2025
Dr. Gregg J Chapman
ECE 3567 Syllabus
ECE 3567 Syllabus
Spring 2024
Lectures and Labs
ECE 3567 Syllabus
Spring 2025
ECE 3567 Syllabus
Spring 2025
ECE 3567 Microcontroller Lab
What to expect:
β€’ There is one video before each lab on the website under The Laboratories
β€’ Available no later than midnight on the Sunday before the lab.
β€’ Watch the video first
β€’ Take the quiz
β€’ This can be done BEFORE or AFTER the lab, up until MIDNIGHT on the Friday
following the lab.
β€’ This semester, the checkpoints will be awarded by the Lab Monitors
β€’ BEFORE you leave the laboratory, SIGN the checkpoint sheet.
β€’ The Commented CODE must be uploaded to Carmen prior to MIDNIGHT on the
Friday following the lab.
Spring 2025
ECE 3567 Microcontroller Lab
Programs (Code)
β€’ Submitted electronically Please use PDF format.
β€’ Must Contain:
1. A COMPLETED Standard File Header for each file submitted.
2. All code for the lab.
3. A comment on each line of code (unless it doesn’t make sense)
4. Additional comments before each function, describing what it does.
β€’ Since this replaces a lab report, it must completely define the program to the extent
that the lab could be duplicated from the information included in the submission.
ECE 3567 Website
u.osu.edu/ece3567labs/
ECE 3567 Microcontroller Lab
ECE 3567 Microcontroller Lab
ECE 3567 Microcontroller Lab
ECE 3567 Microcontroller Lab
ECE 3567 Microcontroller Lab
Embedded System Design
Embedded System
MICROCONTROLLER
(MCU)
Field Programmable
Gate Array
(FPGA)
MEMORY
Inputs
(Sensors)
Outputs
β€’ Actuators
β€’ Displays
β€’ Feedback
ECE 3567 Microcontrollers
Embedded Hardware
Microprocessor (ΞΌP)
Micro-Controller (MCU)
Is there Value in Learning
Embedded C Programming
?
?
Embedded Programming Languages
Embedded Development Talk
March, 2022
Embedded Programming Languages
Survey Results from IEEE Spectrum July 2020
Embedded Programming Languages
geeksforgeeks.com October 23, 2024
Embedded Programming Languages
β€œPython, C, and C++ are clear choices”
Embedded Development Talk March, 2022
β€’ C
β€’ C++
β€’ Java
β€’ Python
β€’ Rust
β€’ Assembly Language
β€’ Generative AI
β€’ Others: ADA, Lua, B#, Verilog
Embedded Program Language
C Programming
C is among the best programming languages for embedded systems. It is one of the oldest
and most widely used embedded programming languages, which was developed in the
early 1970s. C is a compiled language that helps to create programs for low-level
microcontroller applications such as those found in automotive applications and home
appliances.
C language is the industry standard for a wide variety of applications, with estimates
suggesting that up to 80% of embedded systems leverage the language. C is favored for its
efficiency and widespread use in the sector. The downside of this embedded systems
programming language is that its developers must be knowledgeable and be able to utilize
complex coding techniques.
Embedded Program Languages
C++
C++
Another popular embedded programming language is C++. This language for embedded
systems offers many advantages to coders, due to their efficiency and standard library. C+
+ is especially effective as it can streamline the coding process by providing useful libraries
that make writing code faster and simpler. However, one major disadvantage of this
embedded programming language is that it is not easy to learn due to its complexity.
β€’ Reduces development time
β€’ Common
β€’ Superset of Embedded C
Embedded Program Languages
Java
Java
Java is a programming language that is efficient and versatile, it has been very popular in
internet-based applications. And for embedded systems, it does a great job with devices
that rely on the Android operating system. IT IS TOO SLOW FOR MANY APPLICATIONS.
The main benefit of this embedded programming language is its portability (really?).
Additionally, due to their reliable nature, such programs are extremely reliable and enable
greater control when interacting with low-level hardware. This makes a great difference
with software (firmware vs software).
β€’ GUI Development
Embedded Program Languages
Assembly
Assembly
Assembly is a well-known language for embedded systems. The great benefit of this
language is that it is capable of interacting easily with hardware systems. The downside of
this language is its complexity and difficulty to maintain in the long term.
Nowadays, assembly embedded language is not used a lot, we recommend using it only if
you want an absolute control of the system, or in the scenario where you want to build
your own OS (Operative System).
β€’ Minimal code size
β€’ Speed
β€’ Low Level Programming Capability
Embedded Program Languages
Python
Python
Embedded Program Languages
Rust
Rust
Because of its great efficiency, numerous safety features, typestate programming
approach, and zero-cost abstractions, Rust is a suitable language for embedded systems
programming. Rust supports managing memory both dynamically and statically using a
variety of techniques. Small microcontrollers to huge, complex systems may all be
programmed using the Rust programming language. Rust has a sizable community that
supports it as an embedded systems programming language.
β€’ Memory security
β€’ Low Level Programming Capability
Embedded Programming Languages
Embedded C Programming – C / Embedded C / ASM
C Programming Language
β€’ Structure oriented
β€’ Platform specific (processor)
β€’ Compiler used to generate
machine code
β€’ Assumes FAST processor
β€’ Generalized applications
β€’ Requires an OS interface
Assembly Language
β€’ Fastest Speed
β€’ Smallest Code Size
β€’ Too difficult for large scale projects
Embedded C Programming
β€’ VERY different coding style
β€’ Subset of C
β€’ Can be faster and more efficient than β€œC”
β€’ Hardware oriented
β€’ Cross-compiler used to generate
ASM, HEX, and Machine Code
β€’ Microcontroller specific
β€’ Smaller code size
β€’ Speed limited by MCU
β€’ Can be used to interface environment through sensors
and actuators
β€’ Lower cost than computer
β€’ Lower power than computer
β€’ More reliable that OS based systems
β€’ Can provide better security
Embedded C Programming - Distinctives
β€’ Embedded C is a SUBSET of the C Programming Language.
β€’ Like assembly language, it is written to operate directly on HARDWARE.
β€’ ALL features unique to C++ are nearly useless at the embedded level.
β€’ High level software engineers NEARLY ALWAYS look down their nose at the
embedded coding style. They consider it β€œsophomoric”, because it does not take
advantage of many aspects of high-level languages. Please understand that adopting
other coding styles and methods leads to sacrifices in execution speed, code size,
and ease of understanding. Code optimization is often critical in embedded systems.
Advice: Keep an open mind. Intellectual smugness is seen as ignorance in the
electronics community and, unfortunately, is all too common.
Embedded C Programming - Distinctives
β€’ Almost all embedded code is contained in HEADER files, both from the
manufacturer and the person writing the code.
β€’ Embedded code is MICROCONTROLLER SPECIFIC, and only portable to another
application of the same MCU with the same interfaces.
β€’ Almost ALL embedded code contains re-used header files from the IC
manufacturer, written for the same MCU.
Max Headroom
Embedded C Programming - Distinctives
β€’ Trying to write embedded code without using the manufacturer’s header files
is PURE INSANITY.
Bela Lugosi
Embedded C Programming – Cross Compiler
Inputs: .c, .h
Executable: .hex, .bin Debugging, .lst is an ASM file
Assembly: .asm, .a
Object files: .o, .obj
Pre-processor output files: .i
Source files: .s (MCU specific)
Other Considerations
Integrated Development Environment (IDE)
β€’ An IDE includes:
β€’ Top Level Project Manager
β€’ Source Code Editor
β€’ Support for a specific Program Language
β€’ Compiler
β€’ Assembler
β€’ Linker (Build Integration)
β€’ Debugger
Integrated Development Environment (IDE)
β€’ POPULAR IDEs
β€’ Visual Studio (Microsoft) (Adaptable. Almost universal)
β€’ Code Composer Studio (TI)
β€’ MPLAB (ST Microelectronics)
β€’ Arduino
β€’ Red Hat (Linux)
β€’ Eclipse
Pros:
β€’ Off Site backup
β€’ Industry Standard for Code Sharing
β€’ Well Supported
Cons:
β€’ Hopelessly Complex
β€’ Long Learning Curve
β€’ May not be Secure
Version Management
GITHub
Do you need an Operating System?
β€’ Almost ALL embedded applications have a single task.
β€’ You can use a REAL TIME Operating System for a Single Task (RTOS). You must use a
full OS for multi-tasking.
β€’ The additional complexity and scheduling of events in an RTOS creates MANY
resource constraints. AN OS in general will reduce reliability.
β€’ A Real Time OS is only worth the overhead for VERY complex single tasks and a
highly interactive Graphical User Interfaces.
β€’ In my opinion, the RTOS environment is RARELY worth the trouble and additional
resources.
β€’ HOWEVER, an RTOS can significantly cut development time., especially for GUIs.
Marketable Skills
β€’ Languages - Embedded C, Python
β€’ MCU Communications - I2C, SPI
β€’ MCU Peripherals – GPIO, Timers, ADC, DAC
β€’ Ability to Read a Schematic
β€’ Familiarity with Hardware Test Equipment
β€’ Familiarity with RISC Instruction Set and ARM Microcontrollers
β€’ Interrupt Driven Design
β€’ Real Time Operating Systems
β€’ Linux OS Experience
β€’ Ability to work within a Version Control Environment
β€’ Debugging Skills
β€’ GUI Development (Java)
β€’ Internet of Things (IoT)
Embedded Programming Language Trends
1.The rise of AI Developed Systems
2.Open-Source Code
3.Security will be king
4.More modern languages (C++, Rust)
5.Simulation-first Development
6.DevOps (IT involved) and Observability
7.Edge (of network) AI
β€œ7 Embedded Software Trends to Watch in 2025” –
DesignNews, December 17th
, 2024
ECE 3567 Microcontrollers
TI LaunchPad (MSP430FR6989)
fcutoff = 6 Hz
A5 input on ADC12
RC charging circuit
P2.1 RC PWM output
ADC – A5
ECE 3567 Microcontrollers
Custom Designed BoosterPack
RGB PWMs to LED
Heating Circuit
The MSP430FR6989 Microcontroller Architecture
Timers:
TA0 – ISR, Command, USCI_A0
TA1 – ADC12, USCI_A1
TB0 – PWMs
Code Composer Studio (TI)
Our Development Platform
ECE 3567 Microcontrollers
Code Composer Studio
47
ECE 3567 Microcontrollers
Code Composer Studio
Documentation
ECE 3567 Microcontrollers
Embedded C Programming – Documentation
1 – Create a documentation standard
2 – Use a consistent coding style
3 – Use a documentation template
4 – Use a file header
5 – Comment before coding
6 – Document as you go not afterwards
7 – Update comments when making coding changes
8 – Consistent use of commenting brackets and location
9 – Write non-obvious comments – Explain the why, NOT the how
10 – Provide example uses to increase clarity
ECE 3567 Microcontrollers
Embedded C Programming – File headers (.c)
ECE 3567 Microcontrollers
Embedded C Programming – Comments
Compiler directives and .h files
ECE 3567 Microcontrollers
Embedded C Programming – Compiler Directives
β€’ #define – Declares a constant and may or may not give it a
value. Can also be used to label a macro.
β€’ #include – A compiler directive that adds the contents of an external file to the current file definition.
#include β€œstdio.h” // has to be between quotes or carrots <>
#include β€œ3567.h”
β€’ #pragma – Tells the compiler to include something once if it
is included in multiple files.
β€’ #ifdef – Conditional compilation based on a definition
#endif
#define __MSP430FR6989
#ifdef __MSP430FR6989__
#include <msp430fr6989.h>
#else
#include <msp430.h>
#endif // __MSP430FR6989__
#define RED 0x11
Usage is reserved
#typedef
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef long int64_t;
typedef unsigned long uint64_t;
#typedef – Defines an alias name or a new type
The typedefs for abbreviated variable types are defined in stdint.h
const uint16_t BaseAddress;
// Base Address of EUSCI_A port
const uint8_t TxPort;// GPIO Port settings for TX pin
ECE 3567 Microcontrollers
Embedded C Programming – TI header files (.h)
#include
"inc/hw_memmap.h"
#include "adc12_b.h"
#include "aes256.h"
#include "comp_e.h"
#include "crc.h"
#include "crc32.h"
#include "cs.h"
#include "dma.h"
#include "esi.h"
#include "eusci_a_spi.h"
#include "eusci_a_uart.h"
#include "eusci_b_i2c.h"
#include "eusci_b_spi.h"
#include "framctl.h"
#include "gpio.h"
#include "lcd_c.h"
#include "mpu.h"
#include "mpy32.h"
#include "pmm.h"
#include "ram.h"
#include "ref_a.h"
#include "rtc_b.h"
#include "rtc_c.h"
#include "sfr.h"
#include "sysctl.h"
#include "timer_a.h"
#include "timer_b.h"
#include "tlv.h"
#include "wdt_a.h"
extern void ADC12_B_setAdcPowerMode(uint16_t baseAddress, uint8_t powerMode);
#define ADC12_B_START_AT_ADC12MEM0 (ADC12CSTARTADD_0)
#define ADC12_B_START_AT_ADC12MEM1 (ADC12CSTARTADD_1)
#define ADC12_B_START_AT_ADC12MEM2 (ADC12CSTARTADD_2)
#define ADC12_B_START_AT_ADC12MEM3 (ADC12CSTARTADD_3)
#define ADC12_B_START_AT_ADC12MEM4 (ADC12CSTARTADD_4)
#define ADC12_B_START_AT_ADC12MEM5 (ADC12CSTARTADD_5)
#define ADC12_B_START_AT_ADC12MEM6 (ADC12CSTARTADD_6)
#define ADC12_B_START_AT_ADC12MEM7 (ADC12CSTARTADD_7)
#define ADC12_B_START_AT_ADC12MEM8 (ADC12CSTARTADD_8)
#define ADC12_B_START_AT_ADC12MEM9 (ADC12CSTARTADD_9)
#define ADC12_B_START_AT_ADC12MEM10 (ADC12CSTARTADD_10)
#define ADC12_B_START_AT_ADC12MEM11 (ADC12CSTARTADD_11)
#define ADC12_B_START_AT_ADC12MEM12 (ADC12CSTARTADD_12)
#define ADC12_B_START_AT_ADC12MEM13 (ADC12CSTARTADD_13)
#define ADC12_B_START_AT_ADC12MEM14 (ADC12CSTARTADD_14)
#define ADC12_B_START_AT_ADC12MEM15 (ADC12CSTARTADD_15)
#define ADC12_B_START_AT_ADC12MEM16 (ADC12CSTARTADD_16)
typedef struct ADC12_B_initParam
{
//! Is the signal that will trigger a sample-and-hold for an input signal
//! to be converted.
uint16_t sampleHoldSignalSourceSelect;
//! Selects the clock that will be used by the ADC12B core, and the
uint8_t clockSourceSelect;
//! Selects the amount that the clock will be divided.
uint16_t clockSourceDivider;
//! Selects the amount that the clock will be predivided.
uint16_t clockSourcePredivider;
//! Selects what internal channel to map for ADC input channels
uint16_t internalChannelMap;
} ADC12_B_initParam;
Compiler Directives
TI β€œmacro” functions or prototypes
Structures
ECE 3567 Microcontrollers
Embedded C Programming – Custom Header files (.h)
Embedded C Programming- Examples
ECE 3567 Microcontrollers
Embedded C Programming – MicroChip (PICC)
/******************** Microchip Inc. PICC Process Code **************************/
#include <pic.h>
#define XTAL_FREQ 4MHZ
#include "delay.h"
#include "delay.c"
#define TIMEOUT 8 //-- Minutes to timeout
#define MAXTIME (TIMEOUT * 60 * 1000000)/256 //-- us divided by 256
#define SECOND (1000000/256) //-- counts per second
#define OFF 1 //-- OFF State of output
#define ON 0 //-- ON State of output
#define TIMEOUT_ON 1 //-- ON State for Timeout LED
#define TIMEOUT_OFF 0 //-- OFF State for Timeout LED
#define TRUE 1
#define FALSE 0
#define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit))
static bit DEAD @ BITNUM(GPIO, 0); //- Dangerously LOW
static bit EMPTY @ BITNUM(GPIO, 1); //- Lower Limit
static bit FULL @ BITNUM(GPIO, 2); //- Upper Limit
static bit OUTPUT @ BITNUM(GPIO, 4); //- Output Control Pin
static bit TIMEOUTPIN @ BITNUM(GPIO, 5); //- Timeout Indicator.
unsigned long Counter;
bit CountEnabled;
bit Filling;
bit TMRHIGH;
//***************************************************************
//main
//***************************************************************
void main (void)
{
char HourNotUp=0,Minute,Second;
OPTION=0xD8; //- 11011000 Set up the option Register
GPIO=0xFF; //-- All Outputs HIGH
TIMEOUTPIN=TIMEOUT_OFF; //-- No Timeout yet so turn LED OFF
OUTPUT=OFF; //-- Don't Fill so Output is OFF
TRIS=0x0F; //-- Set Up 0 to 3 as input rest as output
CountEnabled=0;
Counter=0;
Filling=0;
TMRHIGH=0;
while(1)
{
ECE 3567 Microcontrollers
Embedded C Programming – Motorola
/******** ********* ********* ********* ********* ********* ********* *********/
void Tilt_ctl(void)
{ int i;
unsigned int counter;
TMSK1 &= 0xCF; /* disable timer 3, 4 interrupt */
counter = TCNT; /* get the current counter value */
TOC3 = counter + 2000; /* set timer 3 to clock at +1ms */
TCTL1 = (TCTL1 & 0xCF) | 0x30; /* set timer 3 to go HIGH then */
TOC4 = counter + 2000; /* set timer 4 to clock at +1ms */
TCTL1 = (TCTL1 & 0xF3) | 0x0C; /* set timer 4 to go HIGH then */
TFLG1 = 0x30; /* clear clocks on timers 3, 4 */
while ((TFLG1 & 0x20)==0){ i=i;} /* and wait until timers 3 fires */
TFLG1 = 0x30; /* clear clocks on timers 3, 4 */
TOC3 = counter + 4000; /* set timer 3 to clock at +2ms */
TCTL1 = (TCTL1 & 0xCF) | 0x20; /* set timer 3 to go LOW then */
TOC4 = counter + 14000; /* set timer 4 to clock at +7ms */
TFLG1 = 0x30; /* clear clocks on timers 3, 4 */
while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */
adc_read(60,1); /* read the left TILT meter side */
adc_read(61,1); /* read the right TILT meter side */
TFLG1 = 0x30; /* clear clocks on timers 3, 4 */
TOC3 = counter + 24000; /* set timer 3 to clock at +12ms */
TCTL1 = (TCTL1 & 0xCF) | 0x30; /* set timer 3 to go HIGH then */
TOC4 = counter + 24000; /* set timer 4 to clock in +12ms */
TCTL1 = (TCTL1 & 0xF3) | 0x08; /* set timer 4 to go LOW then */
while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */
TFLG1 = 0x30; /* clear clocks on timers 3, 4 */
TOC4 = counter + 44000; /* set timer 4 to clock in +22ms */
TCTL1 = (TCTL1 & 0xF3) | 0x0C; /* set timer 4 to go HIGH then */
while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */
}
/******** ********* ********* ********* ********* ********* ********* *********/
ECE 3567 Microcontrollers
Embedded C Programming – Texas Instruments
/******** TI Code for MPS430 Power Management Module ********/
// pmm.c - Driver for the pmm Module.
//********************************************************
//! addtogroup pmm_api pmm
//********************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PMM_FRAM__
#include "pmm.h"
#include <assert.h>
void PMM_enableSVSH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = PMMPW_H;
HWREG8(PMM_BASE + OFS_PMMCTL0_L) |= SVSHE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_unlockLPM5 (void)
{
//Direct register access to avoid compiler warning - #10420-D
//For FRAM devices, at start up, the GPO power-on default
//high-impedance mode needs to be disabled to activate previously
//configured port settings. This can be done by clearing the LOCKLPM5
//bit in PM5CTL0 register
PM5CTL0 &= ~LOCKLPM5;
}
End of Lecture #1

More Related Content

PDF
Consider the following interrupting system. The active-edge inputs o.pdf
DOCX
Introduction to embedded c
PPTX
Embedded programming Embedded programming (1).pptx
PPT
Introductiojwjwwkwkwjejjejsjsjsjsjsjsjn.ppt
PPT
Module-3 embedded system firmware code.ppt
PPT
Module-3 Embedded syatem firmware design.ppt
PPT
Embedded firmware
Β 
PPT
BWU_BTE_21_030_OE_EE702A.ppthhgggggggggg
Consider the following interrupting system. The active-edge inputs o.pdf
Introduction to embedded c
Embedded programming Embedded programming (1).pptx
Introductiojwjwwkwkwjejjejsjsjsjsjsjsjn.ppt
Module-3 embedded system firmware code.ppt
Module-3 Embedded syatem firmware design.ppt
Embedded firmware
Β 
BWU_BTE_21_030_OE_EE702A.ppthhgggggggggg

Similar to ECE-3567-Lecture-1-Spring-2025 for beginner (20)

PPTX
Embedded Programming..pnsnsjsejejwwjjwptx
PPTX
Ppt on embedded system
PPT
Embedded _c_
PPTX
lecture03_EmbeddedSoftware for Beginners
PPTX
Embedded c c++ programming fundamentals master
PDF
Basics of Embedded System
PDF
C Programming For Embedded Systems
PDF
Embedded_C-explanation of pointers C.pdf
PDF
Chapter three embedded system corse ppt AASTU.pdf
PPTX
ESD unit 1.pptx
PPTX
Introduction to Embedded Systems
PDF
es1-150721100817-lva1-app6891.pdf
PPT
Embedded systems
PDF
embeddedsystems-100429081552-phpapp01.pdf
PPTX
Lecture 1 Introduction.pptx
PPTX
Embedded C.pptx
PDF
Module4.pdf ,...................................
PPTX
M.Tech Internet of Things Embeed Systems
PPTX
Embedded systems
PDF
Programming Embedded Systems With C And Gnu Development Tools 2nd Edition 2nd...
Embedded Programming..pnsnsjsejejwwjjwptx
Ppt on embedded system
Embedded _c_
lecture03_EmbeddedSoftware for Beginners
Embedded c c++ programming fundamentals master
Basics of Embedded System
C Programming For Embedded Systems
Embedded_C-explanation of pointers C.pdf
Chapter three embedded system corse ppt AASTU.pdf
ESD unit 1.pptx
Introduction to Embedded Systems
es1-150721100817-lva1-app6891.pdf
Embedded systems
embeddedsystems-100429081552-phpapp01.pdf
Lecture 1 Introduction.pptx
Embedded C.pptx
Module4.pdf ,...................................
M.Tech Internet of Things Embeed Systems
Embedded systems
Programming Embedded Systems With C And Gnu Development Tools 2nd Edition 2nd...
Ad

More from MahmoudElsamanty (6)

PPTX
Lecture 04 Programming C for Beginners 001
PPTX
Lecture 03 Programming C for Beginners 001
PPTX
Lecture 02 Programming C for Beginners 001
PPTX
Lecture 01 Programming C for Beginners 001
PPTX
ECE-3567-Lecture-2-Spring-2025 for beginners
PPTX
C Programming course for beginners and intermideate
Lecture 04 Programming C for Beginners 001
Lecture 03 Programming C for Beginners 001
Lecture 02 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
ECE-3567-Lecture-2-Spring-2025 for beginners
C Programming course for beginners and intermideate
Ad

Recently uploaded (20)

PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
E -tech empowerment technologies PowerPoint
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
Internet___Basics___Styled_ presentation
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
DOCX
Unit-3 cyber security network security of internet system
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
Β 
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Introuction about WHO-FIC in ICD-10.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
E -tech empowerment technologies PowerPoint
The Internet -By the Numbers, Sri Lanka Edition
Β 
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
522797556-Unit-2-Temperature-measurement-1-1.pptx
WebRTC in SignalWire - troubleshooting media negotiation
Job_Card_System_Styled_lorem_ipsum_.pptx
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Tenda Login Guide: Access Your Router in 5 Easy Steps
SAP Ariba Sourcing PPT for learning material
Paper PDF World Game (s) Great Redesign.pdf
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
Internet___Basics___Styled_ presentation
An introduction to the IFRS (ISSB) Stndards.pdf
Unit-3 cyber security network security of internet system
Power Point - Lesson 3_2.pptx grad school presentation
Β 
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
Introduction about ICD -10 and ICD11 on 5.8.25.pptx

ECE-3567-Lecture-1-Spring-2025 for beginner

  • 1. LECTURE 1 ECE 3567 Microcontroller Laboratory Spring 2025 Dr. Gregg J Chapman
  • 7. ECE 3567 Microcontroller Lab What to expect: β€’ There is one video before each lab on the website under The Laboratories β€’ Available no later than midnight on the Sunday before the lab. β€’ Watch the video first β€’ Take the quiz β€’ This can be done BEFORE or AFTER the lab, up until MIDNIGHT on the Friday following the lab. β€’ This semester, the checkpoints will be awarded by the Lab Monitors β€’ BEFORE you leave the laboratory, SIGN the checkpoint sheet. β€’ The Commented CODE must be uploaded to Carmen prior to MIDNIGHT on the Friday following the lab. Spring 2025
  • 8. ECE 3567 Microcontroller Lab Programs (Code) β€’ Submitted electronically Please use PDF format. β€’ Must Contain: 1. A COMPLETED Standard File Header for each file submitted. 2. All code for the lab. 3. A comment on each line of code (unless it doesn’t make sense) 4. Additional comments before each function, describing what it does. β€’ Since this replaces a lab report, it must completely define the program to the extent that the lab could be duplicated from the information included in the submission.
  • 16. Embedded System MICROCONTROLLER (MCU) Field Programmable Gate Array (FPGA) MEMORY Inputs (Sensors) Outputs β€’ Actuators β€’ Displays β€’ Feedback
  • 17. ECE 3567 Microcontrollers Embedded Hardware Microprocessor (ΞΌP) Micro-Controller (MCU)
  • 18. Is there Value in Learning Embedded C Programming ? ?
  • 19. Embedded Programming Languages Embedded Development Talk March, 2022
  • 20. Embedded Programming Languages Survey Results from IEEE Spectrum July 2020
  • 22. Embedded Programming Languages β€œPython, C, and C++ are clear choices” Embedded Development Talk March, 2022 β€’ C β€’ C++ β€’ Java β€’ Python β€’ Rust β€’ Assembly Language β€’ Generative AI β€’ Others: ADA, Lua, B#, Verilog
  • 23. Embedded Program Language C Programming C is among the best programming languages for embedded systems. It is one of the oldest and most widely used embedded programming languages, which was developed in the early 1970s. C is a compiled language that helps to create programs for low-level microcontroller applications such as those found in automotive applications and home appliances. C language is the industry standard for a wide variety of applications, with estimates suggesting that up to 80% of embedded systems leverage the language. C is favored for its efficiency and widespread use in the sector. The downside of this embedded systems programming language is that its developers must be knowledgeable and be able to utilize complex coding techniques.
  • 24. Embedded Program Languages C++ C++ Another popular embedded programming language is C++. This language for embedded systems offers many advantages to coders, due to their efficiency and standard library. C+ + is especially effective as it can streamline the coding process by providing useful libraries that make writing code faster and simpler. However, one major disadvantage of this embedded programming language is that it is not easy to learn due to its complexity. β€’ Reduces development time β€’ Common β€’ Superset of Embedded C
  • 25. Embedded Program Languages Java Java Java is a programming language that is efficient and versatile, it has been very popular in internet-based applications. And for embedded systems, it does a great job with devices that rely on the Android operating system. IT IS TOO SLOW FOR MANY APPLICATIONS. The main benefit of this embedded programming language is its portability (really?). Additionally, due to their reliable nature, such programs are extremely reliable and enable greater control when interacting with low-level hardware. This makes a great difference with software (firmware vs software). β€’ GUI Development
  • 26. Embedded Program Languages Assembly Assembly Assembly is a well-known language for embedded systems. The great benefit of this language is that it is capable of interacting easily with hardware systems. The downside of this language is its complexity and difficulty to maintain in the long term. Nowadays, assembly embedded language is not used a lot, we recommend using it only if you want an absolute control of the system, or in the scenario where you want to build your own OS (Operative System). β€’ Minimal code size β€’ Speed β€’ Low Level Programming Capability
  • 28. Embedded Program Languages Rust Rust Because of its great efficiency, numerous safety features, typestate programming approach, and zero-cost abstractions, Rust is a suitable language for embedded systems programming. Rust supports managing memory both dynamically and statically using a variety of techniques. Small microcontrollers to huge, complex systems may all be programmed using the Rust programming language. Rust has a sizable community that supports it as an embedded systems programming language. β€’ Memory security β€’ Low Level Programming Capability
  • 30. Embedded C Programming – C / Embedded C / ASM C Programming Language β€’ Structure oriented β€’ Platform specific (processor) β€’ Compiler used to generate machine code β€’ Assumes FAST processor β€’ Generalized applications β€’ Requires an OS interface Assembly Language β€’ Fastest Speed β€’ Smallest Code Size β€’ Too difficult for large scale projects Embedded C Programming β€’ VERY different coding style β€’ Subset of C β€’ Can be faster and more efficient than β€œC” β€’ Hardware oriented β€’ Cross-compiler used to generate ASM, HEX, and Machine Code β€’ Microcontroller specific β€’ Smaller code size β€’ Speed limited by MCU β€’ Can be used to interface environment through sensors and actuators β€’ Lower cost than computer β€’ Lower power than computer β€’ More reliable that OS based systems β€’ Can provide better security
  • 31. Embedded C Programming - Distinctives β€’ Embedded C is a SUBSET of the C Programming Language. β€’ Like assembly language, it is written to operate directly on HARDWARE. β€’ ALL features unique to C++ are nearly useless at the embedded level. β€’ High level software engineers NEARLY ALWAYS look down their nose at the embedded coding style. They consider it β€œsophomoric”, because it does not take advantage of many aspects of high-level languages. Please understand that adopting other coding styles and methods leads to sacrifices in execution speed, code size, and ease of understanding. Code optimization is often critical in embedded systems. Advice: Keep an open mind. Intellectual smugness is seen as ignorance in the electronics community and, unfortunately, is all too common.
  • 32. Embedded C Programming - Distinctives β€’ Almost all embedded code is contained in HEADER files, both from the manufacturer and the person writing the code. β€’ Embedded code is MICROCONTROLLER SPECIFIC, and only portable to another application of the same MCU with the same interfaces. β€’ Almost ALL embedded code contains re-used header files from the IC manufacturer, written for the same MCU. Max Headroom
  • 33. Embedded C Programming - Distinctives β€’ Trying to write embedded code without using the manufacturer’s header files is PURE INSANITY. Bela Lugosi
  • 34. Embedded C Programming – Cross Compiler Inputs: .c, .h Executable: .hex, .bin Debugging, .lst is an ASM file Assembly: .asm, .a Object files: .o, .obj Pre-processor output files: .i Source files: .s (MCU specific)
  • 36. Integrated Development Environment (IDE) β€’ An IDE includes: β€’ Top Level Project Manager β€’ Source Code Editor β€’ Support for a specific Program Language β€’ Compiler β€’ Assembler β€’ Linker (Build Integration) β€’ Debugger
  • 37. Integrated Development Environment (IDE) β€’ POPULAR IDEs β€’ Visual Studio (Microsoft) (Adaptable. Almost universal) β€’ Code Composer Studio (TI) β€’ MPLAB (ST Microelectronics) β€’ Arduino β€’ Red Hat (Linux) β€’ Eclipse
  • 38. Pros: β€’ Off Site backup β€’ Industry Standard for Code Sharing β€’ Well Supported Cons: β€’ Hopelessly Complex β€’ Long Learning Curve β€’ May not be Secure Version Management GITHub
  • 39. Do you need an Operating System? β€’ Almost ALL embedded applications have a single task. β€’ You can use a REAL TIME Operating System for a Single Task (RTOS). You must use a full OS for multi-tasking. β€’ The additional complexity and scheduling of events in an RTOS creates MANY resource constraints. AN OS in general will reduce reliability. β€’ A Real Time OS is only worth the overhead for VERY complex single tasks and a highly interactive Graphical User Interfaces. β€’ In my opinion, the RTOS environment is RARELY worth the trouble and additional resources. β€’ HOWEVER, an RTOS can significantly cut development time., especially for GUIs.
  • 40. Marketable Skills β€’ Languages - Embedded C, Python β€’ MCU Communications - I2C, SPI β€’ MCU Peripherals – GPIO, Timers, ADC, DAC β€’ Ability to Read a Schematic β€’ Familiarity with Hardware Test Equipment β€’ Familiarity with RISC Instruction Set and ARM Microcontrollers β€’ Interrupt Driven Design β€’ Real Time Operating Systems β€’ Linux OS Experience β€’ Ability to work within a Version Control Environment β€’ Debugging Skills β€’ GUI Development (Java) β€’ Internet of Things (IoT)
  • 41. Embedded Programming Language Trends 1.The rise of AI Developed Systems 2.Open-Source Code 3.Security will be king 4.More modern languages (C++, Rust) 5.Simulation-first Development 6.DevOps (IT involved) and Observability 7.Edge (of network) AI β€œ7 Embedded Software Trends to Watch in 2025” – DesignNews, December 17th , 2024
  • 42. ECE 3567 Microcontrollers TI LaunchPad (MSP430FR6989)
  • 43. fcutoff = 6 Hz A5 input on ADC12 RC charging circuit P2.1 RC PWM output ADC – A5 ECE 3567 Microcontrollers Custom Designed BoosterPack RGB PWMs to LED Heating Circuit
  • 44. The MSP430FR6989 Microcontroller Architecture Timers: TA0 – ISR, Command, USCI_A0 TA1 – ADC12, USCI_A1 TB0 – PWMs
  • 45. Code Composer Studio (TI) Our Development Platform
  • 49. ECE 3567 Microcontrollers Embedded C Programming – Documentation 1 – Create a documentation standard 2 – Use a consistent coding style 3 – Use a documentation template 4 – Use a file header 5 – Comment before coding 6 – Document as you go not afterwards 7 – Update comments when making coding changes 8 – Consistent use of commenting brackets and location 9 – Write non-obvious comments – Explain the why, NOT the how 10 – Provide example uses to increase clarity
  • 50. ECE 3567 Microcontrollers Embedded C Programming – File headers (.c)
  • 51. ECE 3567 Microcontrollers Embedded C Programming – Comments
  • 53. ECE 3567 Microcontrollers Embedded C Programming – Compiler Directives β€’ #define – Declares a constant and may or may not give it a value. Can also be used to label a macro. β€’ #include – A compiler directive that adds the contents of an external file to the current file definition. #include β€œstdio.h” // has to be between quotes or carrots <> #include β€œ3567.h” β€’ #pragma – Tells the compiler to include something once if it is included in multiple files. β€’ #ifdef – Conditional compilation based on a definition #endif #define __MSP430FR6989 #ifdef __MSP430FR6989__ #include <msp430fr6989.h> #else #include <msp430.h> #endif // __MSP430FR6989__ #define RED 0x11 Usage is reserved
  • 54. #typedef typedef signed char int8_t; typedef unsigned char uint8_t; typedef int int16_t; typedef unsigned int uint16_t; typedef long int32_t; typedef unsigned long uint32_t; typedef long int64_t; typedef unsigned long uint64_t; #typedef – Defines an alias name or a new type The typedefs for abbreviated variable types are defined in stdint.h const uint16_t BaseAddress; // Base Address of EUSCI_A port const uint8_t TxPort;// GPIO Port settings for TX pin
  • 55. ECE 3567 Microcontrollers Embedded C Programming – TI header files (.h) #include "inc/hw_memmap.h" #include "adc12_b.h" #include "aes256.h" #include "comp_e.h" #include "crc.h" #include "crc32.h" #include "cs.h" #include "dma.h" #include "esi.h" #include "eusci_a_spi.h" #include "eusci_a_uart.h" #include "eusci_b_i2c.h" #include "eusci_b_spi.h" #include "framctl.h" #include "gpio.h" #include "lcd_c.h" #include "mpu.h" #include "mpy32.h" #include "pmm.h" #include "ram.h" #include "ref_a.h" #include "rtc_b.h" #include "rtc_c.h" #include "sfr.h" #include "sysctl.h" #include "timer_a.h" #include "timer_b.h" #include "tlv.h" #include "wdt_a.h" extern void ADC12_B_setAdcPowerMode(uint16_t baseAddress, uint8_t powerMode); #define ADC12_B_START_AT_ADC12MEM0 (ADC12CSTARTADD_0) #define ADC12_B_START_AT_ADC12MEM1 (ADC12CSTARTADD_1) #define ADC12_B_START_AT_ADC12MEM2 (ADC12CSTARTADD_2) #define ADC12_B_START_AT_ADC12MEM3 (ADC12CSTARTADD_3) #define ADC12_B_START_AT_ADC12MEM4 (ADC12CSTARTADD_4) #define ADC12_B_START_AT_ADC12MEM5 (ADC12CSTARTADD_5) #define ADC12_B_START_AT_ADC12MEM6 (ADC12CSTARTADD_6) #define ADC12_B_START_AT_ADC12MEM7 (ADC12CSTARTADD_7) #define ADC12_B_START_AT_ADC12MEM8 (ADC12CSTARTADD_8) #define ADC12_B_START_AT_ADC12MEM9 (ADC12CSTARTADD_9) #define ADC12_B_START_AT_ADC12MEM10 (ADC12CSTARTADD_10) #define ADC12_B_START_AT_ADC12MEM11 (ADC12CSTARTADD_11) #define ADC12_B_START_AT_ADC12MEM12 (ADC12CSTARTADD_12) #define ADC12_B_START_AT_ADC12MEM13 (ADC12CSTARTADD_13) #define ADC12_B_START_AT_ADC12MEM14 (ADC12CSTARTADD_14) #define ADC12_B_START_AT_ADC12MEM15 (ADC12CSTARTADD_15) #define ADC12_B_START_AT_ADC12MEM16 (ADC12CSTARTADD_16) typedef struct ADC12_B_initParam { //! Is the signal that will trigger a sample-and-hold for an input signal //! to be converted. uint16_t sampleHoldSignalSourceSelect; //! Selects the clock that will be used by the ADC12B core, and the uint8_t clockSourceSelect; //! Selects the amount that the clock will be divided. uint16_t clockSourceDivider; //! Selects the amount that the clock will be predivided. uint16_t clockSourcePredivider; //! Selects what internal channel to map for ADC input channels uint16_t internalChannelMap; } ADC12_B_initParam; Compiler Directives TI β€œmacro” functions or prototypes Structures
  • 56. ECE 3567 Microcontrollers Embedded C Programming – Custom Header files (.h)
  • 58. ECE 3567 Microcontrollers Embedded C Programming – MicroChip (PICC) /******************** Microchip Inc. PICC Process Code **************************/ #include <pic.h> #define XTAL_FREQ 4MHZ #include "delay.h" #include "delay.c" #define TIMEOUT 8 //-- Minutes to timeout #define MAXTIME (TIMEOUT * 60 * 1000000)/256 //-- us divided by 256 #define SECOND (1000000/256) //-- counts per second #define OFF 1 //-- OFF State of output #define ON 0 //-- ON State of output #define TIMEOUT_ON 1 //-- ON State for Timeout LED #define TIMEOUT_OFF 0 //-- OFF State for Timeout LED #define TRUE 1 #define FALSE 0 #define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit)) static bit DEAD @ BITNUM(GPIO, 0); //- Dangerously LOW static bit EMPTY @ BITNUM(GPIO, 1); //- Lower Limit static bit FULL @ BITNUM(GPIO, 2); //- Upper Limit static bit OUTPUT @ BITNUM(GPIO, 4); //- Output Control Pin static bit TIMEOUTPIN @ BITNUM(GPIO, 5); //- Timeout Indicator. unsigned long Counter; bit CountEnabled; bit Filling; bit TMRHIGH; //*************************************************************** //main //*************************************************************** void main (void) { char HourNotUp=0,Minute,Second; OPTION=0xD8; //- 11011000 Set up the option Register GPIO=0xFF; //-- All Outputs HIGH TIMEOUTPIN=TIMEOUT_OFF; //-- No Timeout yet so turn LED OFF OUTPUT=OFF; //-- Don't Fill so Output is OFF TRIS=0x0F; //-- Set Up 0 to 3 as input rest as output CountEnabled=0; Counter=0; Filling=0; TMRHIGH=0; while(1) {
  • 59. ECE 3567 Microcontrollers Embedded C Programming – Motorola /******** ********* ********* ********* ********* ********* ********* *********/ void Tilt_ctl(void) { int i; unsigned int counter; TMSK1 &= 0xCF; /* disable timer 3, 4 interrupt */ counter = TCNT; /* get the current counter value */ TOC3 = counter + 2000; /* set timer 3 to clock at +1ms */ TCTL1 = (TCTL1 & 0xCF) | 0x30; /* set timer 3 to go HIGH then */ TOC4 = counter + 2000; /* set timer 4 to clock at +1ms */ TCTL1 = (TCTL1 & 0xF3) | 0x0C; /* set timer 4 to go HIGH then */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ while ((TFLG1 & 0x20)==0){ i=i;} /* and wait until timers 3 fires */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ TOC3 = counter + 4000; /* set timer 3 to clock at +2ms */ TCTL1 = (TCTL1 & 0xCF) | 0x20; /* set timer 3 to go LOW then */ TOC4 = counter + 14000; /* set timer 4 to clock at +7ms */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */ adc_read(60,1); /* read the left TILT meter side */ adc_read(61,1); /* read the right TILT meter side */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ TOC3 = counter + 24000; /* set timer 3 to clock at +12ms */ TCTL1 = (TCTL1 & 0xCF) | 0x30; /* set timer 3 to go HIGH then */ TOC4 = counter + 24000; /* set timer 4 to clock in +12ms */ TCTL1 = (TCTL1 & 0xF3) | 0x08; /* set timer 4 to go LOW then */ while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ TOC4 = counter + 44000; /* set timer 4 to clock in +22ms */ TCTL1 = (TCTL1 & 0xF3) | 0x0C; /* set timer 4 to go HIGH then */ while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */ } /******** ********* ********* ********* ********* ********* ********* *********/
  • 60. ECE 3567 Microcontrollers Embedded C Programming – Texas Instruments /******** TI Code for MPS430 Power Management Module ********/ // pmm.c - Driver for the pmm Module. //******************************************************** //! addtogroup pmm_api pmm //******************************************************** #include "inc/hw_memmap.h" #ifdef __MSP430_HAS_PMM_FRAM__ #include "pmm.h" #include <assert.h> void PMM_enableSVSH (void) { HWREG8(PMM_BASE + OFS_PMMCTL0_H) = PMMPW_H; HWREG8(PMM_BASE + OFS_PMMCTL0_L) |= SVSHE; HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00; } void PMM_unlockLPM5 (void) { //Direct register access to avoid compiler warning - #10420-D //For FRAM devices, at start up, the GPO power-on default //high-impedance mode needs to be disabled to activate previously //configured port settings. This can be done by clearing the LOCKLPM5 //bit in PM5CTL0 register PM5CTL0 &= ~LOCKLPM5; }