0% found this document useful (0 votes)
3 views7 pages

Module 6

Uploaded by

anybodycanbe173
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Module 6

Uploaded by

anybodycanbe173
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

MCU Architecture & GPIO


Microcontroller (8051) Overview
 The 8051 is an 8-bit microcontroller used in many embedded
systems.
 It processes data 8 bits at a time, making it suitable for basic control
tasks.
 It works like a small “System on Chip” (SoC) with CPU, RAM, ROM,
I/O ports, and timers integrated on one chip.
o Note: Because everything is inside one chip, it reduces size
and cost.
 Unlike a microprocessor, the 8051 does not need external RAM or
I/O chips.
o Benefit: This makes it easier to design small, low-power
devices.

GPIO (General Purpose Input/Output)


 The 8051 has four 8-bit ports: P0, P1, P2, P3 (total 32 pins).
 Each port pin can act as input or output depending on the program.
 Port 1 (Pins 1–8)
o Only used for simple input/output tasks.
o It has no alternate or special functions.
 Port 0 (Pins 32–39)
o Works as a general I/O port.
o Also works as Address/Data bus (AD0–AD7) when using
external memory.
o This means the same pins carry both address and data
signals.
 Port 2 (Pins 21–28)
o Works as general I/O.
o Also sends high-byte address signals (A8–A15) for external
memory access.
o So, it helps the microcontroller reach higher memory
addresses.
 Port 3 (Pins 10–17)
o A multifunctional port providing serial, interrupt, and timer
functions.
o These special features make P3 very important.
o Pin Functions:
 P3.0 – RXD (Serial Receive)
 P3.1 – TXD (Serial Transmit)
 P3.2 – INT0 (External Interrupt 0)
 P3.3 – INT1 (External Interrupt 1)
 P3.4 – T0 (Timer 0 input)
 P3.5 – T1 (Timer 1 input)
 P3.6 – WR (Write signal for external memory)
 P3.7 – RD (Read signal for external memory)

ADC & DAC


 Embedded systems must convert analog signals (temperature, light,
pressure) into digital form.
 ADC (Analog to Digital Converter)
o Converts analog voltage from sensors into digital values.
o MCU can then process the digital values easily.
 DAC (Digital to Analog Converter)
o Converts MCU’s digital output into analog voltage.
o Used to control motors, speakers, LEDs, etc.

2. Timers, Counters, and Watchdog Timer (WDT)


Timers/Counters
 The 8051 has two 16-bit timers: Timer 0 and Timer 1.
 Each timer can count from 0000H to FFFFH.
 They can work as:
o Timers – count internal clock cycles (measure time).
o Counters – count external pulses (measure events).
 TMOD Register
o Controls the mode of each timer.
o Selects Timer/Counter, gate control, and mode (0,1,2,3).
 TCON Register
o Controls start/stop for timers (TR0, TR1).
o Shows overflow flags (TF0, TF1) when the timer completes
counting.

Timer Modes
 Mode 0: 13-bit timer (old and rarely used).
 Mode 1: 16-bit timer; counts full range; most used.
 Mode 2: 8-bit auto-reload; very useful for generating baud rates.
 Mode 3: Splits Timer 0 into two separate 8-bit timers.

Watchdog Timer (WDT)


 Used to reset the system if software hangs or crashes.
 It is a free-running timer that must be reset regularly by the
program.
 If the program fails to reset it, the WDT times out and resets the
MCU.
o Benefit: This prevents the system from getting stuck
permanently.

PWM (Pulse Width Modulation)


 8051 does not have a built-in PWM unit.
 But PWM can be created using timers and interrupts.
 By adjusting the ON time and OFF time of a square wave, we can
control motor speed, LED brightness, etc.

3. Memory Organization
Architecture Types
 Harvard Architecture
o Program memory (ROM) and Data memory (RAM) are
separate.
o Allows CPU to read instructions and data simultaneously.
o 8051 uses this architecture.
 Von-Neumann Architecture
o Only one memory for both instructions and data.
o Simpler but slower because CPU accesses one at a time.

8051 Memory Map


 Internal ROM
o 4 KB program memory stored inside the chip.
 Internal RAM
o 128 bytes (or 256 bytes for 8052).
o Used for variables, registers, and temporary storage.
 Register Banks (00H–1FH)
o Contains four banks of registers (R0–R7).
o Only one bank is active at a time.
 Bit-Addressable RAM (20H–2FH)
o 16 bytes where each bit has its own address.
o Makes it easy to handle flags and control bits.
 Scratchpad RAM (30H–7FH)
o General-purpose area for storing data and variables.
 SFRs (80H–FFH)
o Contains all special registers like Port registers, Timer
registers, Interrupt registers, etc.

4. Serial Communication
UART (Universal Asynchronous Receiver Transmitter)
 A built-in serial communication module in 8051.
 Uses RXD (P3.0) and TXD (P3.1) for receiving and sending data.
 Used for debugging, programming, and communicating with PCs.
 Controlled using SCON register.

I2C (Inter-Integrated Circuit)


 A two-wire communication protocol for connecting sensors.
 Designed for low-speed data transfer.
 Wires:
o SDA – Data line
o SCL – Clock line
 Key Points:
o Communication begins with a Start condition.
o Every device has a 7-bit address.
o Data is sent in 8-bit format with ACK/NACK.
o Communication ends with a Stop condition.

5. Operating System Basics & RTOS


Processes and Tasks
 Co-operating Processes
o These tasks need each other’s data to work.
o Example: One task writes sensor data; another processes it.
 Competing Processes
o These tasks do not share data but fight for CPU time or
resources.

Real-Time Systems
 Output must be correct and delivered within a deadline.
 Hard Real-Time
o Missing a deadline is dangerous.
o Example: Airbag deployment.
 Soft Real-Time
o Small delays are acceptable.
o Example: Video streaming.

Inter-Process Communication (IPC)


 Shared Memory
o Many tasks access the same data area.
o Faster but needs protection.
 Pipes
o One-way or two-way communication through a shared buffer.
 Message Queue
o FIFO system where tasks post messages for others.
 Mailbox
o Similar but usually stores one message at a time.
 Signaling
o Sends notifications without data.
 RPC (Remote Procedure Call)
o A process calls a function that runs in another process or
device.

6. Task Synchronization
Issues
 Race Condition
o Two tasks access the same data at the same time, causing
errors.
 Deadlock
o Two tasks wait forever because each needs a resource the
other holds.
 Priority Inversion
o A high-priority task waits for a low-priority task unnecessarily.

Techniques
 Spin Lock
o A process repeatedly checks a condition until the resource is
free.
 Binary Semaphore / Mutex
o Only one task can access protected data at a time.
 Counting Semaphore
o Allows a limited number of tasks to access a resource pool.

7. Choosing an RTOS
Functional Requirements
 Check if the RTOS supports the specific processor.
 Ensure the RTOS can meet real-time deadlines.
 Verify available services like IPC, timers, networking, etc.
 Check if you can remove unused components to save memory.

Non-Functional Requirements
 Cost of licensing vs development time.
 Availability of good tools and debuggers.
 Quality of customer support and documentation.

You might also like