0% found this document useful (0 votes)
7 views

Micro Unit 5 Question Answers Notes

Unit 5

Uploaded by

Tanmay shitole
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)
7 views

Micro Unit 5 Question Answers Notes

Unit 5

Uploaded by

Tanmay shitole
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/ 16

UNIT – V: Real Word Interfacing With 18FXXXX

Q. 1 Explain PIC 18F4XX Port Structure

• PIC18FXX microcontroller has a number of input/output pins which are used for
connection with external devices. Called as ports.

• PORTS denoted by A, B, C, D and E.

 Port A consists of seven pins named as RA0-RA6


 Port B consists of eight pins named as RB0-RA7
 Port C consists of eight pins named as RC0-RC7
 Port D consists of eight pins named as RD0-RD7
 Port E consists of three pins named as RE0-RE2
Each port has three registers for its operation. These registers are
• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the device)
• LAT register (output latch)
Internal structure of Port is as shown below

Mrs. Trupti Thite, TE ENTC Microcontroller Page 1


Above port structure consist of following components,

There are 4 cases of Operation,

Writing LOW on pin Reading LOW on pin


Writing High on pin Reading High on pin

Two cases are explained below

Case1 : Writing "LOW" on Pin Px.x Case : Reading “High" on Pin Px.x
Internal CPU Bus(DATA Latch input)= 0 Internal (TRIS Latch input)= 1
Output of DATA latch Output of TRIS latch
Q=0,Q=1 Q=1,Q=0
Internal (TRIS Latch input)= 0 OR-gate
Output of TRIS latch A input=X (Don't care)
Q=0,Q=1 B input=1
OR-gate Y output=1
A input=1 P-type MOSFET=OFF
B input=0 AND -gate
Y output=1 C input= X (Don't care)
P-type MOSFET=OFF D input =0
Z output=0
N-type MOSFET=OFF
AND -gate
C input= 1 Both FET's remains OFF and Hence Logic 1
D input =1 which at pin Px.x will be read
Z output=1
N-type MOSFET=ON Read Latch
Input =1
The pin is pulled down by the lower FET. Q=1
Hence at Px.x = logic '0' on pin. Internal CPU Bus will receive = 1
Hence the output becomes zero.

Mrs. Trupti Thite, TE ENTC Microcontroller Page 2


Q. 2 Explain PIC 18F4XX Interfacing of LED

Or

Write code to flash LED after 1 second

LED (Light emitting diode) is output device having two terminals anode and cathode. More
than one LED can be interfaced with any microcontroller using either common cathode or
common anode configuration

Forward voltage required by a diode to turn it on for red/orange/yellow LED = 1.8 – 2.2V, and
for green/blue/white LED= 3.4V.)

Algorithm

1. Configure the TRISB register to make PortB as output port.


2. Set all the bits of PORTB register High (1) to glow all LEDs.
3. Provide some delay.
4. Set all the bits of PORTB register Low (0) to turn off the LEDs.
5. Provide some delay.
6. Repeat the process from step 2.

Interfacing Diagram

Mrs. Trupti Thite, TE ENTC Microcontroller Page 3


Program for 1 second delay

#include <PIC18F4550.h>
void Delay(void); //Delay Function

Void main()
{
TRISB=0x00; //Port-B pin 4 as output
while(1)
{
PORTB=0X00; //Toggle Output
Delay();
PORTB=0X00; //Toggle Output
Delay(); //Delay
}
}
void Delay(void)
{ //10ms delay
T1CON=0x01; //Timer-1 16-bit mode Prescaler 1:4
TMR1H=0x30; //Count Hight Byte
TMR1L=0xD4; //Count Low Byte
//Runing for loop for 100 times produces 1 second 10ms x 100 = 1 second
for(int i=1;i< =100;i++)
{
T1CONbits.TMR1ON=1; //Run timer
while(INTCONbits.TMR0IF==0); //Wait for flag to over flow
T1CONbits.TMR1ON=0; //Switch off timer
INTCONbits.TMR0IF=0; //Clear Interrupt
}
}

Q. 3 Explain PIC 18F Interfacing to LCD


Or
Write embedded C code to display “Welcome” on LCD

LCD stands for Liquid crystal display. 16×2 LCD is named so because; it has 16 Columns and 2
Rows. There are a lot of combinations available like 8×1, 8×2, 10×2, 16×1, etc. but the most
used one is the 16×2 LCD. So, it will have 16×2 = 32 characters in total and each character will
be made of 5×8 Pixel Dots.

It can be used in two modes. In 4 bit mode we send the data nibble by nibble.

Mrs. Trupti Thite, TE ENTC Microcontroller Page 4


Whereas in 8 bit mode we can send the 8-bit data directly in one stroke since we use all the 8
data lines.

Interfacing Diagram for 8 bit mode

Algorithm

1. Make respective port as output using TRIS register


2. Send First commands to LCD
3. Send characters / Message /data to display on LCD

Steps for Sending Command:


step1: Send the I/P command to LCD.
step2: Select the Control Register by making RS low.
step4: Send a High-to-Low pulse on Enable PIN with some delay

Steps for Sending Data:


step1: Send the character to LCD.
step2: Select the Data Register by making RS high.
step4: Send a High-to-Low pulse on Enable PIN with some delay

Mrs. Trupti Thite, TE ENTC Microcontroller Page 5


Program:

#include<P18f4550.h
#define ldata PORTB //define name ldata to PORTB
#define rs PORTCbits.RC0 //define name rs(egister select) for RC0 pin
#define en PORTCbits.RC1 //define name en (enable) for RC1 pin

void delay(unsigned int);


void lcdcmd(unsigned char);
void lcdval(unsigned char);
void main()
{
unsigned char xc;
TRISB=0; //make PORTB as output
TRISC=0; //make PORTC as output

lcdcmd(0x38); //command to initialise LCD.


lcdcmd(0x0E); //command to make Display on cursor blinking
lcdcmd(0x01); //command to clear display screen
lcdcmd(0x06); //command to increment cursor
lcdcmd(0x86); //command to set cursor at 1st line 6th position

lcdval('W');
lcdval('e');
lcdval('l');
lcdval('c);
lcdval('o');
lcdval('m);
lcdval('e’);

while(1);
}

// lcdcmd fuction used to select COMMAND REGISTER of LCD by making,


// rs=0 and en=1 to 0 edge AND sends 8 bit command to PORTB

Mrs. Trupti Thite, TE ENTC Microcontroller Page 6


void lcdcmd(unsigned char y)
{
rs=0;
ldata=y;
en=1;
delay(10);
en=0;
delay(10);
}

// lcdval fuction used to select DATA REGISTER of LCD by making,


// rs=1 and en=1 to 0 edge AND sends 8 bit command to PORTB

void lcdval(unsigned char y)


{
rs=1;
ldata=y;
en=1;
delay(10);
en=0;
delay(10);
}

void delay(unsigned int X)


{
unsigned int i,j;
for(i=0;i<=X;i++)
{ for(j=0;j<20;j++)
{}
}
}

Mrs. Trupti Thite, TE ENTC Microcontroller Page 7


Q. 4 Explain PIC 18F Interfacing to Keypad

 The keypad is used as an input device to read the key pressed by the user and to process it.

 4x4 keypad consists of 4 rows and 4 columns. Switches are placed between the rows and columns. A
keypress establishes a connection between the corresponding row and column between which the switch
is placed.

 In order to read the key press, we need to configure the rows as outputs and columns as inputs.

 Columns are read after applying signals to the rows in order to determine whether or not a key is pressed
and if pressed, which key is pressed.

Interfacing Diagram

Algorithm:

1. Connect four column pins and four-row pins to the microcontroller port.
2. Define column pins as input and row pins as output

TRISD = 0XF0; /*TRISD register decides the direction of the PORT D pins.

1 for input and 0 for output */

3. Wait for a key press (initial scanning)


4. Make all the row pins high, then keep scanning the rows till a keypress get detected.

Mrs. Trupti Thite, TE ENTC Microcontroller Page 8


do {

PORTD = 0X0F; // Make Row pins high

column = PORTD; // Read column pin status: Read the port

column &= 0xF0; // Read column pin status: Extract column pin status from PortD

}while(column==0x00);

5. Repeat this procedure till a keypress event got detected


6. Detect and identify the pressed key and display on LCD

Q 5 Explain PIR Motion Sensor Interface with PIC18F4550

• PIR sensor detects infrared heat radiations.


• It can be used to detect the presence of living objects that emit infrared heat radiation.
• The PIR sensor is split into two slots.
• Whenever a stationary object is in front of the sensor, the two slots receive the same amount
of radiation and the output is zero.
• Whenever a moving object is in front of the sensor, one of the slots receives more radiation
than the other slot.
• This makes the output swing high or low.
• This change in output voltage is the result of the detection of motion.

PIR Sensor pin diagram

Mrs. Trupti Thite, TE ENTC Microcontroller Page 9


Mrs. Trupti Thite, TE ENTC Microcontroller Page 10
Q 6 Explain DAC with PIC18F4550
OR
Write C code to Generate sine waveform using DAC with PIC18F4550

Digital to analog Converter is widely used to convert digital pulses into analog signal.
Interfacing diagram for DAC and PIC 18 for sine wave generation is as shown below.

DAC 0808 COVERTS 8 BIT Digital value into current output, This current output is converted
into voltage by V-I Converter using Op-Amp.

Formula for generating sine wave using DAC is as follows,

Mrs. Trupti Thite, TE ENTC Microcontroller Page 11


Using Above formula we can create table as follows for the values to send to DAC from
PIC

Program:

#include<PIC18F4550.h>

Mrs. Trupti Thite, TE ENTC Microcontroller Page 12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy