SlideShare a Scribd company logo
1
CHAPTER 3: INPUT OUTPUT PORTS PROGRAMMING
Outcomes
At the end of this chapter, you will be able to:
1. Identify input and output (I/O) pins and their function
2. Explain dual role ports of data I/O
3.1 I/O Ports pins and their function
PIC18F4550 belongs to pic18f family of microcontrollers from the microchip technology.
Examine Figure 3.1 for the PIC18F4550 40-pin chip. A total of 35 pins are Input-Output
pins which can be configured for general Input or Output by setting registers associated
with them. The rest of the pins are designated as Vdd (Vcc), Vss (GND), OSC1, OSC2,
MCLR (reset) and another set of Vdd and Vss.
Figure 3.1: PIC18F4550’s pin out diagram
The PIC18F4550 has 5 ports. They are PORTA, PORTB, PORTC, PORTD and
PORTE. Not all port has 8 pin. Table 3.1 shows the number of pin and pin name of the
port.
2
Table 3.1: Number of pin and pin name
Ports Number of pins Pin Name
PORTA 7 RA0-RA6
PORTB 8 RB0-RB7
PORTC 7 RC0-RC2, RC4-RC7 (Check the Pinout Diagram)
PORTD 8 RD0-RD7
PORTE 4 RE0-RE3
3.2 Dual role ports of data I/O
For practical reasons, many I/O pins have two or three functions.
1. used as a general purpose input/output pin;
2. alternate function - can be seeing next after symbol “/” .
Figure 3.2
Example 3.1:
I/O pin name: RA0/AN0
RA0 – used as digital I/O
AN0 - alternate function (used as input for analog-to-digital converter channel 0)
3
3.2.1 Port A
Port A is an 8-bit wide, bidirectional port. All Port A pins act as digital inputs/outputs.
Five of them can also be analog inputs (denoted as AN):
Because many projects use an ADC, we do not use Port A for simple I/O functions.
Table 3.1: PORTA I/O SUMMARY
4
Table 3.2: Port A alternate function
Bit Alternate Function
RA0 AN0
RA1 AN1
RA2 AN2/VREF-
RA3 AN3/VREF+
RA4 T0CK1
RA5 AN4/SS/LVDIN
RA6 OSC2/CLKO
3.2.2 Port B
Port B is an 8-bit wide, bidirectional port.. Six pins on this port can act as analog inputs
(AN).
Table 3.3: Port B alternate function
Bit Alternate Function
RB0 INT0
RB1 INT1
RB2 INT2/CANTX
RB3 CANRX
RB4
RB5 PGM
RB6 PGC
RB7 PGD
5
3.2.3 Port C
Port C is an 8-bit wide, bidirectional port.
Table 3.4: Port C alternate function
Bit Function
RC0 T1OS0/T1CK1
RC1 T1OS1
RC2 CCP1
RC3 SCK/SCL
RC4 SDI/SDA
RC5 SDO
RC6 TX/CK
RC7 RX/DT
3.2.4 Port D
Port D is an 8-bit wide, bidirectional port.
Table 3.4: Port D alternate function
Bit Alternate Function
RD0 PSP0/C1IN+
RD1 PSP1/C1IN-
RD2 PSP2/C2IN+
RD3 PSP3/C1IN-
RD4 PSP4/ECCP1/PIA
RD5 PSP5/P1B
RD6 PSP6/P1C
RD7 PSP7/P1D
6
3.2.5 Port E
Port E is a 4-bit wide, bidirectional port. Similar to Ports A and B, three pins can be
configured as analog inputs in this case. The ANSELH register bits determine whether a
pin will act as analog input (AN) or digital input/output:
Three pins (RE0/AN5/CK1SPP, RE1/AN6/CK2SPP and RE2/AN7/OESPP) are
individually configurable as inputs or outputs.
On a Power-on Reset, RE3 is enabled as a digital input only if Master Clear functionality
is disabled
Table 3.5: Port E alternate function
Bit Alternate Function
RE0 AN5/CK1SPP
RE1 RE1/AN6/CK2SPP
RE2 RE2/AN7/OESPP)
RE3 MCLR/VPP/RE3
Activity 3.1:
Name ONE (1)of PIC18 I/O pin and identify how that pin used in I/O control.
____________________________________________________________________
Review question
1. There are a total of _____ ports in the PIC18f4550.
2. True or false. All of the PIC18F4550 ports have 8 pins.
3. List all ports that have 8 pins.
___________________________________________________________________
7
3.3 Code PIC instruction for I/O handling
To use any of I/O ports as an input or output port, it must be programmed.
Each port in pic18f4450 is associated with three 8 bit registers for IO operations.
1. TRISx (8 bit)
2. PORTx (8 bit)
3. LATx (8 bit)
3.3.1 TRISX:
TRISX: where X is the name of the ports either of A, B, C, D, E.
Every port has its own TRISX register, thus there are 5 TRISXs to be configured:
a. TRISA
b. TRISB
c. TRISC
d. TRISD
e. TRISE
Data direction (TRIS) register needs to be set before the I/O operation
 1  to make a port an input
 0  to make a port an output
