Hey guys, I have created a code where adc conversion takes place from a variable resistor and displays it on screen (0-1023)...thankfully it is successful, however, i want my program to display something on the screen when a certain value is reached for example, if the adc value reaches 500 on the LCD i want it to display the letter A on the screen and if it reaches 600 it displays B? Do i need an interrupt or a timer or can it be easily done?
Any help or guidance would be highly Appreciated.
Thank you
the MCU is PIC16F877A
THE CODE:
Any help or guidance would be highly Appreciated.
Thank you
the MCU is PIC16F877A
THE CODE:
Code:
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
void main() {
char adc []= "ADC value=";
char *temp = "0000";
unsigned int adc_value;
ADCON0 = 0b10001000; //AN1 analog channel selected
ADCON1 = 0b01001001; //PORT configuratoin to AN1
TRISA = 0b00000010; //RA1 analogue input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,adc);
do {
adc_value = ADC_Read(1); //read from channel 1
temp [0] = adc_value/1000 +48 ; //add 48 to get the ascii value
temp [1] = (adc_value/100) %10 +48 ;
temp [2] = (adc_value/10) %10 +48;
temp [3] = (adc_value/1)%10 +48;
Lcd_Out(1,11,temp);
Delay_ms(100);
} while (1)
}