Aim:
It is necessary to understand basic I/O operations of PIC18F4520 before dealing with its complexities. This article presents a way to take simple input from a PIC microcontroller. This learning would also help in interfacing of external devices with the controller. Here theinput from the microcontroller is taken on a set of switch.
Description:
Fig. 1 shows how to interface the switch to microcontroller. A simple switch has an open state and closed state. However, a microcontroller needs to see a definite high or low voltage level at a digital input. A switch requires a pull-up or pull-down resistor to produce a definite high or low voltage when it is open or closed. A resistor placed between a digital input and the supply voltage is called a “pull-up” resistor because it normally pulls the pin’s voltage up to the supply.
Fig. 1 Interfacing switch to Microcontroller
We now want to control the LED by using switches in PIC Development board. It works by turning ON a LED & then turning it OFF when switch is going to LOW or HIGH
Block Diagram
Schematic
Code
// **************************************************** // Project: Interfacing single switch to PIC18F4520 // Author: Hack Projects India // Module description: Operate array of LED's // **************************************************** #include<p18f452.h> #pragma config OSC=HS, FCMEN=ON, WDT=OFF, IESO=OFF, XINST=OFF, LVP=OFF #define SWITCH PORTCbits.RC0 #define LED PORTBbits.RB0 int main(void) { ADCON1=0xF0; TRISB=0x00; TRISC=0X0F; while(1) { if(SWITCH) { LED=1; } else { LED=0; } } }
Downloads:
The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.
Further Reading suggestions:
You may also like,
- Interfacing keypad with PIC
- nterfacing DAC with PIC
- Interfacing with UART of PIC controller
- Interfacing SPI communication with PIC
- PIC Displaying Custom Characters on LCD
- PIC Graphical LCD
- RTC interfacing using I2C in PIC
- Interfacing ultrasonic sensor with PIC
- Interfacing GPS Modu with PIC
- Interfacing GSM Module with PIC
- Interfacing PWM in PIC
- Interfacing ADC with PIC
- Scrolling string on LCD using PIC
- Interfacing keypad with PIC
- nterfacing DAC with PIC
- Interfacing with UART of PIC controller
- Interfacing SPI communication with PIC
- PIC Displaying Custom Characters on LCD
- PIC Graphical LCD
- RTC interfacing using I2C in PIC
- Interfacing ultrasonic sensor with PIC
- Interfacing GPS Modu with PIC
- Interfacing GSM Module with PIC
- Interfacing PWM in PIC
- Interfacing ADC with PIC
- Scrolling string on LCD using PIC
No comments:
Post a Comment