Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

How to take input with PIC18F4550 Microcontroller- (Part 2/25)

By Ashutosh Bhatt

Any microcontroller based system typically has an input and a corresponding output. Taking simple output with a PIC microcontroller has been explained in LED blinking with PIC18F4550. This article explains how to provide an input to the controller and get a corresponding output using PIC18F4550.


 

 

PIC18F4550 has a total of 35 I/O (input-output) pins which are distributed among 5 Ports. Each Port of a PIC microcontroller corresponds to three 8-bit registers (TRIS, PORT & LAT) which should be configured to use the Port for general I/O purpose. For more details, refer LED blinking using PIC.

 
To configure a particular port/pin as input, the corresponding TRIS register/TRIS bit should be set to high (1). For output, the relevant TRIS register/bit should be set to low (0).
 
For example, for PortD
·         To set the entire PortD as input               
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
1
1
1
1
1
1
1
1
 Bit Configuration of TRISD Register with PortD as input in PIC18F4550
Fig. 2: Bit Configuration of TRISD Register with PortD as input in PIC18F4550
 
·         To set only 3rd pin (RD2) of PortD as input                    
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
–
–
–
–
–
1
–
–
 Bit Configuration of TRISD Register with 3rd pin RD2 of PortD as input in PIC18F4550
Fig. 3: Bit Configuration of TRISD Register with 3rd pin RD2 of PortD as input in PIC18F4550
 
·         To set  1st pin (RD0) as output and 4th pin (RD3) of PortD as input                   
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
–
–
–
–
1
–
–
0
 Bit Configuration of TRISD Register with 1st pin RD0 as output and 4th pin (RD3) of PortD as input in PIC18F4550
 Fig. 4: Bit Configuration of TRISD Register with 1st pin RD0 as output and 4th pin (RD3) of PortD as input in PIC18F4550
 
In this program, a tactile switch has been connected on pin RA5 of PortA to provide input to the microcontroller. The input is monitored as an output on LED connected to pin RA0. The connections are shown in the adjoining circuit diagram.

Project Source Code

###

// Program to control an LED using a switch

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on
*/

void main()
{
	ADCON1=0x0F;            // Set all pins as digital I/O
	CMCON=0x07;             // Set all comparators as digital I/O
	TRISA.RA0=0;            // Configure pin RA0 as output
	TRISA.RA5=1;            // Configure pin RA5 as input
	while(1)
	{
		if(PORTA.RA5)     	// If input is high
			LATA.LATA0=1;   // Turn the LED On
		else
			LATA.LATA0=0;   // Turn the LED Off
	}
}

###

 


Circuit Diagrams

Circuit-Diagram-of-How-to-take-input-with-PIC18F4550-Microcontroller

Project Components

  • LED
  • PIC18F4550

Project Video


Filed Under: PIC Microcontroller
Tagged With: display, led, microcontroller, pic18f4550, switch
 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)
  • An Embedded Developer’s Perspective on IOT (Internet of Things)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Need help to choose accelerometer
  • Pic 16f877A Hex file
  • 7 segment display connections
  • finding attenuation coefficient in CST
  • Effect of variable gain amplifier and LNA on the input RF signal's phase

RSS Electro-Tech-Online.com Discussions

  • How to designing a battery charging indicator circuit for 18650 battery pack
  • NOR gate oscillator in LTspice not working
  • ICM7555 IC duty cycle limit at high frequency?
  • I've DESTROYED 3 piezo buttons :((((
  • led doorbell switch
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering