mailus
Full Member level 4
please explain this code....
program......
need explanation for these....
here "(2)" indicates channel number is it correct...
program......
Code:
*/
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
// Define Messages
char message1[] = "ADC Value= ";
char *temp = "0000";
unsigned int ADC_Value;
void main() {
ANSEL = 0b00000100; // RA2/AN2 is analog input
ADCON0 = 0b00001000; // Analog channel select @ AN2
CMCON0 = 0x07 ; // Disbale comparators
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message1); // Write message1 in 1st row
do {
adc_value = ADC_Read(2);
temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
temp[1] = (adc_value/100)%10 + 48;
temp[2] = (adc_value/10)%10 + 48;
temp[3] = adc_value%10 + 48;
Lcd_Out(1,11,temp);
Delay_ms(2000);
} while(1);
}
need explanation for these....
Code:
char *temp = "0000";
Code:
temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
temp[1] = (adc_value/100)%10 + 48;
temp[2] = (adc_value/10)%10 + 48;
temp[3] = adc_value%10 + 48;
Lcd_Out(1,11,temp);
here "(2)" indicates channel number is it correct...
Code:
adc_value = ADC_Read(2);