Sie sind auf Seite 1von 25

1.

LED interfacing with PIC Microcontroller

Aim:

To interface two LEDs with PIC microcontroller and to make it blink


alternately.

Software Required:

PROTEUS Simulator &

MPLAB Assembler

Procedure:

1. Prepare the hardware circuit in PROTEUS, by placing the devices required


and making the appropriate connections between them.
2. Write the embedded C program to turn on the two LEDs alternately with the
help of PIC microcontroller.
3. Assemble the embedded C program in to its equivalent .hex program, with
the help of MPLAB software.
4. Link the assembled .hex program to the hardware circuit prepared in
PROTEUS.
5. Execute and verify the result in PROTEUS.
Circuit Diagram:
Program:

#include<htc.h>

#include<stdio.h>

__CONFIG(0x3f32);

void main()

TRISC = 0x00;

PORTC = 0x06;

while(1)

RC1 = 0;

RC2 = 1;

_delay(250);

RC1 = 1;

RC2 = 0;

_delay(250);

}
Output:

Result:

Thus, the embedded program for LED interfacing with PIC microcontroller
is executed and the result is verified.
2. LCD interfacing with PIC Microcontroller

Aim:

To interface LCD with PIC microcontroller and to display the required


strings on LCD.

Software Required:

PROTEUS Simulator &

MPLAB Assembler

Procedure:

1. Prepare the hardware circuit in PROTEUS, by placing the devices required


and making the appropriate connections between them.
2. Write the embedded C program to display the required strings on LCD with
the help of PIC microcontroller.
3. Assemble the embedded C program in to its equivalent .hex program, with
the help of MPLAB software.
4. Link the assembled .hex program to the hardware circuit prepared in
PROTEUS.
5. Execute and verify the result in PROTEUS.
Circuit Diagram:
Program:

#include<htc.h>

#include<stdio.h>

__CONFIG(0x3f32);

void lcd_init();

void lcd_cmd(unsigned char b);

void lcd_data1(unsigned char a);

void lcd_write(unsigned char *ch);

unsigned char var1[]={"GOOD"};

unsigned char var2[]={"DAY"};

unsigned char var3[]={"Keep"};

unsigned char var4[]={"Smiling!"};

int main()

TRISD=0x00;

TRISE=0x00;

lcd_init();

lcd_cmd(0x80);

lcd_write(var1);

lcd_cmd(0x89);

lcd_write(var2);

lcd_cmd(0xC0);

lcd_write(var3);
lcd_cmd(0xC7);

lcd_write(var4);

void lcd_init()

lcd_cmd(0x38);

lcd_cmd(0x01);

lcd_cmd(0x06);

lcd_cmd(0x0e);

void lcd_cmd(unsigned char b)

PORTD=b;

PORTE=0x01;

_delay(125000);

PORTE=0x00;

void lcd_data1(unsigned char a)

PORTD=a;

PORTE=0x05;

_delay(125000);

PORTE=0x04;
}

void lcd_write(unsigned char *ch)

while(*ch != '\0')

lcd_data1(*ch);

ch++;

}
Output:

Result:

Thus, the embedded program for LCD interfacing with PIC microcontroller
is executed and the result is verified.
3. Switches & Output Devices interfacing with PIC Microcontroller

Aim:

To interface switches & output devices with PIC microcontroller and to


control the output devices through the switches.

Software Required:

PROTEUS Simulator &

MPLAB Assembler

Procedure:

1. Prepare the hardware circuit in PROTEUS, by placing the devices required


and making the appropriate connections between them.
2. Write the embedded C program to control the output devices through the
input switches with the help of PIC microcontroller.
3. Assemble the embedded C program in to its equivalent .hex program, with
the help of MPLAB software.
4. Link the assembled .hex program to the hardware circuit prepared in
PROTEUS.
5. Execute and verify the result in PROTEUS.
Circuit Diagram:
Program:

#include<htc.h>

#include<stdio.h>

__CONFIG(0x3f32);

void main()

TRISB = 0x07;

TRISC = 0x00;

PORTC = 0x06;

while(1)

RC0 = !RB0;

RC1 = RB1;

RC2 = RB2;

_delay(250);

}
Output:

Result:

Thus, the embedded program for switches and output devices interfacing
with PIC microcontroller is executed and the result is verified.
4. Analog input devices & LCD interfacing with PIC Microcontroller
through serial communication

Aim:

To interface analog input devices & LCD with PIC microcontroller through
serial communication.

Software Required:

PROTEUS Simulator &

MPLAB Assembler

Procedure:

1. Prepare the hardware circuit in PROTEUS, by placing the devices required


and making the appropriate connections between them.
2. Write the embedded C program to take input from analog devices, to find the
digital equivalent of the analog inputs with the help of ADC & to display the
values on LCD by transmitting through serial communication mode with the
help of PIC microcontroller.
3. Assemble the embedded C program in to its equivalent .hex program, with
the help of MPLAB software.
4. Link the assembled .hex program to the hardware circuit prepared in
PROTEUS.
5. Execute and verify the result in PROTEUS.
Circuit Diagram:
Program:

#include<htc.h>

#include<stdio.h>

__CONFIG(0x3f32);

void lcd_init();

void lcd_cmd(unsigned char b);

void lcd_data1(unsigned char a);

void adc_conv(unsigned int c);

void serial_txr(unsigned char a);

void lcd_write(unsigned char *ch);

unsigned char var1[]={"S:"};

unsigned char var2[]={"P:"};

unsigned char var3[]={"T:"};

unsigned char var4[]={"GAS:"};

unsigned int ADC;

int main()

TRISB=0X01;

TRISC=0X80;

TXSTA=0X26;

TRISD=0x00;

TRISE=0x00;

TRISA=0XFF;
RCSTA=0X90;

SPBRG=0X40;

ADCON0=0X81;

ADCON1=0x82;

ADRESH=0X00;

PORTB=0X00;

lcd_init();

lcd_cmd(0x80);

lcd_write(var1);

lcd_cmd(0x89);

lcd_write(var2);

lcd_cmd(0xC0);

lcd_write(var3);

lcd_cmd(0xC7);

lcd_write(var4);

while(1)

unsigned int temp1,ldr;

CHS0=0;

CHS1=0;

CHS2=0;

serial_txr('X');
_delay(500);

lcd_cmd(0x82);

ADGO=1;

while(ADGO==1);

RP0=1;

ADC=ADRESL;

temp1=ADC;

adc_conv(ADC);

RP0=0;

CHS0=1;

CHS1=0;

CHS2=0;

serial_txr('Y');

_delay(500);

lcd_cmd(0xC2);

ADGO=1;

while(ADGO==1);

RP0=1;
ADC=ADRESL;

ldr=ADC;

adc_conv(ADC);

RP0=0;

CHS0=0;

CHS1=1;

CHS2=0;

serial_txr('Z');

_delay(500);

lcd_cmd(0x8b);

ADGO=1;

while(ADGO==1);

RP0=1;

ADC=ADRESL;

ldr=ADC;

adc_conv(ADC);

RP0=0;

}
CHS0=1;

CHS1=1;

CHS2=0;

serial_txr('A');

_delay(500);

lcd_cmd(0xCC);

ADGO=1;

while(ADGO==1);

RP0=1;

ADC=ADRESL;

ldr=ADC;

adc_conv(ADC);

RP0=0;

void lcd_init()

lcd_cmd(0x38);

lcd_cmd(0x01);
lcd_cmd(0x06);

lcd_cmd(0x0e);

void lcd_cmd(unsigned char b)

PORTD=b;

PORTE=0x01;

delay();

PORTE=0x00;

void lcd_data1(unsigned char a)

PORTD=a;

PORTE=0x05;

delay();

PORTE=0x04;

void adc_conv(unsigned int c)

int temp,hun,ten,one;

temp=c;

hun=(temp/100);

lcd_data1(hun+0X30);
serial_txr(hun+0x30);

_delay(1950);

ten=((temp/10)%10);

lcd_data1(ten+0X30);

serial_txr(ten+0x30);

_delay(1950);

one=(temp%10);

lcd_data1(one+0X30);

serial_txr(one+0x30);

_delay(1950);

delay()

_delay(125000);

_delay(125000);

_delay(25000);

//_delay(25000);

_delay(25000);

void serial_txr(unsigned char a)

TXREG=a;

while(TXIF==0);
}

void lcd_write(unsigned char *ch)

while(*ch != '\0')

lcd_data1(*ch);

ch++;

}
Output:

Result:

Thus, the embedded program for analog input devices and LCD interfacing
with PIC microcontroller is executed and the result is verified.

Das könnte Ihnen auch gefallen