DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING ETERNAL UNIVERSITY, BARU SAHIB (H.P.

)

VOCATIONAL TRAINING REPORT MICROCONTROLLER (PIC16F877A) CDAC, MOHALI

A REPORT SUBMITTED FOR VOCATIONAL TRAINING IN PARTIAL FULFILLMENT OF B.TECH DEGREE IN ELECTRONICS AND COMMUNICATION ENGINEERING ETERNEL UNIVERSITY, BARU SAHIB, DISTT. SOLAN (H.P)

UNDER THE GUIDENCE OF : MR. VIKAS MALHOTRA CDAC, Mohali

SUBMITTED BY: ARTI MEHTA 08BBEC159 ECE-A

ACKNOWLEDGEMENT

This project report is an acknowledgment to the sincere efforts of all the individuals who have contributed for the completion of my industrial training report. It gives me immense pleasure to express my gratitude to all staff of All India Radio FM station Dharamshala, Himachal Pradesh. who went through the manuscript personally and contributed his valuable suggestion in editing and reviewing. Without their active support it would not be possible to complete this report. I am confident that this project will be useful and dependable guide for incoming student. The constructive suggestion for further improvement will be much appreciable.

INDEX
          Introduction to microcontroller PIC Microcontroller Architecture Memory Concepts Programming (Byte Oriented Instruction) Programming (Bit Oriented Instruction) Programming (Literal and control Oriented Instruction) Port and Power supply LED and Relay Interfacing Switch Interfacing LCD Interfacing

INTRODUCTION
What is a Microcontroller….
It is a device that has been developed to work on specific application. It is an advancement on microproccesor . • • • • • • • Reduce chip count. Many applications do not require as much computing power. Reduced power consumption. Reduced design cost Microcontrollers come as 4-bit , 8-bit , 16-bit and 32-bit Execute a stored set of instructions to carry out user defined tasks. Ability to interface with I/O Devices.

MICROPROCESSOR V/S MICROPROCESSOR
 A microprocessor (uP) is a one-chip CPU such as the Intel 80x86, or Pentium series, the Motorola 68000 series, the PowerPC series and so on…  These single-chip systems were called microprocessors because they replaced an older generation which used multiple chips and even multiple pc boards to perform the same functions.  A uP needs additional chips such as RAM, ROM, serial and parallel ports, timers, interrupt controllers and so on to make a complete cpu (motherboard).  A microcontroller (uC) has the CPU and most, if not all of these peripheral functions built into a single chip.  uCs tend to be much smaller than modern uPs, with memory in tens of bytes to kilobytes.  uCs can also include other features such as oscillator-on-chip, A/D converters, reset circuitry, high current I/O drive capability, watchdog timers etc.

The benefit of uCs in embedded systems is that complete systems can be built with a very low component count, frequently just one chip.

MICROCONTROLLER ARCHITECTURE
 Memory is needed for programs and data.  Program memory used in embedded systems is typically of non-volatile type.  Data memory used is SRAM- or DRAM- type volatile memory.

Von Neumann-architecture:
Program and data located in same address space.

Harvard-architecture:
Separate address spaces and buses for program and data memories.

Harvard Vs Von Neumann..

Examples Harvard: 8051 Microchip PIC families Atmel AVR Von Neumann: PCs (Intel 80x86/Pentium) Motorola 68000 Motorola 68xx uC families

Features of Different processor Architectures…
CISC • • • • • RISC • • • • • Load/store Architecture generally. Fixed length instruction Generally inst.=1 clock More general purpose internal registers PIC,ARM,AVR… Addressing modes. Variable length inst. No. of clocks >1 Less general purpose internal registers x86,8051…

Overview of PIC16FXX family
Low - end PIC Architectures :
Microchip PIC microcontrollers are available in various types. When PIC microcontroller MCU was first available from General Instruments in early 1980's, the microcontroller consisted of a simple processor executing 12-bit wide instructions with basic I/O functions. These devices are known as low-end architectures. They have limited program memory and are meant for applications requiring simple interface functions and small program & data memories. Some of the low-end device numbers are 12C5XX 16C5X 16C505

Mid range PIC Architectures
Mid range PIC architectures are built by upgrading low-end architectures with more number of peripherals, more number of registers and more data/program memory. Some of the midrange devices are 16C6X 16C7X 16F87X

