Micro Paper 1
Micro Paper 1
a) Draw and explain interfacing of external 16 KB RAM with the 8051 microcontroller.
Answer:
For interfacing external RAM, address lines from the 8051 are divided as follows:
The lower byte of the address (A0–A7) is multiplexed with data on Port
0.
The higher byte of the address (A8–A15) is sent through Port 2.
A latch (like 74LS373) is used to de-multiplex the lower address/data lines. The ALE signal is
used to enable the latch. CS (Chip Select) and RD/WR signals are used to enable the RAM for
read/write operations.
(A diagram would show the connection of Port 0 to RAM via the latch, Port 2 directly to the
address lines of RAM, and control lines connected appropriately.)
1. General Purpose Registers: The lower 128 bytes (00H–7FH) are for
general-purpose registers, working registers, and bit-addressable
memory.
2. Register Banks: 4 banks (Bank 0–Bank 3), each containing 8 registers
(R0–R7).
3. Bit-Addressable Memory: 16 bytes (20H–2FH) are bit-addressable.
4. Stack Area: The stack starts at 08H by default and grows upward.
b) Write an 8051 C program to generate a square wave with 2500 Hz frequency on pin 2.7.
Answer:
#include <reg51.h>
void delay() {
// Assuming a 12 MHz crystal, the delay function generates ~200
microseconds
unsigned int i;
for (i = 0; i < 200; i++);
}
void main() {
while (1) {
P2 ^= 0x80; // Toggle pin 2.7
delay(); // Delay for half-period
}
}
#include <reg51.h>
sbit RS = P2^0;
sbit EN = P2^1;
#define LCD P1
void delay() {
int i;
for (i = 0; i < 30000; i++);
}
void lcd_init() {
lcd_cmd(0x38); // 2 lines, 5x7 matrix
lcd_cmd(0x0C); // Display ON, Cursor OFF
lcd_cmd(0x01); // Clear display
}
void main() {
lcd_init();
lcd_cmd(0x80); // Move cursor to first line
lcd_data('E');
lcd_data('L');
lcd_data('E');
lcd_data('C');
lcd_data('T');
lcd_data('R');
lcd_data('O');
lcd_data('N');
lcd_data('I');
lcd_data('C');
lcd_data('S');
while (1);
}
d) Interrupts in 8051:
The 8051 has four 8-bit I/O ports (P0, P1, P2, P3). Each port can
function as input or output.