After a Reset all port pins are defined as inputs
3.3.2 PORT X
PORT X : Reads the device level, stores the Input level of the pins and reads the input
signal from the external device if the pin is configured as Input.
3.3.3 LAT X
LAT X: The latch registers reads and modifies the write operation on the value of I/O
pin and stored the output data that is to be passed on to the external hardware.
A write to the LATx register has the same effect as a write to the PORTx register.
8
3.2.1 TRIS register role in inputting and outputting data
By clearing some bit of the TRIS register (bit=0), the corresponding port pin is
configured as output. Similarly, by setting some bit of the TRIS register (bit=1), the
corresponding port pin is configured as input.
This rule is easy to remember 0 = Output, 1 = Input.
Example 3.2
Determine the value of TRIS register for the following circuit .
Figure 3.3
Solution:
Step 1: Analyze I/O pin:-
INPUT: Pin 2 and pin 4 of I/O port
OUTPUT: Pin 6 and pin 7 of I/O port
Step 2:
Set Bit 2 and Bit 4 of TRIS register
Clear Bit 6 and Bit 7 of TRIS register
The value of TRIS register in binary is 00110101.
If the external circuit is connected to Port D, we will write TRISD=0b00110101;
9
.
Example 3.3:
Write C program statement to initialize I/O port for the following diagram.
Figure 3.4
Solution:
INPUT: RB3, RB4, RB6 and RB7
OUTPUT: RB0-RB2, and RB5
TRISB = 0b11011000;
Example 3.4
Write C statement to make Port B of PIC18F4550 become output.
Solution:
To make these port serves as Output, we need to put 0’s bit in the register TRISB0 to
TRISB7. The answer is:
TRISB = 0b00000000;
____________________________________________________________________
Activity 3.2
1. True or false. Upon power-up, the I/O pins are configured as output ports.
10
2. To make Port B an output, we must place __ in register _________.
3. To make Port B an input port, we must place ___ in register __________.
4. Write the I/O initialization for the following situation:
i. SW1 connected to RB1 and LED1 connected to RD2.
ii. Light sensor connected to RC0 and lamp connected to RC3.
______________________________________________________________________
3.4 I/O Port and bit addressability
All PIC18 register is 8 bit size. We will access the register either:
1. all 8 bits - byte addressable
2. any single bit without altering the rest. – bit addressable
Access register by bit:
NAMEbitx = 1/0;
e.g.
RB5 = 1; //Set bit 5 of Port B
Access register by byte:
NAME= 0bxxxxxxxx;
e.g.
PORTB= 0b00001111; //Send binary 00001111 to Port B.
Example 3.5 :
Write a program statement to set bit5 of Port B to logic HIGH by:
a. Bit
b. Byte
11
Solution:
a. By bit:
RB5 = 1; //Set bit 5 of Port B
b. By byte:
PORTB= 0b00100000; //Send logic HIGH to pin 5 of Port B.
Activity 3.3:
Refer the following table to write a program statement to access LATC and TRISC by:
a. Bit
b. Byte
12
Activity 3.4:
Refer the following table to write a program statement to access PORTD and LATD by:
a. Bit
b. Byte
13
Hardware connections (Extra notes)
Output
For the purpose of interfacing the PIC, we can consider a 'high' output to be 5V, and a
low output to be 0V. If you check the PIC datasheets, you will find that the output pins
can actually 'sink' or 'source' a reasonable amount of current - about 25mA or so.
'Sink' means that the chip 'sinks' current down into itself, so the load is connected from
the positive rail to the I/O pin and the load is switched ON by the pin going 'low'.
'Source' is just the reverse, the I/O pin is the actual source of the current, and it flows
out of the pin, through the load down to ground - in this case the load is switched ON by
the pin going 'high'.
Connecting the LED without a resistor is likely to damage both the LED and the PIC.
The two examples below show how to connect an LED in either 'sink' or 'source' modes
Sink mode example
This is how to connect an LED for the PIC to SINK current. The LED will light when the
PIC pin is low.
14
Source mode example
This is how to connect an LED for the PIC to SOURCE current. The LED will light when
the PIC pin is high
Inputs
Inputs to a PIC have the same 5V logic requirements, so the inputs can be active
'high' or active 'low'. Basically this is just a variation on the same theme - but, depending
on the actual input device, you may be forced to use a particular method.
Active LOW input
'Active LOW':The resistor R1 'pulls' the PIC input high (logic '1') - when you press the
switch it pulls the voltage down to zero, changing the input to logic '0'.
15
Active HIGH input
The 'Active HIGH' example works in the opposite way, R2 is a 'pull down' resistor,
holding the PIC input at logic '0', pressing the switch connects the PIC input to the 5V
rail, forcing it to logic '1'.
Example 3..5
A control system consist of a PIC microcontroller, 2 switches (active LOW) and one
LED (active HIGH). Switch 1 is connected to pin RA3 and switch 2 connected to pin
RB0. One LED connected to RC1.
a. Draw a circuit diagram for the system.
b. Write I/O pin initialization for the system
c. Write a program statement to linght on the LED
16
Solution
a.
b. TRISA3=1;
TRISB0=1;
TRISC1=0;
c. RC1=1;
References
http://www.matrixmultimedia.com/wiki/index.php?title=Component:_Switch_base
_(Inputs)
http://www.winpicprog.co.uk/pic_tutorial_extras.htm

