PIC INTERFACING WITH LED USING ADC PINS

INTRODUCTION:

  • Here I am using the PIC16 8 bit MCU  version that is PIC16F887A.

DESCRIPTION:

  • Here the idea is to disable the comparators to enable the process of signal conversion.
  • The PORT C or the PORTD LEDs can be toggled as the user wishes.

Circuit Diagram:

The Test configuration:

Microcontroller unit:          PIC16F887

             

Development.Board:    EasyPIC6 – ac:ADC

               

Oscillator frequency :   8.0000 MHz

Ext. Modules:

Software used :           mikroC PRO(PIC)                  

PROGRAM:

unsigned int tem_res;//temporary result stored in the variable temp res

void main()

{

 ANSEL  = 0x04;           // AN2 pin configured  as analog input

 ANSELH = 0;              // Rest other AN pins to be configured  as digital Input/Outptut pins

 C1ON_bit = 0;            // Disable the available  comparators

 C2ON_bit = 0;

 TRISD  = 0xFF;          // PORTA is regarded as  input

 TRISA  = 0;           // PORTC is assigned as  output

 TRISC  = 0;          // PORTD is assigned  output

 do {

tem_res = ADC_Read(2);   // Obtain the corresponding results of AD conversion(10 bits)

PORTC = temp_res;      // Lowermost  8 bits assigned  to PORTD

PORTA = temp_res >> 8; // The  most significant bits are assigned  to RC1, RC0

 } while(1);While logic is high

}

Connection diagram:

WORKING VIDEO:

https://drive.google.com/open?id=1YNjd5rbFtYynpqEu2DuUc4grpoz-V5HU