Escolar Documentos
Profissional Documentos
Cultura Documentos
In this example we connect an LDR to ADC channel 2 which is PA 2. Once again you will get a value in theory between 0 and 1023. The more light that there is the higher
the value.
We will read the value in from the LDR and display this on the LCD
Schematic
PIC16F877 LDR
Code
void main()
{
TRISA = 0xFF; // PORTA is input
TRISB = 0;
PORTB = 0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, " ADC :");
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
adcvalue = temp_res;
ShowADC (1,7,adcvalue);
Delay_ms(300);
} while(1);
} // end main
Links
Microcontroller Programmer Kit Development Board for PIC microcontroller evaluation QL200 PIC
Be Sociable, Share!
Related posts: