0% found this document useful (0 votes)
35 views

Exp 5

1. The document describes an experiment using a PIC18F4520 microcontroller to interface with an ADC and transfer ADC values to a serial port or LCD screen. 2. The code samples show how to configure the ADC, read ADC values, and transmit the values over serial by converting them to ASCII characters. 3. The output shows example ADC readings transmitted over serial for different potentiometer positions representing 30%, 60%, and 75% of the voltage range.

Uploaded by

Jaynil Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Exp 5

1. The document describes an experiment using a PIC18F4520 microcontroller to interface with an ADC and transfer ADC values to a serial port or LCD screen. 2. The code samples show how to configure the ADC, read ADC values, and transmit the values over serial by converting them to ASCII characters. 3. The output shows example ADC readings transmitted over serial for different potentiometer positions representing 30%, 60%, and 75% of the voltage range.

Uploaded by

Jaynil Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sardar Patel Institute of Technology

Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India Electronics


Engineering Department
Subject: MA Lab Academic Year: 2020-21
Name: Jaynil Patel Batch: D batch
UID No- 2016110043 Date: 01-July-2021

Experiment No: 5

Aim:
To study the programming and interfacing of an 8-bit PIC18F4520 microcontroller.

Problem Statement:
To write a program where the PIC microcontroller is interfaced with ADC and to
transfer ADC values in serial port or LCD screen.

Software Used:
1. MPLAB X IDE v5.50
2. Proteus 8 professional

Code:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "newfile.h"
void main(void){
TRISAbits.TRISA0=1;
ADCON0=0x01;
ADCON1=0x00;
ADCON2=0x87;

unsigned char x;
unsigned int v1,v2,v3;
TXSTA=0x02;
RCSTA=0x90;
SPBRG=15;
TXSTAbits.TXEN=1;
v3=v2;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
v1 = ADRESH;
v1 = v1<<8;
v1 = v1+ADRESL;
v2=v1;
if(v3 !=v2){
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India Electronics
Engineering Department
Subject: MA Lab Academic Year: 2020-21
v3=v2;
TXREG=((v2/10000)%10)|0x30;
while(PIR1bits.TXIF==0);
TXREG=((v2/1000)%10)|0x30;
while(PIR1bits.TXIF==0);
TXREG=((v2/100)%10)|0x30;
while(PIR1bits.TXIF==0);
TXREG=((v2/10)%10)|0x30;
while(PIR1bits.TXIF==0);
TXREG=(v2%10)|0x30;
while(PIR1bits.TXIF==0);
TXREG='_';
while(PIR1bits.TXIF==0);
}
}
return;
}

Circuit Diagram:
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India Electronics
Engineering Department
Subject: MA Lab Academic Year: 2020-21

Output:
ADC value: (for 30%op is 00307)

ADC value: (for 60% op is 00614)


Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India Electronics
Engineering Department
Subject: MA Lab Academic Year: 2020-21

(ADC value for 75% op is 00767)

Conclusion:
➢ In this experiment, I learnt how to program a PIC18F4520 microcontroller and
print numbers on virtual terminal
➢ I used POT-HG which is a variable resistor that allows to change the resistance
during simulation run-time
➢ The AN0(channel 0) pin is used from a PIC microcontroller. The resolution of
the 10-bit ADC is [5/ (1024)] that is 4.8828 mV as Vrefs are not used.
➢ Thus we successfully interfaced a PIC microcontroller

You might also like