0% found this document useful (0 votes)
17 views1 page

MC Lab 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

MC Lab 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CODE:

#include <p18f4550.h>
#include "vector_relocate.h" void Start_Conversion()
#define LCD_DATA PORTD {ADCON0bits.GO=1;
#define en PORTEbits.RE2 }
#define rw PORTEbits.RE1 unsigned int Get_ADC_Result()
#define rs PORTEbits.RE0 {unsigned int ADC_Result=0;
void ADC_Init(void); while(ADCON0bits.GO);
unsigned int Get_ADC_Result(void); ADC_Result=ADRESL;
void Start_Conversion(void); ADC_Result|=((unsigned int)ADRESH) << 8;
void msdelay (unsigned int time); return ADC_Result;
void init_LCD(void); }
void LCD_command(unsigned char cmd); void msdelay (unsigned int time)
void LCD_data(unsigned char data); {unsigned int i, j;
void LCD_write_string(static char *str); for (i = 0; i < time; i++)
void main() for (j = 0; j < 710; j++);
{char msg1[] = "Smart Logic Tech";
char msg2[] = "ADC O/P:";
unsigned char i, Thousands,Hundreds,Tens,Ones; void init_LCD(void)
unsigned int adc_val; { LCD_command(0x38);
ADCON1 = 0x0F; msdelay(15);
TRISD = 0x00; LCD_command(0x01);
TRISE = 0x00; msdelay(15);
ADC_Init(); LCD_command(0x0C);
init_LCD(); msdelay(15);
LCD_write_string(msg1); LCD_command(0x80);
LCD_command(0xC0); msdelay(15);
LCD_write_string(msg2); }
while(1) void LCD_command(unsigned char cmd)
{ Start_Conversion(); { LCD_DATA = cmd;
adc_val= Get_ADC_Result(); rs = 0;
LCD_command (0xC8); rw = 0;
i = adc_val/1000 ; en = 1;
Thousands = i + 0x30; msdelay(15);
LCD_data (Thousands); en = 0;
i = (adc_val%1000)/100; }
Hundreds = i + 0x30; void LCD_data(unsigned char data)
LCD_data (Hundreds); { LCD_DATA = data;
i = ((adc_val%1000)%100)/10; rs = 1;
Tens = i + 0x30; rw = 0;
LCD_data (Tens); en = 1;
i = adc_val%10 ; msdelay(15);
Ones = i + 30; en = 0;
LCD_data (i + 0x30); }
void LCD_write_string(static char *str)
msdelay(300); } { int i = 0;
} while (str[i] != 0)
void ADC_Init() { LCD_data(str[i]);
{ADCON0=0b00000100; msdelay(15);
ADCON1=0b00001110; i++;
ADCON2=0b10001110; }
ADCON0bits.ADON=1; }
}

You might also like