More Related Content

What's hot

ALAT – ALAT PENGUKUR ELEKTRIK.ppt
ALAT – ALAT PENGUKUR ELEKTRIK.pptALAT – ALAT PENGUKUR ELEKTRIK.ppt
ALAT – ALAT PENGUKUR ELEKTRIK.ppt
OmiKong1
 
Ujian Rintangan Penebatan
Ujian Rintangan PenebatanUjian Rintangan Penebatan
Ujian Rintangan Penebatanshrim shaharin
 
Kertas penerangan peralatan tangan
Kertas penerangan  peralatan tanganKertas penerangan  peralatan tangan
Kertas penerangan peralatan tangan
suhaimiawe12
 
Buku papan suis utama
Buku papan suis utama Buku papan suis utama
Buku papan suis utama
Ezuan Atok
 
elektronik tingkatan 2
elektronik tingkatan 2elektronik tingkatan 2
elektronik tingkatan 2Ziana J
 
Litar bekalan kuasa
Litar bekalan kuasaLitar bekalan kuasa
Litar bekalan kuasa
Mohamad Husni Ramli
 
fungsi-komponen dalam litar
fungsi-komponen dalam litarfungsi-komponen dalam litar
fungsi-komponen dalam litar
Herney Aqilah Kay
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)Ikhwan_Fakrudin
 
Bab 3 : Penamatan kabel Rangkaian
Bab 3 : Penamatan kabel RangkaianBab 3 : Penamatan kabel Rangkaian
Bab 3 : Penamatan kabel Rangkaian
Zulhana Zulkifle
 
E4120 penyelenggaraan & baik pulih alat elektronik
E4120 penyelenggaraan & baik pulih alat elektronikE4120 penyelenggaraan & baik pulih alat elektronik
E4120 penyelenggaraan & baik pulih alat elektronik
saifuladlihjyusoff
 
Pdf pengujian-elektrik
Pdf pengujian-elektrikPdf pengujian-elektrik
Pdf pengujian-elektrik
AgusKurniawan117
 
Automation
AutomationAutomation
Automation
FadilAdli
 
motor dc
motor dcmotor dc
soldering @ pematerian
soldering @ pemateriansoldering @ pematerian
soldering @ pematerianfadhilibrahim
 
