Uploaded by Hitanshu Jain

Experiment6 InterfacingADC

advertisement
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
Electronics Engineering Department
Subject: MC Lab Academic SEM: IV Year: 2020-21
Name: Aditya Patwardhan
UID No: 2019110043
Batch: C
Date: 10/04/2021
Experiment No:6
AIM:
To use C language programming to interface an ADC with the PIC 18F4520
microcontroller.
Objective:
1. To understand C language programming for PIC 18F4520 microcontroller.
2. To interface an ADC motor with a microcontroller.
3. To implement serial communication.
Software used:
1. MPLAB IDE
2. Proteus 8 Professional
Procedure:
1. Proteus 8 Professional:





Run Proteus 8 Professional as administrator
Click on schematic capture
Go to components and select ‘PIC 18F4520’ and place it on the schematic
Similarly, select the LEDs, switches, DC power source, resistors, and ground
Connect them with the wires accordingly.
2. MPLAB IDE:
 Run the MPLAB and create a new Standalone Project
 Select the Advanced 8-bit MCUs
 Select the device – PIC 18F4520
 Select the simulator in Tools
 Select the complier you want to use
 Give the file a name
 Include the required header files and start coding.
3. Now open Proteus 8 Professional, again
 Open project
 Double click on the microcontroller
 Then in the Program File select the hex file
 Run the Simulation
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
Electronics Engineering Department
Subject: MC Lab Academic SEM: IV Year: 2020-21
Program:
#include <stdio.h>
#include <stdlib.h>
#include "headerFile.h"
#include <xc.h>
unsigned long adcRead()
{
unsigned long data;
ADCON0bits.GO = 1;
while(ADCON0bits.DONE == 1);
data = ADRESH;
data = (data << 8);
data = data + ADRESL;
return (data);
}
void main() {
unsigned long data;
char dataArray[4];
int length = sizeof(dataArray)/sizeof(int);
TRISAbits.TRISA0 = 1;
TRISCbits.TRISC6 = 0;
TRISB = 0;
TRISD = 0;
ADCON0 = 0x01;
ADCON1 = 0x30;
ADCON2 = 0x87;
TXSTA = 0x02;
SPBRG = 15;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
while(1)
{
data = adcRead();
for(int i = 0;i<length;i++){
dataArray[i] = (data % 10) + 0x30;
data = (data / 10);
}
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
Electronics Engineering Department
Subject: MC Lab Academic SEM: IV Year: 2020-21
for(int i = length-1; i>=0; i--)
{
TXREG = dataArray[i];
while(PIR1bits.TXIF==0);
}
TXREG = 0x0D;
while(PIR1bits.TXIF==0);
}
}
Interfacing:
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
Electronics Engineering Department
Subject: MC Lab Academic SEM: IV Year: 2020-21
Conclusion:
 We learnt how to generate interface an ADC with a microcontroller.
 We also learnt how to modify the range of using a reference voltage.
 We also learnt how to serially communication with PIC 18F4520.
Download