Interfacing Switch with PIC32

Dear Readers,

In this article, I would like to explain how to interface switch with PIC32. Here I’ve used P32M5795F512L as uC, and interfaced switch to PortA.0. Given LCD as an O/P device, and connected as shown below:


Software Program:

Target: Interfacing Switch Button to PORTA.0
Programmer: MAD

// Lcd module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End Lcd module connections

void main() {

TRISA=1; // Interfaced Switch to PortA.0
AD1PCFG  = 0xFFFF; // Configure AN pins as digital I/O
JTAGEN_bit = 0;                // Disable JTAG port



if (Button(&PORTA, 0, 1, 0))
while((Button(&PORTA, 0, 1, 0)));
Lcd_Out_Cp(“Button Pressed”);
goto saha;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s