Omron ladder programming
Omron ladder programmingOmron ladder programming
Omron ladder programming
Suzaini Supingat
 

What's hot (20)

ALAT – ALAT PENGUKUR ELEKTRIK.ppt
ALAT – ALAT PENGUKUR ELEKTRIK.pptALAT – ALAT PENGUKUR ELEKTRIK.ppt
ALAT – ALAT PENGUKUR ELEKTRIK.ppt
 
Ujian Rintangan Penebatan
Ujian Rintangan PenebatanUjian Rintangan Penebatan
Ujian Rintangan Penebatan
 
Kertas penerangan peralatan tangan
Kertas penerangan  peralatan tanganKertas penerangan  peralatan tangan
Kertas penerangan peralatan tangan
 
Buku papan suis utama
Buku papan suis utama Buku papan suis utama
Buku papan suis utama
 
Lab pneumatic
Lab pneumatic Lab pneumatic
Lab pneumatic
 
8.1 multimeter
8.1 multimeter8.1 multimeter
8.1 multimeter
 
elektronik tingkatan 2
elektronik tingkatan 2elektronik tingkatan 2
elektronik tingkatan 2
 
Litar bekalan kuasa
Litar bekalan kuasaLitar bekalan kuasa
Litar bekalan kuasa
 
fungsi-komponen dalam litar
fungsi-komponen dalam litarfungsi-komponen dalam litar
fungsi-komponen dalam litar
 
Embedded system (Chapter 1)
Embedded system (Chapter 1)Embedded system (Chapter 1)
Embedded system (Chapter 1)
 
Bab 3 : Penamatan kabel Rangkaian
Bab 3 : Penamatan kabel RangkaianBab 3 : Penamatan kabel Rangkaian
Bab 3 : Penamatan kabel Rangkaian
 
Litar pengguna
Litar penggunaLitar pengguna
Litar pengguna
 
E4120 penyelenggaraan & baik pulih alat elektronik
E4120 penyelenggaraan & baik pulih alat elektronikE4120 penyelenggaraan & baik pulih alat elektronik
E4120 penyelenggaraan & baik pulih alat elektronik
 
Jenis2 pghidup
Jenis2 pghidupJenis2 pghidup
Jenis2 pghidup
 
Pdf pengujian-elektrik
Pdf pengujian-elektrikPdf pengujian-elektrik
Pdf pengujian-elektrik
 
Automation
AutomationAutomation
Automation
 
motor dc
motor dcmotor dc
motor dc
 
soldering @ pematerian
soldering @ pemateriansoldering @ pematerian
soldering @ pematerian
 
Omron ladder programming
Omron ladder programmingOmron ladder programming
Omron ladder programming
 
Pemasangan elektrik
Pemasangan elektrikPemasangan elektrik
Pemasangan elektrik
 

Viewers also liked

Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )Ikhwan_Fakrudin
 
CMOS Topic 3 -_the_device
CMOS Topic 3 -_the_deviceCMOS Topic 3 -_the_device
CMOS Topic 3 -_the_device
Ikhwan_Fakrudin
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part AIkhwan_Fakrudin
 
Isi kandungan (latihan industri)
Isi kandungan (latihan industri)Isi kandungan (latihan industri)
Isi kandungan (latihan industri)
Ikhwan_Fakrudin
 
CMOS Topic 7 -_design_methodology
CMOS Topic 7 -_design_methodologyCMOS Topic 7 -_design_methodology
CMOS Topic 7 -_design_methodology
Ikhwan_Fakrudin
 
Panduan menulis report akhir
Panduan menulis report akhirPanduan menulis report akhir
Panduan menulis report akhir
Ikhwan_Fakrudin
 
Introduction to Embedded Systems and its Applications
Introduction to Embedded Systems and its ApplicationsIntroduction to Embedded Systems and its Applications
Introduction to Embedded Systems and its Applications
Gaurav Verma
 
CMOS Topic 5 -_cmos_inverter
CMOS Topic 5 -_cmos_inverterCMOS Topic 5 -_cmos_inverter
CMOS Topic 5 -_cmos_inverter
Ikhwan_Fakrudin
 
CMOS Topic 4 -_the_wire
CMOS Topic 4 -_the_wireCMOS Topic 4 -_the_wire
CMOS Topic 4 -_the_wire
Ikhwan_Fakrudin
 
Introduction To Embedded Systems
Introduction To Embedded SystemsIntroduction To Embedded Systems
Introduction To Embedded Systemsanishgoel
 
report latihan industri politeknik ( Bab 1 )
report latihan industri politeknik ( Bab 1 )report latihan industri politeknik ( Bab 1 )
report latihan industri politeknik ( Bab 1 )
Ikhwan_Fakrudin
 
CMOS Topic 6 -_designing_combinational_logic_circuits
CMOS Topic 6 -_designing_combinational_logic_circuitsCMOS Topic 6 -_designing_combinational_logic_circuits
CMOS Topic 6 -_designing_combinational_logic_circuits
Ikhwan_Fakrudin
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Ikhwan_Fakrudin
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Ikhwan_Fakrudin
 
CMOS Topic 2 -manufacturing_process
CMOS Topic 2 -manufacturing_processCMOS Topic 2 -manufacturing_process
CMOS Topic 2 -manufacturing_process
Ikhwan_Fakrudin
 
INTRODUCTION_TO_IC
INTRODUCTION_TO_ICINTRODUCTION_TO_IC
INTRODUCTION_TO_IC
Ikhwan_Fakrudin
 

Viewers also liked (18)

Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
 
Pengakuan
PengakuanPengakuan
Pengakuan
 
CMOS Topic 3 -_the_device
CMOS Topic 3 -_the_deviceCMOS Topic 3 -_the_device
CMOS Topic 3 -_the_device
 
Embedded system (Chapter 2) part A
Embedded system (Chapter 2) part AEmbedded system (Chapter 2) part A
Embedded system (Chapter 2) part A
 
Isi kandungan (latihan industri)
Isi kandungan (latihan industri)Isi kandungan (latihan industri)
Isi kandungan (latihan industri)
 
CMOS Topic 7 -_design_methodology
CMOS Topic 7 -_design_methodologyCMOS Topic 7 -_design_methodology
CMOS Topic 7 -_design_methodology
 
Panduan menulis report akhir
Panduan menulis report akhirPanduan menulis report akhir
Panduan menulis report akhir
 
Introduction to Embedded Systems and its Applications
Introduction to Embedded Systems and its ApplicationsIntroduction to Embedded Systems and its Applications
Introduction to Embedded Systems and its Applications
 
CMOS Topic 5 -_cmos_inverter
CMOS Topic 5 -_cmos_inverterCMOS Topic 5 -_cmos_inverter
CMOS Topic 5 -_cmos_inverter
 
CMOS Topic 4 -_the_wire
CMOS Topic 4 -_the_wireCMOS Topic 4 -_the_wire
CMOS Topic 4 -_the_wire
 
Introduction To Embedded Systems
Introduction To Embedded SystemsIntroduction To Embedded Systems
Introduction To Embedded Systems
 
report latihan industri politeknik ( Bab 1 )
report latihan industri politeknik ( Bab 1 )report latihan industri politeknik ( Bab 1 )
report latihan industri politeknik ( Bab 1 )
 
CMOS Topic 6 -_designing_combinational_logic_circuits
CMOS Topic 6 -_designing_combinational_logic_circuitsCMOS Topic 6 -_designing_combinational_logic_circuits
CMOS Topic 6 -_designing_combinational_logic_circuits
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 
Report latihan industri
Report latihan industriReport latihan industri
Report latihan industri
 
CMOS Topic 2 -manufacturing_process
CMOS Topic 2 -manufacturing_processCMOS Topic 2 -manufacturing_process
CMOS Topic 2 -manufacturing_process
 
INTRODUCTION_TO_IC
INTRODUCTION_TO_ICINTRODUCTION_TO_IC
INTRODUCTION_TO_IC
 

Similar to Embedded system (Chapter 3) io_port_programming

8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
Monica Gunjal
 
unit-3-8255.pdf
unit-3-8255.pdfunit-3-8255.pdf
unit-3-8255.pdf
ShanmukhSaiR
 
74LS47 / DM74LS47 Datasheet PDF
74LS47 / DM74LS47 Datasheet PDF74LS47 / DM74LS47 Datasheet PDF
74LS47 / DM74LS47 Datasheet PDF
Datasheet
 
