Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

TUTORIAL

1
EMJ23204 - MICROCONTROLLER DESIGN
Q1 : DESCRIBE AND EXPLAIN THE 3 ELEMENT OF BASIC
MICROCONTROLLER SYSTEM

Processor - CPU
1. CPU 3. MEMORY
Handle data processing Store data
execute instruction ROM (permanent storage):
perform calculation program instruction
RAM (temporary storage):
program execution
System i/o pins
clock
PIC 2. system clock
4. i/o pins
Provide timing reference for
microcontroller operations. Allow microcontroller to
communicate with ext.
device/ other peripherals.

memory
Q2 : EXPLAIN OPERATIONAL MODES OF..
I. WATCHDOG TIMERS
II. POWER UP RESET
III. BROWN-OUT RESET
IV. LOW VOLTAGE PROGRAMMING

WatchdogTimers Power Up Reset Brown-out Reset Low Voltage Programming


Resets the Ensures the Resets the Allows programming
microcontroller microcontroller microcontroller the microcontroller at
if it stops initialises if the voltage lower voltages,
correctly during drops too low, useful for low-power
working
powered on, preventing or battery-operated
properly, setting it to a
errors due to applications.
preventing it known state. It
from getting insufficient
clearing any
power.
stuck. undefined values
and setting the
processor's
program counter
to the start address
of the program
memory.
Q3 : CONSTRUCT AND EXPLAIN THE BASIC CIRCUIT OF
A MICROCONTROLLER

Processor - CPU

System i/o pins


clock
PIC

memory
Explain the basic circuit of a microcontroller...

: To start up the microcontroller, there are 7 pins


that should be connected correctly.
1. Power supply (Vcc, Vss)
Microcontroller is powered by 5 Vdc supply.

2. Reset Pin (MCLR)


Reset pin is MCLR - Master Clear Reset.
If PIC read 0V at MCLR pin, it will reset the program, thus, the PIC will
remain reset and program will not execute.
In default connection, the MCLR pin is connected to 5V, and
microcontroller is effectively disabled from resetting.

3. System Clock (Oscillator)


There are pins named as OSC1 and OSC2.
They can be connected to the crystal oscillator from various frequency.
Pulse generated from the oscillator will some time have the noise. To
reduce the noise, two capacitors in piko farad value are needed. The value
of capacitor is depending on the speed of oscillator used.
Q4 : CONVERT THE FOLLOWING DECIMAL NUMBERS TO BINARY
METHOD 1:

I. 12 = 00001100
2 2 2 2 2 2 2 2
7 6 5 4 3 2 1 0

II. 123 = 01111011


128 64 32 16 8 4 2 1
III. 63 = 00111111
IV. 128 = 10000000 0 0 0 0 1 1 0 0

V. 1000 = 1111101000 METHOD 2: Divide the number into 2 repeatedly and take the remainders:

12/2 → 6 Remainder 0 (LSD)


6/2 → 3 Remainder 0
3/2→ 1 Remainder 1
1/2 → 0 Remainder 1
0/2 → 0 Remainder 0
0/2 → 0 Remainder 0
0/2 → 0 Remainder 0
0/2 → 0 Remainder 0(MSD)
_______________________________________
The binary number is 0000 1100
Q5 : CONVERT THE FOLLOWING BINARY NUMBERS TO DECIMAL
METHOD 1:

I. 100100 = 36
2 2 2 2 2 2 2 2
7 6 5 4 3 2 1 0

II. 1000001 = 65
128 64 32 16 8 4 2 1
III. 11101 = 29
0 0 1 0 0 1 0 0
IV. 1010 = 10
V. 100100010 = 290
METHOD 2: Multiply by bit and sum up the total:

10 0100 = (1 x25)+(0 x24)+(0 x23)+( 1 x 22)+( 0 x 21)+(0x 20 )


= 32 + 0 + 0 + 4 + 0 + 0
= 36
_______________________________________
The decimal number is 36
Q6 : CONVERT THE FOLLOWING BINARY NUMBERS TO HEXADECIMAL
METHOD 1:

I. 100100 = 24 2 4

II. 1000001 = 41
0 0 1 0 0 1 0 0
III. 11101 = 1D
IV. 1010 = 0A METHOD 2: First, divide the number into groups of four(4 bits),
then find the hexadecimal equivalent of each group:
10 0100 = 0010 0100
_______________________________________
The hexadecimal number is 24
Q7. CONVERT THE FOLLOWING VALUES NUMBERS TO SIGNED 8-BIT I.
METHOD 1:
I. -5 = 11111011
- 5
II. -34H = 11001100
III. -128V = 10000000 0 0 0 0 0 0 1 0 1

1 1 1 1 1 1 0 1 1

