You are on page 1of 12

Difference between a uP (Microprocessor) and a uC

(Microcontroller):

 uP is used for multitasking whereas uC is used for specific tasks


 Once formulated/configured, a uC can’t be changed whereas n no. of devices
of n capacity can be appended to a uP as per the requirement
 uP is comparatively expensive than a uC
 The uC resumes its current program once the interrupt encountered during
the course of the program is over. Till the time the interrupt continues, uC holds
the data of the program

UART: Universal Asynchronous Receiver Transmitter


Used for serial communication

The uC we used was: P89V51RD2


• P—Philips
• 9—Flash memory
8051 was the prototype of the uC. 8951 is based on 8051 architecture.
Flash is used to write and erase the program very rapidly and conveniently
• RD2—refers to enhanced features
Here it refers to 64K of flash RAM
• V—indicates low power consumption

SPI— Serial Peripheral Interface


 There are 3 timers, T0, T1 and T2
 Watchdog Timer— used in case of idle CPU
 Reset Circuitry— used to provide direct stabilized voltage to uC (it bypasses
a certain time-interval, say 10ms, till he voltage level is fluctuating)

Pin multiplexing in P89V51RD2:


• Refers to 1 pin- many functions
• In this uC, 1 pin controls 2 functions
RXD/ P3.0 10
\

TXD/ P3.1 11

INT0/ P3.2 12

INT1/ P3.3 14

T0/ P3.4 15

T1/ P3.5 16

WR/ P3.6 17

INT0 and INT1 (active-LOW) are internal or external interrupts


Timer

Clock pulses
(fixed time-interval)

Counter

Here size of the clock pulses doesn’t matter, only the no.
Of clock pulses counted matters

Register 1:
TMOD: Timer/Counter Mode Control register

Bit 7 6 5 4 3 2 1 0

Symbol T1GATE T1C/ T T1M1 T1M0 T0GATE T0C/ T T0M1 T0M0


• Every functionality has a particular register. The way we feed the register,
tells the uC to work in a specific way.
1 function might require 2 or 3 registers.

• Bit (1) – Nibble (4) – Byte (8) – Word – Double Word

• Hexadecimal No. System:


 We’ll use this no. system
 Symbol: OX
 Number following OX is read as hexadecimal
 E.g. OX00 denotes 8 zeros (each zero is for 1 nibble)
 E.g. OX10 denotes 4 zeros
 OX0F = 15
This is the way a binary value is passed to a register/port

• 1 register – 2 functions (Timer+ Counter)


 T1 and T0 are 2 timers
 We observe that when we remove T1 and T0, the upper and the lower nibble
are same
Bit and their functions:
 GATE —when other devices are used, then this bit is activated
 C/T — C is active-HIGH
T is active-LOW
 M1/M0 – provide 4 modes for timer
We’re only concerned with mode2 (10)

• uC also activates 2 registers internally


 THX and TLX
T— timer
H— high
L— low
X— don’t care
 Both the registers belong to either 0 (Timer 0) or 1 (Timer 1)
 TH and TL are both of 1 full byte-length
 Baud rate: No. of bits transmitted/received per sec
9600 is the universally accepted baud rate/ freq.
 Feed OXFD in the register to feed 9600 in it, to start it
 The freq. at which the timer (activated by the uC) will work, is decided by this
value fed
 1111 1101
F D
E.g. 7 6 5 4 3 2 1 0
0 0 0 0 0 0 1 0
is equivalent to OX02
It’s conventional to use Timer1 for serial communication
• Once the value in Timer1 is set, we leave it and modify the values in
Timer0
E.g. OX02 denotes Timer1, mode2

Register2:
TCON: Timer/ Counter Control register

Bit 7 6 5 4 3 2 1 0

Symbol TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT 0

1— Timer1
0— Timer0

• The register TR is for Timer Start


• E.g. for serial communication:
 TH1= OXFD
We’ll use this value if we want baud rate of 11.0592 MHz i.e. crystal of this rate
 9600 can also be achieved by crystals of: 18 MHz
20 MHz
40 MHz
 TL starts the actual timer
 TL1= OXFD (same value as TH1 is passed here)
OXFE
OXFF
 After this, the timer will overflow