Io (2)
Io (2)Io (2)
Io (2)Aisu
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
Srikrishna Thota
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
nanocdac
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
deval patel
 
Programmable peripheral interface 8255
Programmable peripheral interface 8255Programmable peripheral interface 8255
Programmable peripheral interface 8255
Marajulislam3
 
Mod-2 M&M.pptx
Mod-2 M&M.pptxMod-2 M&M.pptx
Mod-2 M&M.pptx
TechCook1
 
8255 ppi
8255 ppi8255 ppi
8255 ppi
Suraj Bora
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
deval patel
 
2.instrumentation ii
2.instrumentation ii2.instrumentation ii
2.instrumentation ii
Bikash Gyawali
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
Neelam Kapoor
 
8255 presentaion.ppt
8255 presentaion.ppt8255 presentaion.ppt
8255 presentaion.ppt
kamlesh deshmukh
 
1.ppi 8255
1.ppi 8255 1.ppi 8255
1.ppi 8255
MdFazleRabbi18
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5PRADEEP
 
26. 8255 control word programming
26. 8255 control word programming26. 8255 control word programming
26. 8255 control word programming
sandip das
 
1203 Ppi 8155
1203 Ppi 81551203 Ppi 8155
1203 Ppi 8155
techbed
 

Similar to Embedded system (Chapter 3) io_port_programming (20)

8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
 
unit-3-8255.pdf
unit-3-8255.pdfunit-3-8255.pdf
unit-3-8255.pdf
 
74LS47 / DM74LS47 Datasheet PDF
74LS47 / DM74LS47 Datasheet PDF74LS47 / DM74LS47 Datasheet PDF
74LS47 / DM74LS47 Datasheet PDF
 
Io (2)
Io (2)Io (2)
Io (2)
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
 
Programmable peripheral interface 8255
Programmable peripheral interface 8255Programmable peripheral interface 8255
Programmable peripheral interface 8255
 
Mod-2 M&M.pptx
Mod-2 M&M.pptxMod-2 M&M.pptx
Mod-2 M&M.pptx
 
8255 ppi
8255 ppi8255 ppi
8255 ppi
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
2.instrumentation ii
2.instrumentation ii2.instrumentation ii
2.instrumentation ii
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
 
8255 presentaion.ppt
8255 presentaion.ppt8255 presentaion.ppt
8255 presentaion.ppt
 
1.ppi 8255
1.ppi 8255 1.ppi 8255
1.ppi 8255
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
 
26. 8255 control word programming
26. 8255 control word programming26. 8255 control word programming
26. 8255 control word programming
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
1203 Ppi 8155
1203 Ppi 81551203 Ppi 8155
1203 Ppi 8155
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