The features of the PIC16FXX
      8-bit CPU optimized for control applications Only 35 instructions to learn All single-cycle instructions except branches 8K ROM memory in FLASH technology 368 bytes RAM memory 256 bytes EEPROM memory

 A/D converter: 14-channels 10-bit resolution  35 input/output pins

High current source/sink for direct LED drive software and individually programmable pull-up resistor Interrupt-on-Change pin  In-Circuit Serial Programming Option  3 independent timers/counters  Analogue comparator module with Two analogue comparators Programmable on-chip voltage reference  Enhanced USART module Supports RS-485, RS-232 and LIN2.0 Auto-Baud Detect  Oscillator & Clock Circuit

Block Diagram of PIC16f877a

Pinout diagram of PIC16F877a

Pin Description of 16F877a

NAME MCLR/VPP

NUMBER 1

FUNCTION MCLR VPP

DESCRIPTION Master Clear (Reset) input. This pin is active low Programming voltage input. Digital I/O. Analog input 0 Digital I/O. Analog input 1. Digital I/O. Analog input 2. A/D reference voltage (Low) input. Comparator VREF output. Digital I/O. Analog input 3. A/D reference voltage (High) input. Digital I/O – Open-drain when configured as output. Timer0 external clock input. Comparator 1 output. Digital I/O. Analog input 4. SPI slave select input. Comparator 2 output. Digital I/O.

RA0/AN0

2

RA0 AN0

RA1/AN1

3

RA1 AN1

RA2/AN2/VREF-/CVREF

4

RA2 AN2 VREF CVREF

RA3/AN3/VREF+

5

RA3 AN3 VREF+

RA4/T0CKI/C1OUT

6

RA4 T0CKI C1OUT

RA5/AN4/SS/C2OUT

7

RA5 AN4 SS C2OUT

RE0/RD/AN5

8

RE0

RD AN5 RE1/WR/AN6 9 RE1 WR AN6 RE2/CS/AN7 10 RE2 CS AN7 VDD VSS OSC1/CLKI 11 12 13 OSC1 CLKI

Read control for Parallel Slave Port. Analog input 5. Digital I/O. Write control for Parallel Slave Port. Analog input 6. Digital I/O. Chip select control for Parallel Slave Port. Analog input 7. Positive supply Ground Oscillator crystal input External clock source input. Always associated with pin function OSC1

OSC2/CLKO

14

OSC2 CLKO

Oscillator crystal output. In RC mode, OSC2 pin outputs CLKO, which has 1/4 the frequency of OSC1

RC0/T1OSO/T1CKI

15

RC0 T1OSO T1CKI

Digital I/O. Timer1 oscillator output. Timer1 external clock input Digital I/O. Timer1 oscillator input. Capture2 input, Compare2 output, PWM2 output.

RC1/T1OSI/CCP2

16

RC1 T1OSI CCP2

RC2/CCP1

17

RC2 CCP1

Digital I/O. Capture1 input, Compare1 output, PWM1 output. Digital I/O. Synchronous serial clock input/output for SPI mode. Synchronous serial clock input/output for I2C mode.

RC3/SCK/SCL

18

RC3

SCK

SCL

RD0/PSP0

19

RD0 PSP0

Digital I/O. data.

RD1/PSP1

20

RD1 PSP1

Digital I/O. data.

RD2/PSP2

21

RD2 PSP2

Digital I/O. data.

RD3/PSP3

22

RD3 PSP3

Digital I/O. data.

RC4/SDI/SDA

23

RC4 SDI

Digital I/O. SPI data in.

SDA

I2C data I/O

RC5/SDO

24

RC5 SDO

Digital I/O. SPI data out.

RC6/TX/CK

25

RC6

Digital I/O.

TX CK

USART asynchronous transmit. USART1 synchronous clock

RC7/RX/DT

26

RC7 RX DT

Digital I/O. USART asynchronous receive. USART synchronous data. Digital I/O. data. RD5 PSP5 Digital I/O. data. Digital I/O.

RD4/PSP4

27

RD4 PSP4

RD5/PSP5

28

RD6/PSP6

29

RD6

PSP6 RD7/PSP7 30 RD7 PSP7 VSS VDD RB0/INT 31 32 33 RB0 INT RB1 RB2 RB3/PGM 34 35 36 RB3 PGM RB4 RB5 RB6/PGC 37 38 39 RB6

data. Digital I/O. data. Ground Positive supply Digital I/O. External interrupt. Digital I/O. Digital I/O. Digital I/O. Low-voltage ICSP programming enable pin. Digital I/O. Digital I/O. Digital I/O. In-circuit debugger and ICSP programming clock. Digital I/O. In-circuit debugger and ICSP programming data.

