Micro Unit 5 Question Answers Notes
Micro Unit 5 Question Answers Notes
• PIC18FXX microcontroller has a number of input/output pins which are used for
connection with external devices. Called as ports.
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.
Or
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
Interfacing Diagram
#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
}
}
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.
Algorithm
#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
lcdval('W');
lcdval('e');
lcdval('l');
lcdval('c);
lcdval('o');
lcdval('m);
lcdval('e’);
while(1);
}
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.
column &= 0xF0; // Read column pin status: Extract column pin status from PortD
}while(column==0x00);
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.
Program:
#include<PIC18F4550.h>