METHOD 2: First, write the number as a positive number, then find the complement and
add 1 to LSB bit:
0000 0101 (positive integer 5)
1111 1010 (complement 5)
1111 1011 (add 1)
_______________________________________
The signed 8-bit is 11111011
Q8: STATE THE RESULT OF EACH OF THESE OPERATIONS IN DECIMAL AND 4-BIT BINARY,
if n = 5 and m = 7
i. n + +
n=6 or 0110

ii. ~m
m=8 or 1000

iii. n & m
n&m=5 or 0101

iv. n | m
n|m=7 or 0101
Q9: EXPLAIN WHY A PULL-UP RESISTOR NEEDED WITH A SWITCH INPUT.

When the switch is open, the output voltage of the


circuit is pulled up to 5V via the resistor.
*Another way to look at it is that there is no current in the resistor, so there is no voltage
drop at the resistor, and the output voltage must be the same as the supply ( 5V ).

When the switch is closed the output is connected


directly to 0 V; the resistor prevents the supply being
shorted to ground.
Q10: WRITE A PROGRAM AND CREATE A CIRCUIT TO LIGHT 4 LED DIODES THAT
CONNECTED TO RD4, RD5, RD6 AND RD7 OF A MICROCONTROLLER PIC16F877A. CONNECT
TWO(2) PUSH BUTTONS TO RC1 AND RC2.
THE 4 LED DIODES WILL BE ON IF THE PUSH BUTTON ON RC1 IS PUSHED
AND OFF IF THE PUSH BUTTON ON RC2 IS PUSHED.
Q10: WRITE A PROGRAM AND CREATE A CIRCUIT TO LIGHT 4 LED DIODES THAT CONNECTED TO RD4, RD5,
RD6 AND RD7 OF A MICROCONTROLLER PIC16F877A. CONNECT TWO(2) PUSH BUTTONS TO RC1 AND RC2.
THE 4 LED DIODES WILL BE ON IF THE PUSH BUTTON ON RC1 IS PUSHED
AND OFF IF THE PUSH BUTTON ON RC2 IS PUSHED.
Q10: WRITE PROGRAM (CONT......)
Q10: WRITE A PROGRAM AND CREATE A CIRCUIT TO LIGHT 4 LED DIODES THAT
CONNECTED TO RD4, RD5, RD6 AND RD7 OF A MICROCONTROLLER PIC16F877A. CONNECT
TWO(2) PUSH BUTTONS TO RC1 AND RC2.
THE 4 LED DIODES WILL BE ON IF THE PUSH BUTTON ON RC1 IS PUSHED
AND OFF IF THE PUSH BUTTON ON RC2 IS PUSHED.

Reset
circuit PIC16f877a
LEDs

Pushbutton
Crystal
Oscillator
Q11: EXPLAIN WHY A BCD ENCODED DISPLAY DOES NOT NEED A CODE TABLE

A BCD encoded display


doesn't require a code table
because each decimal
digit directly corresponds
to a unique 4-bit binary
number, eliminating the
need for translation
between the PIC to 7
segment display.
Q13: DRAW A BLOCK DIAGRAM OF THE CIRCUIT WITH A KEYPAD AND 7-SEGMENT DISPLAY,
INDICATING THE MAIN COMPONENTS AND SIGNALS IN THE SYSTEM

7 segment display

Reset
circuit PIC16f877a

Crystal
Oscillator
4x4 Keypad
Q15: WRITE A PROGRAM TO COUNT UP 0 – 99 USING C LANGUAGE, AND DISPLAY ON THE 7 SEGMENT
Q15: WRITE A PROGRAM TO COUNT UP 0 – 99 USING C LANGUAGE, AND DISPLAY ON THE 7 SEGMENT
Q15: WRITE A PROGRAM TO COUNT UP 0 – 99 USING C LANGUAGE, AND DISPLAY ON THE 7 SEGMENT
Q15: WRITE A PROGRAM TO COUNT UP 0 – 99 USING C LANGUAGE, AND DISPLAY ON THE 7 SEGMENT
Q16: A PROGRAM IN C LANGUAGE IS WRITTEN BELOW TO OPERATE A MICROCONTROLLER PIC16F877A.
I. EXPLAIN PER LINE OF THE PROGRAM.
Q16: A PROGRAM IN C LANGUAGE IS WRITTEN BELOW TO OPERATE A MICROCONTROLLER PIC16F877A.
I. EXPLAIN PER LINE OF THE PROGRAM.
Q16: A PROGRAM IN C LANGUAGE IS WRITTEN BELOW TO OPERATE A MICROCONTROLLER PIC16F877A.
II. IF TWO PUSH BUTTONS AND FOUR LED DIODES ARE CONNECTED TO THE MICROCONTROLLER AS
INPUT AND OUTPUT, RESPECTIVELY. DRAW A COMPLETE CIRCUIT OF THE MICROCONTROLLER,
PUSH BUTTONS AND LED DIODES. WHAT CAN BE DONE BY THE PUSH BUTTONS AND LED
DIODES.

You might also like