PGC RB7/PGD 40 RB7

PGD

Important Terms used in PIC16F877A
Pulse P: It is the smallest interval of time within microcontroller established by the clock
frequency.

Machine Cycle: Smallest interval of time to accomplish any simple instruction or part of
complex instruction.

State: Basic time interval for discrete operations of machine cycles, such as fetching op-code
byte, decoding an opcode etc.

Machine cycle in PIC16F877A..
The execution time is the same for all instructions except two and lasts 4 clock cycles (oscillator frequency is stabilized by a quartz crystal). The Jump and Branch instructions execution time is

2 clock cycles. It means that if the microcontroller’s operating speed is 20MHz, execution time of each instruction will be 200nS, i.e. the program will be executed at the speed of 5 million instructions per second! STATUS REGISTER Bit7 Bit0

bit 7 IRP: Register Bank Select bit (used for indirect addressing) 1 = Bank 2, 3 (100h-1FFh) 0 = Bank 0, 1 (00h-FFh) bit 6-5 RP1:RP0: Register Bank Select bits (used for direct addressing) 11 = Bank 3 (180h-1FFh) 10 = Bank 2 (100h-17Fh) 01 = Bank 1 (80h-FFh) 00 = Bank 0 (00h-7Fh) Each bank is 128 bytes. bit 4 TO: Time-out bit 1 = After power-up, CLRWDT instruction or SLEEP instruction 0 = A WDT time-out occurred bit 3 PD: Power-down bit 1 = After power-up or by the CLRWDT instruction 0 = By execution of the SLEEP instruction bit 2 Z: Zero bit 1 = The result of an arithmetic or logic operation is zero 0 = The result of an arithmetic or logic operation is not zero bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions) (for borrow, the polarity is reversed)

1 = A carry-out from the 4th low order bit of the result occurred 0 = No carry-out from the 4th low order bit of the result bit 0 C: Carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions) 1 = A carry-out from the Most Significant bit of the result occurred 0 = No carry-out from the Most Significant bit of the result occurred

Memory concepts in PIC16f877A
Types of Memory
The PIC16f877A has three very general types of memory. To effectively program the PIC16f877A it is necessary to have a basic understanding of these memory types. The memory types are illustrated in the following graphic. They are:  On-Chip ROM Memory  On-Chip EEPROM  On-Chip RAM.  On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists within the microcontroller itself.  EPROM Memory is code (or program) memory that resides on-chip. This is often in the form of an EPROM.  EEPROM with an address range from 00h to FFh.  RAM is memory that resides on-chip. This is often in the form of standard static RAM or flash RAM.  The PIC16F87XA devices have a 13-bit program counter capable of addressing an 8K word x 14 bit program memory space.  The PIC16F876A/877A devices have 8K words x 14 bits of Flash program memory, while PIC16F873A/874A devices have 4K words x 14 bits.  The PIC16F876A/877A devices have 256 bytes of data

Program Memory
 The program memory in the PIC16F877A has a total of 8K words. . After the program memory has been programmed it will retain the program even if power is lost. Therefore program memory is said to be nonvolatile.  The 8K words or program memory are made up of 4 sections or Pages of 2K words each. Within each page every 14 bit word has an address with the first one starting at 000hex and ending with 7FFhex which corresponds to 0 through 2047 decimal. The MCU can

only use one of the program memory pages at a time. To read or write to a different page requires the programmer to do page switching within his program.

EEPROM Memory
 This memory is nonvolatile meaning that it will retain its data even if the power is lost. EEPROM is normally used to store parameter data that needs to be saved over a long period over many power-up and power-down cycles. Writing to EEPROM involves a more complex series of steps than writing to the File Registers. Each write cycles is very slow compared to writing to the File Registers. However reading is much simpler and much faster. The procedures for using this type of memory will be covered in an intermediate course.  The PIC16F877A has 256 bytes of EEPROM memory. The EEPROM memory is separate from program memory and data memory. It has it own address space. To read or write to EEPROM memory the Special Function Registers are used such as EEDATA and EEADR

Data memory Organization
RP1:RP0 00 01 10 11 Bank 0 1 2 3

The data memory is partitioned into multiple banks

