Microprocessors and Microcontrollers-2
Microprocessors and Microcontrollers-2
Microcontrollers
VNIT Nagpur
Pin configuration
Pin configuration
Vcc: +5 V power for internal operation
Minimum:
Maximum:
8086 operates as a
8086 operates with one or
standalone processor without
more external coprocessors
any external coprocessors or
or support chips
support chips
Pin configuration
HOLD input, HLDA output :
HOLD:
● Demultiplexed by external
latches and ALE signal.
● Three latch ICs (Intel
8282/8283), two for a 16-bit
address and three for full
20-bit address.
● 8286 contains eight
receivers, and eight drivers.
Two 8286s are required to
service 16 data lines
Write cycle example
8086 Architecture
Register organization of 8086
Non-Overlapping and Overlapping segments
In the Overlapped
Area Locations,
Physical Address
CS1 + IP1
CS2 + IP2
https://ggnindia.dronacharya.info/Downloads/Sub-info/RelatedBoo
k/5thSem/MICROPROCESSOR-AND-INTERFACING-TEXT-BOO
K-2.pdf
Programming
File extension
When you assemble a program in EMU8086, it creates the following files:
.BIN (Binary file) Contains the raw machine code (executable instructions).
.SYMBOL (Symbol file) Stores labels, variables, and their memory addresses.
Memory Notation
Memory addresses represented in segment:offset notation, where:
MOV SS, AX ; Set stack segment ; Pop elements back in reverse order
Reverse order of and store them in the same location
MOV SP, 0FFFH ; Stack pointer (top of stack)
an array in-place POP AX
MOV SI, OFFSET ARRAY ; address of ARRAY
using stack! MOV [SI], AL
[1,2,3] POP AX
; Push array elements onto stack
MOV [SI+1], AL
MOV AL, [SI]
POP AX
PUSH AX
MOV [SI+2], AL
MOV AL, [SI+1]
PUSH AX
PUSH AX
Program 5 (compact way?) MOV SI, OFFSET ARRAY ; Load address of ARRAY
Reverse order of
; Push all elements onto stack
an array in-place
PUSH WORD PTR [SI]
using stack!
PUSH BYTE PTR [SI+2]
[1,2,3]
; Pop back in reverse order
#define KEY_PIN P1_0 // Define the pin for the key (P1.0)
Switch! #define LED_PIN P1_1 // Define the pin for the LED (P1.1)
void main() {
while (1) {
} else {
}
Seven Segment Display
Seven Segment Display
#include <reg51.h> void delay(unsigned int time) void main() {
Seven // Define codes for digits 0-9
{
unsigned char i;
#include <reg51.h>
sbit R0=P1^0;
sbit R1=P1^1;
sbit R2=P1^2;
sbit R3=P1^3;
sbit C0=P1^4;
sbit C1=P1^5;
sbit C2=P1^6;
sbit rs=P3^4;
sbit rw=P3^5;
sbit e= P3^6;
void delay();
void cmd(unsigned int);
void dat(unsigned char);
Interfacing LCD
Sample 16x2 LCD
Interfacing 2x16 LCD
Pinout
1. Ground 9. Data bit 2 (DB2)
2. VCC (Normally 5V) 10. Data bit 3 (DB3)
3. Contrast adjust input (Voltage between VCC and GND) 11. Data bit 4 (DB4)
4. Register select (For a command RS = 0. For data RS = 12. Data bit 5 (DB5)
1)
5. Read/Write 13. Data bit 6 (DB6)
(To write to the display = R/W = 0. To read = R/W = 1)
6. Enable 14. Data bit 7 (DB7)
7. Data bit 0 (DB0) 15. Backlight +
8. Data bit 1 (DB1) 16. Backlight -
Get-Set-Go with an LCD
Initialize LCD, RS = 0
1. Set data lines to: 00111000
"Function set" to 8 wire mode, 2 lines and 5x8 dots.
2. Set enable high, Wait 1uS, Set enable low, Wait until the screen is not busy
3. Set data lines to: 00000110
"Set entry mode" automatic shift of cursor after character
4. Set enable high , Wait 1uS, Set enable low, Wait until the screen is not busy
5. Set data lines to: 00001100
"Display on/off" command. Display on
6. Set enable high, Wait 1uS, Set enable low
Send Data, RS = 1
1. Set R/S = 1
2. Set data lines to 01001000
ASCII code for "H"
3. Set enable high, Wait 1uS,Set enable low
4. Set data lines to 01001001
ASCII code for "I"
5. Set enable high, Wait 1uS, Set enable low
Demo
Timers in 8051
Machine Cycle: time to execute instruction
• 6 States: S1, S2, S3, S4, S5, S6
• Each state → 2 clock cycles: phase 1 (P1) and phase 2 (P2).
• Phase 1: Arithmetic and logical operations
• Phase 2: Internal data transfers
• 1 Machine Cycle = 12 Clock cycles
Timer Registers in 8051
Highlights
• Use of timer:
• create time delay,
• counter to count the external events happening outside
• Difference between counter and timer is source of clock pulse
• Register overflow from FFFF h to 0000 h, it sets TF flag (interrupt)
Clock source for timer
Pin-out
Two 16-bit timers: T0 and T1
Timer Mode Control
TCON
Count for specific delay
1. Calculate time period of timer clock pulse.
2. Calculate number of timer clock pulses N, required to generate desired
time delay by dividing desired time delay
by period of timer clock,
3. Count = FFFFH – N (Hex) +1, and
4. Let us say, Count = n1n2n3n4, Load TH and TL as TH = n1n2 and TL =
n3n4
Activity
Find the count to be loaded into timer registers to generate a time
delay of 500 µs and also write a program for the same using Timer 0
Mode 1. Assume crystal frequency is 12 MHz.
1 KHz Square Wave: Example: Mode 1
void main() {
TMOD = 0x10; // Configure Timer 1 in Mode 1 (16-bit timer mode)
while (1) {
TL1 = 0x0C; // Load TL1 with 0x0C (low byte of timer value)
TH1 = 0xFE; // Load TH1 with 0xFE (high byte of timer value)
TR1 = 1; // Start Timer 1
void main() {
TMOD = 0x02; // Configure Timer 0 in Mode 2 (8-bit auto-reload mode)
TH0 = 0x00; // Load TH0
while (1) {
if (TF0) { // Check if Timer 0 overflow flag is set
TF0 = 0; // Clear Timer 0 overflow flag
square_wave = ~square_wave; // Toggle P0.0 to generate square wave
}
}
}
Counters!
#include <reg51.h>
void main() {
TMOD = 0x05; // Configure Timer 0 in Mode 2 (8-bit auto-reload mode)
TR0 = 1; // Start Timer 0
}
ADC/DAC
DAC
DAC
A DAC takes an n-bit binary input and converts it into an equivalent analog voltage or current
using a reference voltage (Vref).
● Analog Output:
Vout = 5 × 160 / 256 = 3.125V
Example of Successive Approximation
For Vin = 3.5V the final digital output is 011 (3 in decimal).
https://www.ti.com/lit/ds/symlink/dac0808.pdf
#include <reg51.h>
void delay() {
int i;
for (i = 0; i < 10000; i++); // Small delay
}
void main() {
unsigned char value = 0; // Start with 0
while (1) {
P0 = value; // Send data to DAC0808
value++; // Increment value (sawtooth wave)
delay(); // Small delay for waveform visibility
}
}
#include<reg51.h>
void main(){
int sin_value[12] = {128,192,238,255,238,192,128,64,17,0,17,64};
int i;
while(1){
for(i = 0; i<12; i++){
DAC = sin_value[i];
}
}
}
ADC
ADC
Start Conversion
ADC ● Apply Analog Input at Vin+, keeping Vin- at GND.
2. Conversion Process
● RD = 0 (Low pulse for at least 100 ns) → Reads 8-bit digital value from D0-D7.
● RD = 1 (Returns to high).
• transmits 10 bits through TXD pin and receives through RXD pin
START bit (always 0) -> 8 data bits (LSB first) -> STOP bit (always 1)
F Osci × 2SMOD
BR = _____________________________
12 × 32 × (256 – TH1)
F Osci × 2SMOD
TH1 = 256 - _______________________
12 × 32 × BR
For example, with 11.0592 MHz:
to
slave address
1010000 (A0H)
SDA and SCL
S1CON
S1STA
SI = 1 indicates that any one of 25 possible states is
entered.
Status code in S1STA
Sample Code for Master Transmit