Real Time Embedded System Lab                       Department of Electrical & Computer Engineering
Lab 06- APPLICATION AND UNDERSTANDING OF ANALOG
               TO DIGITAL CONVERTER
       Task 01: Here an input signal of voltage from the potentiometer is given to analog input
channel AN0 then the 10-bit result after conversion has been displayed on 8 bits at PORTC and
remaining 2 bits PORTD.
Matlab Code:
          \* File:   atdc.c
           * Author: Syed Haider Abbas
           * Created on October 24, 2022, 8:58 PM
           */
          #pragma config OSC = HS
          #pragma config WDT = OFF
          #pragma config PWRT = OFF
          #pragma config BOREN = OFF
          #pragma config LVP = OFF
          #pragma config CPD = OFF
          #pragma config WRTD = OFF
          #pragma config CP1 = OFF
          #include <xc.h>
          void delay(int n);
          void main(void)
          {
           TRISC=0x00;
           TRISD=0x00;
           TRISAbits.TRISA0=1;
           ADCON0=0x81;
           ADCON2=0xCE;
           while(1) {
           delay(1);
           ADCON0bits.GO=1;
          while(ADCON0bits.DONE==1)
           PORTC=ADRESL;
           PORTD=ADRESH;
           delay(1);
           } }
          void delay(int n)
          { for(int i=0;i<n;i++)
           { for(int j=0;j<250;j++) { }
           } }
Output:
Registration No: FA19-BSEE-023