Embedded system (Chapter 3) io_port_programming

  • 1. 1 CHAPTER 3: INPUT OUTPUT PORTS PROGRAMMING Outcomes At the end of this chapter, you will be able to: 1. Identify input and output (I/O) pins and their function 2. Explain dual role ports of data I/O 3.1 I/O Ports pins and their function PIC18F4550 belongs to pic18f family of microcontrollers from the microchip technology. Examine Figure 3.1 for the PIC18F4550 40-pin chip. A total of 35 pins are Input-Output pins which can be configured for general Input or Output by setting registers associated with them. The rest of the pins are designated as Vdd (Vcc), Vss (GND), OSC1, OSC2, MCLR (reset) and another set of Vdd and Vss. Figure 3.1: PIC18F4550’s pin out diagram The PIC18F4550 has 5 ports. They are PORTA, PORTB, PORTC, PORTD and PORTE. Not all port has 8 pin. Table 3.1 shows the number of pin and pin name of the port.
  • 2. 2 Table 3.1: Number of pin and pin name Ports Number of pins Pin Name PORTA 7 RA0-RA6 PORTB 8 RB0-RB7 PORTC 7 RC0-RC2, RC4-RC7 (Check the Pinout Diagram) PORTD 8 RD0-RD7 PORTE 4 RE0-RE3 3.2 Dual role ports of data I/O For practical reasons, many I/O pins have two or three functions. 1. used as a general purpose input/output pin; 2. alternate function - can be seeing next after symbol “/” . Figure 3.2 Example 3.1: I/O pin name: RA0/AN0 RA0 – used as digital I/O AN0 - alternate function (used as input for analog-to-digital converter channel 0)
  • 3. 3 3.2.1 Port A Port A is an 8-bit wide, bidirectional port. All Port A pins act as digital inputs/outputs. Five of them can also be analog inputs (denoted as AN): Because many projects use an ADC, we do not use Port A for simple I/O functions. Table 3.1: PORTA I/O SUMMARY
  • 4. 4 Table 3.2: Port A alternate function Bit Alternate Function RA0 AN0 RA1 AN1 RA2 AN2/VREF- RA3 AN3/VREF+ RA4 T0CK1 RA5 AN4/SS/LVDIN RA6 OSC2/CLKO 3.2.2 Port B Port B is an 8-bit wide, bidirectional port.. Six pins on this port can act as analog inputs (AN). Table 3.3: Port B alternate function Bit Alternate Function RB0 INT0 RB1 INT1 RB2 INT2/CANTX RB3 CANRX RB4 RB5 PGM RB6 PGC RB7 PGD
  • 5. 5 3.2.3 Port C Port C is an 8-bit wide, bidirectional port. Table 3.4: Port C alternate function Bit Function RC0 T1OS0/T1CK1 RC1 T1OS1 RC2 CCP1 RC3 SCK/SCL RC4 SDI/SDA RC5 SDO RC6 TX/CK RC7 RX/DT 3.2.4 Port D Port D is an 8-bit wide, bidirectional port. Table 3.4: Port D alternate function Bit Alternate Function RD0 PSP0/C1IN+ RD1 PSP1/C1IN- RD2 PSP2/C2IN+ RD3 PSP3/C1IN- RD4 PSP4/ECCP1/PIA RD5 PSP5/P1B RD6 PSP6/P1C RD7 PSP7/P1D
  • 6. 6 3.2.5 Port E Port E is a 4-bit wide, bidirectional port. Similar to Ports A and B, three pins can be configured as analog inputs in this case. The ANSELH register bits determine whether a pin will act as analog input (AN) or digital input/output: Three pins (RE0/AN5/CK1SPP, RE1/AN6/CK2SPP and RE2/AN7/OESPP) are individually configurable as inputs or outputs. On a Power-on Reset, RE3 is enabled as a digital input only if Master Clear functionality is disabled Table 3.5: Port E alternate function Bit Alternate Function RE0 AN5/CK1SPP RE1 RE1/AN6/CK2SPP RE2 RE2/AN7/OESPP) RE3 MCLR/VPP/RE3 Activity 3.1: Name ONE (1)of PIC18 I/O pin and identify how that pin used in I/O control. ____________________________________________________________________ Review question 1. There are a total of _____ ports in the PIC18f4550. 2. True or false. All of the PIC18F4550 ports have 8 pins. 3. List all ports that have 8 pins. ___________________________________________________________________
  • 7. 7 3.3 Code PIC instruction for I/O handling To use any of I/O ports as an input or output port, it must be programmed. Each port in pic18f4450 is associated with three 8 bit registers for IO operations. 1. TRISx (8 bit) 2. PORTx (8 bit) 3. LATx (8 bit) 3.3.1 TRISX: TRISX: where X is the name of the ports either of A, B, C, D, E. Every port has its own TRISX register, thus there are 5 TRISXs to be configured: a. TRISA b. TRISB c. TRISC d. TRISD e. TRISE Data direction (TRIS) register needs to be set before the I/O operation  1  to make a port an input  0  to make a port an output After a Reset all port pins are defined as inputs 3.3.2 PORT X PORT X : Reads the device level, stores the Input level of the pins and reads the input signal from the external device if the pin is configured as Input. 3.3.3 LAT X LAT X: The latch registers reads and modifies the write operation on the value of I/O pin and stored the output data that is to be passed on to the external hardware. A write to the LATx register has the same effect as a write to the PORTx register.
  • 8. 8 3.2.1 TRIS register role in inputting and outputting data By clearing some bit of the TRIS register (bit=0), the corresponding port pin is configured as output. Similarly, by setting some bit of the TRIS register (bit=1), the corresponding port pin is configured as input. This rule is easy to remember 0 = Output, 1 = Input. Example 3.2 Determine the value of TRIS register for the following circuit . Figure 3.3 Solution: Step 1: Analyze I/O pin:- INPUT: Pin 2 and pin 4 of I/O port OUTPUT: Pin 6 and pin 7 of I/O port Step 2: Set Bit 2 and Bit 4 of TRIS register Clear Bit 6 and Bit 7 of TRIS register The value of TRIS register in binary is 00110101. If the external circuit is connected to Port D, we will write TRISD=0b00110101;
  • 9. 9 . Example 3.3: Write C program statement to initialize I/O port for the following diagram. Figure 3.4 Solution: INPUT: RB3, RB4, RB6 and RB7 OUTPUT: RB0-RB2, and RB5 TRISB = 0b11011000; Example 3.4 Write C statement to make Port B of PIC18F4550 become output. Solution: To make these port serves as Output, we need to put 0’s bit in the register TRISB0 to TRISB7. The answer is: TRISB = 0b00000000; ____________________________________________________________________ Activity 3.2 1. True or false. Upon power-up, the I/O pins are configured as output ports.
  • 10. 10 2. To make Port B an output, we must place __ in register _________. 3. To make Port B an input port, we must place ___ in register __________. 4. Write the I/O initialization for the following situation: i. SW1 connected to RB1 and LED1 connected to RD2. ii. Light sensor connected to RC0 and lamp connected to RC3. ______________________________________________________________________ 3.4 I/O Port and bit addressability All PIC18 register is 8 bit size. We will access the register either: 1. all 8 bits - byte addressable 2. any single bit without altering the rest. – bit addressable Access register by bit: NAMEbitx = 1/0; e.g. RB5 = 1; //Set bit 5 of Port B Access register by byte: NAME= 0bxxxxxxxx; e.g. PORTB= 0b00001111; //Send binary 00001111 to Port B. Example 3.5 : Write a program statement to set bit5 of Port B to logic HIGH by: a. Bit b. Byte
  • 11. 11 Solution: a. By bit: RB5 = 1; //Set bit 5 of Port B b. By byte: PORTB= 0b00100000; //Send logic HIGH to pin 5 of Port B. Activity 3.3: Refer the following table to write a program statement to access LATC and TRISC by: a. Bit b. Byte
  • 12. 12 Activity 3.4: Refer the following table to write a program statement to access PORTD and LATD by: a. Bit b. Byte
  • 13. 13 Hardware connections (Extra notes) Output For the purpose of interfacing the PIC, we can consider a 'high' output to be 5V, and a low output to be 0V. If you check the PIC datasheets, you will find that the output pins can actually 'sink' or 'source' a reasonable amount of current - about 25mA or so. 'Sink' means that the chip 'sinks' current down into itself, so the load is connected from the positive rail to the I/O pin and the load is switched ON by the pin going 'low'. 'Source' is just the reverse, the I/O pin is the actual source of the current, and it flows out of the pin, through the load down to ground - in this case the load is switched ON by the pin going 'high'. Connecting the LED without a resistor is likely to damage both the LED and the PIC. The two examples below show how to connect an LED in either 'sink' or 'source' modes Sink mode example This is how to connect an LED for the PIC to SINK current. The LED will light when the PIC pin is low.
  • 14. 14 Source mode example This is how to connect an LED for the PIC to SOURCE current. The LED will light when the PIC pin is high Inputs Inputs to a PIC have the same 5V logic requirements, so the inputs can be active 'high' or active 'low'. Basically this is just a variation on the same theme - but, depending on the actual input device, you may be forced to use a particular method. Active LOW input 'Active LOW':The resistor R1 'pulls' the PIC input high (logic '1') - when you press the switch it pulls the voltage down to zero, changing the input to logic '0'.
  • 15. 15 Active HIGH input The 'Active HIGH' example works in the opposite way, R2 is a 'pull down' resistor, holding the PIC input at logic '0', pressing the switch connects the PIC input to the 5V rail, forcing it to logic '1'. Example 3..5 A control system consist of a PIC microcontroller, 2 switches (active LOW) and one LED (active HIGH). Switch 1 is connected to pin RA3 and switch 2 connected to pin RB0. One LED connected to RC1. a. Draw a circuit diagram for the system. b. Write I/O pin initialization for the system c. Write a program statement to linght on the LED