KEMBAR78
Module 3 | PDF | Microcontroller | Electronics
0% found this document useful (0 votes)
28 views27 pages

Module 3

Mcplc module 3

Uploaded by

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

Module 3

Mcplc module 3

Uploaded by

vidris094
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

BASICS OF SERIAL COMMUNICATION

• Computers transfer data in two ways:

– Parallel: Often 8 or more lines (wire conductors) are used to transfer data to a device
that is only a few feet away.

– Serial: To transfer to a device located many meters away, the serial method is used. The
data is sent one bit at a time.

COMPARISON

BASICS OF SERIAL COMMUNICATION


• Serial communication uses single data line making it much cheaper

• Byte of data must be converted to serial bits using a parallel-in-serial out shift register and
transmitted over a single data line

• At the receiving end there must be a serial-in-parallel-out shift register

MODES OF SERIAL COMMUNICATION

1.Simplex mode:
In simplex mode, Sender can send the data but that sender can’t receive the data. It is a unidirectional
communication.(Eg:COM and Printer)

2. Half-duplex mode:
In half duplex mode, Sender can send the data and also can receive the data but one at a time(Eg:Walkie
Talkies)

3.Full duplex mode:


In full duplex mode, Sender can send the data and also can receive the data
simultaneously(Eg:Telephone)

• Serial data communication uses two methods

– Synchronous method transfers a block of data at a time

– Asynchronous method transfers a single byte at a time

• There are special IC’s made by many manufacturers for serial communications.

– UART (universal asynchronous Receiver transmitter)


– USART (universal synchronous-asynchronous Receiver-transmitter)

– 8051 chip has a built-in UART

DATA FRAMING IN ASYNCHRONOUS SERIAL COMMUNICATION

• Data is transmitted in 0s and 1s

• Transmitter and Receiver have certain rules(Protocols) for data transmission/receiving Which
describes

1. how the data is packed

2. how many bits constitute a character

3. when the data begins and ends

4. Asynchronous serial data communication is widely used for character-oriented transmissions

1. Each character is placed in between start and stop bits, this is called data framing.

5. The start bit is always one bit, but the stop bit can be one or two bits

6. The start bit is always a 0 (low) and the stop bit(s) is 1 (high)

7.

8. We are transmitting 10 Bits(including one stop/start bit) for 8 bit data transmission
9. This gives 25% overhead, i.e. each 8-bit character with an extra 2 bits

10. In some systems in order to maintain data integrity, the parity bit of the character byte is
included in the data frame

11. UART chips allow programming of the parity bit for odd-, even-, and no-parity options

UART Block diagram

DATA TRANSFER RATE

• The rate of data transfer in serial data communication is stated in bps (bits per second)

• The data transfer rate of given computer system depends on communication ports incorporated
into that system

• Another widely used terminology for bps is baud rate

• It is modem terminology and is defined as the number of signal changes per second

1. For IBM PC/XT could transfer data at the rate of 100 to 9600 bps

2. In asynchronous serial data communication, the baud rate is limited to 100K bps
RS232 STANDARDS

• An interfacing standard RS232 was set by the Electronics Industries Association (EIA) in 1960

• In RS232, a 1 is represented by -3 ~ -25 V, while a 0 bit is +3 ~ +25 V, making -3 to +3 undefined


(For 8051b logic 0-0V and logic 1 is 5V)

• The standard was set long before the advent of the TTL logic family, its input and output voltage
levels are not TTL compatible

• A microcontroller system must use voltage converters such as MAX232 to convert the TTL logic
levels to the RS232 voltage levels, and vice versa

• Earlier RS232 having 25 pins

• Since not all pins are used in PC cables, IBM introduced the DB-9 version of the serial I/O
standard

RS232 Connector DB-9

• Current terminology classifies data communication equipment as

1. DTE (data terminal equipment) refers to terminal and computers that send and receive data

2. DCE (data communication equipment) refers to communication equipment, such as modems

• The simplest connection between a PC and microcontroller requires a minimum of three pins,
TxD, RxD, and ground
RS232 PINS

• DTR (data terminal ready) When terminal is turned on, it sends out signal DTR to indicate that it
is ready for communication

• DSR (data set ready) When DCE is turned on and has gone through the self-test, it assert DSR to
indicate that it is ready to communicate

• RTS (request to send) When the DTE device has byte to transmit, it assert RTS to signal the
modem that it has a byte of data to transmit

• CTS (clear to send) When the modem has room for storing the data it is to receive, it sends out
signal CTS to DTE to indicate that it can receive the data now

• DCD (data carrier detect): The modem asserts signal DCD to inform the DTE that a valid carrier
has been detected and that contact between it and the other modem is established

• RI (ring indicator) : An output from the modem and an input to a PC indicates that the telephone
is ringing • It goes on and off in synchronous with the ringing sound

8051 CONNECTION TO RS232

• A line driver such as the MAX232 chip is required to convert RS232 voltage levels to TTL levels,
and vice versa

• 8051 has two pins that are used specifically for transferring and receiving data serially

1. These two pins are called TxD and RxD and are part of the port 3 group (P3.0 and P3.1)
2. These pins are TTL compatible; therefore, they require a line driver to make them RS232
compatible

REGISTERS RELATED TO SERIAL COMMUNICATION

1. SBUF Register

2. SCON Register

3. PCON Register

1)SBUF Register

• SBUF is an 8-bit register used solely for serial communication.

• For a byte data to be transferred via the TxD line, it must be placed in the SBUF register.

• The moment a byte is written into SBUF, it is framed(added) with the start and stop bits and
transferred serially via the TxD line.

• SBUF holds the byte of data when it is received by 8051 RxD line.

• When the bits are received serially via RxD, the 8051 deframes it by eliminating the stop and
start bits, making a byte out of the data received, and then placing it in SBUF.
2)SCON

• SCON Register used to control the serial data communication


• It is an 8 bit register
• Data is transmitted/Received through TXD and RXD pins of 8051
• SM0,SM1 and SM2 are mode selection bits

Modes of operations

1)MODE 0(Synchronous Serial Communication)

1. Serial data enters and exits through RXD


2. TXD outputs the clock

3. 8 bits are transmitted / received

4. The baud rate is fixed at (1/12) of the oscillator frequency

2)MODE 1(8-Bit UART with Timer Data Rate)

1. Serial data enters through RXD

2. Serial data exits through TXD

3. On receive, the stop bit goes into RB8 in SCON

4. 10 bits are transmitted / received

1. Start bit (0)

2. Data bits (8)

3. Stop Bit (1)

3)MODE 2(9-Bit UART with Set Data Rate)

1. Serial data enters through RXD

2. Serial data exits through TXD

3. 11 bits are transmitted / received

1. Start bit (0)

2. Data bits (9)

3. Stop Bit (1)

3)PCON REGISTER
• There are two ways to increase the baud rate of data transfer

1. By using a higher frequency crystal

2. By changing a bit in the PCON register(SMOD bit)

o When 8051 is powered up, SMOD is zero


o We can set it to high by software and thereby double the baud rate

8051 INTERFACING

• The interconnection of the peripheral devices ,memory within the a micro computer system is
called interfacing

• The transfer of data between the microcomputer system and I/O devices requires an interface
between them

Why interfacing?

• Microcontroller works digitally but most I/O devices are analogue in nature

• Micro controller outputs low power level but i/o devices requires large power

• To increase the number of I/O ports

• It is a circuitry or IC especially designed to convert signals received from I/O devices to suitable
format

• The I/O devices away from microcontroller but interface module is very close to the
microcontroller(may be in same PCB)

• Eg:

1. 8155,8255-PPI

2. 8251USART
3. 8253,8254-PROGRAMMABLE TIMER/COUNTER

4. 8279-KEYBOARD DISPLAY CONTROLLER

5. ADC AND DAC

8255 PPI(8255 PROGRAMMABLE PERIPHERAL INTERFACE)

• MAKE :INTEL

• It is TTL Compatible

• Some manufactures use the term peripheral interface adapter(PIA)

• It is a multiport Input/output device

• It is 40 pin DIP(Dual in package) IC

• It operates on supply voltage +5V

• It has three 8 bit I/O ports namely, Port A, Port B, Port C

• Port C further divided into 4 bit ports, Port C Upper and Port C lower

• Thus total 4 ports are available

8255 PIN DIAGRAM


• RD(Read):A low(0) on the control pin enables microcontroller to read data from the selected I/O
ports of 8255

• WR(Write): A low(0) on the control pin enables microcontroller to write data into the selected
I/O ports of 8255

• CS(Chip select):A low on this pin selects select 8255 PPI. It enables communication between
microcontroller and 8255 when it is low.

• RESET:

1. An active-high signal input

2. Used to clear the control register

3. When RESET is activated, all ports are initialized as input ports

4. The RESET input pin is normally connected to RESET out signal of the Microcontroller so
whenever microcontroller is RESET it also RESETS the 8255

• D0-D7:

1. Data pins that are connected with the data pins of microcontroller

2. Allowing it to send data back and forth between the controller and the 8255 chip
A0-A1:it is A0 and A1 that select specific ports

8255 ARCHITECTURE/BLOCK DIAGRAM

• Each port can be programmed as an input port or output port

• It has an 8 bit register to store the control word

• The control word can make the three ports as input/output

• Port A and Port C Upper are grouped together as Group A and Port B, Port C Lower grouped
together as Group B

• PA0 - PA7 (8-bit port A):Can be programmed as all input or output

• PB0 - PB7 (8-bit port B): Can be programmed as all input or output
• PC0 – PC7 (8-bit port C):
1. We can make all input or output
2. Or Can also be split into two parts:
a. CU (upper bits PC4 - PC7)
b. CL (lower bits PC0 – PC3)

each can be used for input or output

• Any of bits PC0 to PC7 can be programmed individually

• 8255 having two modes of operation(BIT SET/RESET & I/O MODES(MODE0,MODE1,MODE2)

• Data bus: Bidirectional bus and used for transferring data

• Address bus :Unidirectional bus for specifying the address for storing data

PORT SELECTION IN 8255

8255 MODES

• Two basic modes of 8255 are I/O mode and Bit Set-Reset mode (BSR).

• While ports A, B and C are used to input or output data, the control register must be
programmed to select operation mode of three ports

• 8255 have three I/O modes of operation(Mode0,Mode1 and Mode2)


1)Mode 0,(simple I/O)

• Any of the ports A, B, CL, and CU can be programmed as input out output

• All bits are out or all are in

2)Mode 1

• Port A and B can be used as input or output ports with handshaking capabilities

• Handshaking signals are provided by the bits of port C

3)MODE-2(Bidirectional I/O mode)

• Port A can be used as a bidirectional I/O port with handshaking capabilities provided by port C

• Port B can be used either in mode 0 or mode 1

4)BSR MODE(BIT ST-RESET MODE)

• It uses only in Port C

• Any bit of this Port can be set/reset by appropriate control word register in CWR

• In this mode I/o operations of Port A, Port B are not disturbed

PROGRAMMING OF 8255

A)CONTROL WORD REGISTER


• 8255 is a programmable I/O device

• Programming done by Writing control word to control word register

• As per the requirement a port can be programmed as either input or output

EXAMPLE

• Find the control word of the 8255 for the following configurations:

(a) All the ports of A, B and C are output ports (mode 0)

(b) PA = in, PB = out, PCL = out, and PCH = out

Answer

(a) 1000 0000 = 80H (b)1001 0000 = 90H

STEPPER MOTOR INTERFACING WITH 8051

• A stepper motor is a device that translates electrical pulses into mechanical movement in steps
of fixed step angle.

• It is used in disk drives, dot matrix printers, plotters and robotics and process control circuits.

• Stepper motors have a permanent magnet called rotor (also called the shaft) surrounded by a
stator

• Even a small stepper motor require a current of 400 mA for its operation.

• But the ports of the microcontroller cannot source this much amount of current.

• If such a motor is directly connected to the microprocessor/microcontroller ports, the motor


may draw large current from the ports and damage it
• So we used an 8255 between stepper motor and 8051

• Stepper motor driver circuits are available readily in the form of ICs.

• ULN2003 is one such driver IC which is a High-Voltage High-Current Darlington transistor array
and can give a current of 500mA.

• This current is sufficient to drive a small stepper motor.

• Internally, it has protection diodes used to protect the motor from damage due to back emf and
large eddy currents.

PROGRAMMING

• The hex code mainly depends on the construction of the stepper motor

• All the stepper motors do not have the same Hex code for their rotation. (refer the operation
manual supplied by the manufacturer.)

• For example, let us consider the hex code for a stepper motor to rotate in clockwise direction is
77H , BBH , DDH and EEH.

• This hex code will be applied to the input terminals of the driver through the assembly language
program

ORG 0000H;

MOV A,#80H ;control word for PA=out

MOV DPTR,#CRPORT ;CWR port address(Depend upon the connection between 8051 and 8255)

MOVX @DPTR,A ;configure PA=out