which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (Status<6>) and RP0 (Status<5>) are the bank select bits. • Bank3 • The concept of register banks adds a great level of flexibility to the PIC16f877A, especially when dealing with interrupts Four Banks: Bank0, Bank1, Bank2,

Special Function Register (SFR)
The Special Function Registers are registers used by the CPU and peripheral modules for controlling desired operation of the device. These registers are implemented as static RAM. The Special Function Registers can be classified into two sets: core (CPU) and peripheral.

Core (CPU) registers - control and monitor operation and processes in the central processor. Even though there are only a few of them, the operation of the whole microcontroller depends on their contents. Peripheral SFRs- control the operation of peripheral units (serial communication module, A/D converter etc.). Input /Output Ports  PORTA and the TRISA Register  PORTA is a 6-bit wide, bidirectional port.  Data direction register is TRISA.  Set TRISA bit (= 1) will make the corresponding PORTA pin input  Clear TRISA bit (= 0) will make the corresponding PORTA pin output  PORTB and the TRISB Register  PORTB is an 8-bit wide, bidirectional port.  Data direction register is TRISB.  Set TRISA bit (= 1) will make the corresponding PORTA pin input  Clear TRISA bit (= 0) will make the corresponding PORTA pin output  PORTC and the TRISC Register  PORTC is an 8-bit wide, bidirectional port.  Data direction register is TRISC.  Set TRISC bit (= 1) will make the corresponding PORTC pin input  Clear a TRISC bit (= 0) will make the corresponding PORTC pin output  PORTD and the TRISD Register  PORTD is an 8-bit wide, bidirectional port.  Data direction register is TRISD.  Set TRISD bit (= 1) will make the corresponding PORTD pin input

 Clear TRISD bit (= 0) will make the corresponding PORTD pin an output  PORTE and the TRISE Register  PORTE is an 3-bit wide, bidirectional port.  Data direction register is TRISE.  Set TRISE bit (= 1) will make the corresponding PORTE pin input  Clear TRISE bit (= 0) will make the corresponding PORTE pin output

Stack, Stack Pointer and Program Counter
Stack - The PIC16F87XA family has 13-bit wide hardware stack. The stack space is not part of either program or data space and the stack pointer is not readable or writable. The PC is PUSHed onto the stack when a CALL instruction is executed, or an interrupt causes a branch. The stack is POPed in the event of a RETURN, RETLW or a RETFIE instruction execution. Stack Pointer - It is an 8-bit register to hold an internal RAM address that is called top - of stack. Program Counter - The Program Counter (PC) is 13 bits wide. The low byte comes from the PCL register which is a readable and writable register. The upper bits (PC<12:8>) are not readable, but are indirectly writable through the PCLATH register. On any Reset, the upper bits of the PC will be cleared.

Addressing modes
The various ways of accessing data are called addressing modes. The data could be in a register or in memory, or be provided as an immediate value. 1. Direct Addressing 2. Indirect Addressing 1.Direct Addressing Mode:• In direct addressing mode, the operand data is in a RAM memory location whose address is known and this address is given as a part of instruction. Direct Addressing is done through a 9-bit address. This address is obtained by connecting 7th bit of direct address of an instruction with two bits (RP1, RP0) from STATUS register as is shown in example. Any access to SFR registers is an example of direct addressing. Eg. Bsf STATUS, RP0 ;select bankl movlw 0xFF ;w=0xFF movwf TRISA ;address of TRISA register is from ;instruction movwf

• •

taken

2.Indirect Addressing Mode:Indirect addressing is possible by using the INDF register. Any instruction using the INDF register actually accesses the register pointed to by the File Select Register,FSR. Reading the INDF register itself, indirectly (FSR = 0) will read 00h. An effective 9-bit address is obtained by concatenating the 8-bit FSR register and the IRP bit. Eg. Let’s take one general purpose register (GPR) at address 0Fh contains a value of 20. By writing a value of 0Fh in FSR register we will get a register indicator at address 0Fh, and by reading from INDF register, we will get a value of 20, which means that we have read from the first register its value without accessing it directly (but via FSR and INDF). It appears that this type of addressing does not have any advantages over direct addressing, but certain needs do exist during programming which can be solved smoothly only through indirect addressing. Eg: Temp Equ 0x030 ;address of temp is 0x030 Movlw 0x30 Movwf FSR Movlw 5 Movwf INDF

Instruction Set
The PIC16 instruction set is highly orthogonal and is comprised of three basic categories:    Byte-oriented operations Bit-oriented operations Literal and control operations

BYTE-ORIENTED OPERATIONS
• ADDWF f,d Add W and f

Add the contents of the W register with register ‘f’. If ‘d’ is ‘0’, the result is stored in the W register. If ‘d’ is ‘1’, the result is stored back in register ‘f’. • ANDWF f,d AND W with f

AND the W register with register ‘f’. If ‘d’ is ‘0’, the result is stored in the W register. If ‘d’ is ‘1’, the result is stored back in register ‘f’. • CLRF f Clear f

The contents of register ‘f’ are cleared • INCF f,d Increment f

The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. • INCFSZ f,d Increment f, Skip if 0

The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. If the result is ‘1’, the next instruction is executed. If the result is ‘0’, a NOP is executed instead, making it a 2 TCY instruction. • IORWF f,d Inclusive OR W with f

Inclusive OR the W register with register ‘f’. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. • MOVF f,d mov f

MOVF instruction is used to bring data into WREG register from I/O pins Eg: MOVF PORTB,W • MOVWF f ; Bring data from portB into WREG mov W to F

Mov the content of WREG register to F register Eg: MOVLW 55H MOVWF PORTB • • NOP RLF f,d ;WREG= 55H : Copy WREG to PortB (PortB=55H)

no operation Rotate Left f through Carry

The contents of register ‘f’ are rotated one bit to the left through the Carry flag. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is stored back in register ‘f’. • RRF f,d Rotate Right f through Carry

The contents of register ‘f’ are rotated one bit to the right through the Carry flag. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. • SUBWF f,d Subtract W from f

Subtract (2’s complement method) W register from register ‘f’. If ‘d’ is ‘0’, the result is stored in the W register. If ‘d’ is ‘1’, the result is stored back in register ‘f’.

SWAPF f,d

Swap Nibbles in f

The upper and lower nibbles of register ‘f’ are exchanged. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed in register ‘f’. Eg: MYREG EQU 72h MOVWF MYREG SWAPF MYREG,F ; MYREG = 72H ; MYREG = 27H

XORWF f,d

Exclusive OR W with f

Exclusive OR the contents of the W register with register ‘f’. If ‘d’ is‘0’, the result is stored in the W register. If ‘d’ is ‘1’, the result is stored back in register ‘f’. • DECFSZ f,d Decrement f, Skip if 0

The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. If the result is ‘1’, the next instruction is executed. If the result is ‘0’, then a NOP is executed instead, making it a 2 TCY instruction. DECFSZ MYREG, F ; decrement MYREG and skip if MYREG =0 (Here F=1)

BIT-ORIENTED FILE REGISTER OPERATIONS • BCF f,d Bit Clear f Eg: BCF TRISB , 2 ; bit=0,make RB2 an output pin

Bit ‘b’ in register ‘f’ is cleared. • BSF f,d Bit Set f

Bit ‘b’ in register ‘f’ is set. Eg: BSF PORTD, 0 • BTFSS f,d ; bit set turn on RD0 Bit Test f, Skip if Set

If bit ‘b’ in register ‘f’ is ‘0’, the next instruction is executed. If bit ‘b’ is ‘1’, then the next instruction is discarded and a NOP is executed instead, making this a 2 TCY instruction. Eg: BTFSS PORTB,3 BRA HERE BSF PORTB,2 • BTFSC f,d Bit Test, Skip if Clear ;keep monitoring RB3 for high

If bit ‘b’ in register ‘f’ is ‘1’, the next instruction is executed. If bit ‘b’ in register ‘f’ is ‘0’, the next instruction is discarded. Eg: BTFSC PORTB,3 BRA HERE BSF PORTB,2 ;keep monitoring RB3 for low

LITERAL & CONTROL INSTRUCTIONS
 ANDLW k AND Literal with W

 The contents of W register are AND’ed with the eight-bit literal ‘k’. The result is placed in the W register. Eg:  ADDLW k Add Literal and W

 The contents of the W register are added to the eight-bit literal ‘k’ and the result is placed in the W register.  Eg: MOVLW 25H ADDLW34H ; ; Load 25H into the WREG add value 34 to W

Executing the above lines results in WREG=59H  CALL k Call Subroutine

Call Subroutine. First, return address (PC+1) is pushed onto the stack. The eleven-bit immediate address is loaded into PC bits <10:0>. The upper bits of the PC are loaded from PCLATH. CALL is a two-cycle instruction. CLRWDT Clear Watchdog Timer

 CLRWDT instruction resets the Watchdog Timer. It also resets the prescaler of the WDT. Status bits, TO and PD, are set.  GOTO k Unconditional Branch

 GOTO is an unconditional branch. The eleven-bit immediate value is loaded into PC bits <10:0>. The upper bits of PC are loaded from PCLATH<4:3>. GOTO is a two-cycle instruction.  IORLW k Inclusive OR Literal with W

 The contents of the W register are OR’ed with the eight-bit literal ‘k’. The result is placed in the W register.  RETURN Return from Subroutine

 Return from subroutine. The stack is POPed and the top of the stack (TOS) is loaded into the program counter. This is a two-cycle instruction.  SLEEP Go into the standby mode

 The power-down status bit, PD,is cleared. Time-out status bit, TO, is set. Watchdog Timer and its prescaler are cleared.The processor is put into Sleep mode with the oscillator stopped. • • SUBLW k Subtract W from Literal

The W register is subtracted (2’s complement method) from the

eight-bit literal ‘k’. The result is placed in the W register. • • XORLW k Exclusive OR Literal with W

The contents of the W register are XOR’ed with the eight-bit literal ‘k’. The result is placed in the W register. Move literal to W

 MOVLW K

 Move literal value which is of 8-bit that can be range from 0-255 into the WREG register Eg: MOVLW 25h :  RETFIE Mov 25h value into WREG register Return from interrupt

After an interrupt this instruction returns back to the main program. It does this by pulling from the stack the program counter.  RETLW K Return with literal in W or subprogram with constant in W 8-bit constant K is stored in W register .Value off the top of the stack is stored in program counter Return from a

Power supply for PIC

BASIC INTERFACINGS Interfacing Switch to PIC16F877A
 In the given figure when the switch is not pressed the 10k resistor provides the current needed for LOGIC 1 closure of switchaewsesre provides LOGIC 0 to the controller PIN.

Interfacing LED to PIC16F877A
 Figure shows how to interface the LED to microcontroller. As you can see the Cathode is connected through a resistor to Ground & the Anode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is ON & when the Port Pin is LOW the LED is turned OFF.

Relay Interfacing
Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. For a relay to operate a suitable pull-in & holding current should be passed through its coil. Generally relay coils are designed to operate from a particular voltage often its 5V or 12V. The function of relay driver circuit is to provide the necessary current (typically 25 to 70ma) to energize the relay coil.

Connection with PIC16F877a
 2 shows the basic relay driver circuit. As you can see an NPN transistor BC547 is being used to control the relay. The transistor is driven into saturation (turned ON) when a LOGIC 1 is written on the PORT PIN thus turning ON the relay. The relay is turned OFF by writing LOGIC 0 on the port pin. A diode (1N4007/1N4148) 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.

Seven Segment Display Interfacing with Pic16F877a
 Figure shows how to interface 7-seg display to a microcontroller. Now we create a lookup table containing the seven segment pattern to display the corresponding hex digits. e.g. consider we have to display '1' from the above figure we come to know that turning ON segment B & C will show '1' on the 7-seg display so RB1 & RB2 should be LOGIC 0 whereas rest of the pins should be LOGIC 1.

LCD Interfacing

Pin Description
Pin No  1  2  3  4  5  6  7-14  15  16 Description Vss Vcc Contrast Voltage RS R/W EN Data Input/Output Pins (D0-D7) Anode (K) Cathode (K)

 1) Vss- Vss is connected to the ground.  2) Vcc- Vcc is connected to +5V.  3) Contrast Voltage- Vee is used for controlling LCD Contrast. Variable pin of Variable Resistor of 10K is connected to this pin.  4) RS- RS is used for the selection of internal resistors of LCD.

 Command Code Register – It allows the user to send command such as clear display, cursor at home etc.  Data Register – It allows the user to send data to be displayed on LCD. If RS=0, then Command Register is selected. If RS=1, then Data Register is selected.  5) R/W- R/W input allows user to write information to the LCD or read information from it. R/W=1 when Reading R/W=0 when Writing  6) EN- This enable pin is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a High-to-low pulse must be applied to this pin.  7) Pin 7-14 – The 8-bit data pins, D0-D7 are used to send information to LCD or read the contents of the LCD’s internal registers. To Display letters and numbers, ASCII codes for letters and numbers are sent to these pins while making RS=1.

Hardware Connection of PIC16F877A With LCD

Sign up to vote on this title
UsefulNot useful