At this time, TF1 will set (=1)
This indicates the uC that the timer is set
Then TH1 will get reloaded (8-bit auto-reload)
Thereafter TH1  TH0
This way the cycle keeps on repeating

• When external timers/ counters are used, only then IE1 and IT1 are used
(i.e. when INT0 and INT1 are activated, as in case of inter-controller
communication)
Register3:
SCON: Serial Port Control register

Bit 7 6 5 4 3 2 1 0

Symbol SM0/ FE SM1 SM2 REN TB8 RB8 TI RI

• TI and RI get SET/CLEAR according to the program when we transmit or


receive data
 When data is fully received, RI gets automatically SET
When data is fully transmitted, TI gets automatically SET
 TB8 and RB8 are used only in special conditions when we need to transmit/
receive extra bits after a byte of data
 Here 7654 is an important nibble
 SM2 is basically not used as 4 modes are achieved through SM0 and SM1 only

• To change the baud rate, change the value in TH


• Mode2 is used for variable clock speed
Thus, 7 6
0 1
• Only when REN is SET, the data is received
If REN is not set, then the uC will not receive the data even if it is coming

Bit addressable registers:


• Many registers in uC are bit-addressable
• To set the 6th bit in TCON, we write: TR1= OX1

Selection Sequence:

Timer Mode TH Variable clock speed


TMOD= OX20
SCON= OX50
TH1= OXFD
TR1= OX1

KEIL: It is the compiler that translates embedded C to machine HEX file


Flash Magic (Version: 3.42.179, Philips) is used to provide the HEX file to the
controller
Basics of steps to write the code:
#include <reg51F.h> // header file for 8051 family
#include <stdio.h>

void main()
• The uC we use works on 5V
Current and Voltage rating: Current supplied by uC is 15 mA
Output voltage= 5V

Symbol of an LED

(Starts with 3.2V, gets full glow at 5V)

• P0.0= 1; implies that Port1 is providing 5V


5V 0
uC uC

I
(Current sourcing) I
(Current sinking)

0
5V

• E.g.1
sbit LED = P1.3; //s— single
LED =0;
void main( )
{
P1.3= 0;
}

• E.g. 2
LED = 0;
delay ( );
LED = 1;

 Here delay ( ) is a function


 There are 2 ways to include a function in an embedded-C program:
1. Define and declare the function before the main( ) function
2. Declare the function before the main( ) function, call it with the main( )
function whenever required, and define it outside the main( ) function

• void delay ( );
{
For (i=0; i<100; i++);
}

• 11.0592 MHz
|
1/12 divider (inside uC)
|
= 921.6 KHz (f)
|
1/f = 108.5 us (time-period of clock pulses)

Two ways for serial communication:


1. Using printf ( )

void serial ( )
{
TMOD = OX20;
SCON = OX50;
TH = OXFD; // for 9600bps  11.0592MHz
TR1 = 1;
TI = 1; // printf turns TI  0
}
void main ( )
{
void serial ( );
printf (“SWARM”);
}

2. Till TI, it’s the same as the previous method


void main ( )
{
SBUF = “S”;
while (R1 = = 0);
RI = 1;
}

Actuator: Something that initiates


E.g. an H-bridge – it helps convert 5V to 12V (we need to use this as 5V is
insufficient to drive a uC)

12V is sufficient to drive the motor of the H-bridge


+12V

LENA LENB

(LENB)’
(LENA)’

Left motor of the H-bridge


+12V

RENA RENB

(RENB)’
(RENA)’

Right motor of the H-bridge

LENA/RENA LENB/REN
B
0 0

0 1

1 0

1 1
• 1 H-bridge = 2 movements

0, 0  stop
0, 1  CCW movement
1, 0  CW movement
1, 1  X

• There’s no heat-sinking in the H-bridge


• Buffer is used so that the SMT version of the H-bridge doesn’t burn-up due
to large current
 Buffer = NOT gate

How to create a HEX file:


 Go to option ‘Target’
 Output
 HEX file
 Once again go to option ‘Target’
 Xtal MH2 = 11.0592
 Project: go to ‘Rebuild Target Files’
 Desktop: go to ‘Flash Magic’

You might also like