MOV DPTR,#APORT ;load PA address((Depend upon the connection between 8051 and 8255))

MAIN:MOV A,#77H ;A=77H,stepper motor

MOVX @DPTR,A ; Load contents of A to PORT A of 8255

ACALL DELAY;

MOV A,# BBH; Load value BB to A(For the next step of stepper Motor)

MOVX @DPTR,A ; Load contents of A to PORT A of 8255

ACALL DELAY;

MOV A,# DDH; Load value DD to A(For the next step of stepper Motor)
MOVX @DPTR,A ; Load contents of A to PORT A of 8255

ACALL DELAY;

MOV A,# EEH; Load value EE to A(For the next step of stepper Motor)

MOVX @DPTR,A ; Load contents of A to PORT A of 8255

ACALL DELAY;

SJMP MAIN;

DELAY:MOV R4, #0FF H ; Load R4 with FF

MOV R5, # 0FF ; Load R5 with FF

LOOP1: DJNZ R4, LOOP1 ; Decrement R4 until zero,wait

LOOP2: DJNZ R5, LOOP2 ; Decrement R5 until zero,wait

RET ; Return to main program .

RELAY INTERFACING

• Relays are switches that open and close circuits when actuated by an electrical signal

• Relays are the link between the low power digital electronics and high power devices.

• Microcontroller cant drive the relay directly(5V and having small current rating)

• With the help of transistor ,the relay on off is controlled


• The transistor turned on and off by writing logic 1 and 0 to the corresponding port pin

• A diode is connected across the relay coil this is done so as to protect the transistor from
damage due to the BACK EMF generated in the relay's inductive coil when the transistor is
turned OFF.

• When the transistor is switched OFF the energy stored in the inductor is dissipated through the
diode & the internal resistance of the relay coil

PROGRAM(CONSIDERING TRANSISTOR IS CONNECTED TO P1.0(PORT 1 PIN 0))

Org 0000h;

BACK:MOV A,#00H;Load 00 H value to accumulator

MOV P1,A;All pins of P1 is logic0(Transistor off and relay is in off)

ACALL DELAY; Wait

MOV A,#01H;Load value 01h to A

MOV P1,A;P7-P4 are logic 0 and P3 to P0 Logic 1

ACALL DELAY;

DELAY:MOV R2,#255d;

K3:MOV R0,#255d;

K2:MOV R1,#255d;
K1:DJNZ R1,K1;

DJNZ R0,K2;

DJNZ R2,K3

RET

PIC MICROCONTROLLER

• PIC microcontroller was developed in the year 1993 by microchip technology.

• The term PIC stands for Peripheral Interface Controller

• Fast and easy to implement program comparing with other microcontrollers like 8051

• Used in alarm systems, phones and almost in all electronic equipments

• 4 families of IC’S(PIC10 ,PIC12 ,PIC16 ,PIC18 )

FEATURES OF PIC MICROCONTROLLERS

• Flash memory(non volatile memory like usb drive)

• Sleep Mode(Power saving)

• Watchdog timer(Watchdog Timer (WDT) can be helpful to automatically reset the system
whenever a timeout occurs)

• High speed execution

• Up to 25 mA output pin drive

• Programming of microcontroller can be done by synchronous serial pins

• USART

• SRAM(Data memory)

• Analog input port

• Brown out reset(Many microcontrollers have a protection circuit which detects when the supply
voltage goes below this level and puts the device into a reset state to ensure proper startup
when power returns)

ADVANTAGES OF PIC

• They are reliable and malfunctioning percentage is less

• Less power conception


• Programming is simple compared to other microcontrollers

• Analog ckts can be directly connected without any external ckts.

• Interfacing is very easy

DISADVANTAGE PIC

• The length of the program is high due to using RISC architecture (35 instructions)

• One single accumulator is present and program memory is not accessible

PIC18 MICROCONTROLLER

• PIC microcontroller architecture consists of RAM, ROM, CPU, timers, counters.

• At present PIC microcontrollers are extensively used for industrial purpose due to low power
consumption, high performance ability and easy of availability of its supporting hardware and
software tools like compilers, debuggers and simulators.

PIC 18 FEATURES

• 8 bit microcontroller

• 40 PIN PDIP

• I/O PIN=35

• 10 bit A/D converter

• Serial Communication Peripherals: 1-EUSART, 1-MSSP(SPI/I2C)

• Timers: 1 x 8-bit, 3 x 16-bit

• 256 bytes to 1KB EEPROM

• 4KB to 128 KB flash memory

• Operates up to 40 MHZ crystal oscillator

• Comparators: 2

• 2 KB SRAM

• It implemented with nano watt technology(low power conception)

ARCHITECTURE
• The PIC microcontroller architecture comprises of CPU, I/O ports, memory organization, A/D
converter, timers/counters, interrupts, serial communication, oscillator and CCP module

• CPU (Central Processing Unit):Overall operations are controlled by CPU. CPU consists of the ALU,
CU, MU and accumulator, etc

• Memory organisation : Includes RAM (Random Access Memory), ROM (Read Only Memory) and
STACK

• RAM: Used to store data temporarily. The RAM registers are classified into two types: Special
Function Registers (SFR) and General Purpose Registers (GPR).

• ROM: To store the data permanently. Normally programs are stored in ROM.

• Flash memory : Flash memory is also programmable read only memory (PROM) in which we can
read, write and erase the program thousands of times. Generally, the PIC microcontroller uses
this type of ROM.
• I/O Ports: The series of PIC18 consists of five ports such as Port A(8 bit), Port B(8bit), Port
C(8bit), Port D(8bit) & Port E.
• BUS:BUS is used to transfer and receive the data from one peripheral to another. It is classified
into two types such as data bus and address.
• A/D Converters :The main intention of this analog to digital converter is to convert analog
voltage values to digital voltage values.
• Timers/ Counters : PIC microcontroller has four timer/counters where in the one 8-bit timer and
the remaining timers have the choice to select 8 or 16-bit mode
• Oscillators: Oscillators are used for timing generation. PIC microcontroller consist of external
oscillators like RC oscillators or crystal oscillators

PIC16 MICROCONTROLLER

FEATURES

• Pin Count: 40-pin PDIP

• I/O PIN : 33

• Program Memory: 14KB or 8K 14-bit Flash

• Max Crystal Speed: 20MHz

• Internal Oscillator : No

• RAM Bytes: 368

• EEPROM (Bytes): 256

• Timers: 2 x 8 bit, 1 x 16-bit

• Serial Communication: 1xUSART, 1 x MSSP(SPI/I2C)

• Capture/Compare/PWM: 2 x CCP

• ADC: 10-bit

• Comparators: 2

Architecture is similar to PIC18 the difference is (No. of timers, I/O ports etc)

AVR MICROCONTROLLERS

• 8-bit RISC single chip microcontroller

• Developed by Atmel in 1996

AVR FAMILY

• 8 Bit tinyAVR Small package

Less memory(.5-8 KB, small size (6 to 32 pins ))


• 8 Bit megaAVR

They are most popular one, having good amount of memory(256KB),Pins(28-100)

• XmegaAVR

Used in complex applications . Pins(44-100),Memory(16-384 KB)

FEATURES

• High Performance 8-Bit MCU

• RISC Architecture

• 2-Address Instructions

• Single Cycle Execution

• On-chip in-system programmable memories

• Low Power

• Large linear address spaces

• Efficient C language code density

• Industrial Temperature Range

AVR TINY 25 ARCHITECTURE AND FEATURES

• 32 general purpose working registers

• All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU)

• Two independent registers can be accessed by one instruction

• System programmable flash memory(2/4/8 KB)

• EEPROM(128/256/512 bytes)

• SRAM(128/256/256 bytes )

• 6 general purpose I/O lines

• one 8-bit Timer/Counter,one 8-bit high speed Timer/Counter

• 10-bit ADC

• GIVE EXPLANATION FOR ALU,MEMORY,OSCR,ADC,REGISTERS..ETC (LIKE ALL ARCHITECTURE)


AVR ATMEGA32 ARCHITECTURE AND FEATURES

• Atmega32 has got 40 pins

• 32 (4×8) I/O pins

• Internal Calibrated RC Oscillator

• Two 8-bit Timer/Counters

• One 16-bit Timer/Counter

• 32Kbytes of In-System Self-programmable Flash program memory

• 1024Bytes EEPROM
• 2Kbytes Internal SRAM

• 32 general purpose working registers.

• All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),

• two independent registers to be accessed in one single instruction

• 10-bit ADC

• USART

• GIVE EXPLANATION FOR ALU,MEMORY,OSCR,ADC,REGISTERS..ETC (LIKE ALL ARCHITECTURE)

You might also like