Microcontroller › 8051 › how to display ADC values to 16×2 LCD
- This topic has 8 replies, 3 voices, and was last updated 10 years, 11 months ago by shruthikandakatla.
-
AuthorPosts
-
March 15, 2011 at 11:49 am #798romel emperadoParticipant
guys i have problem on converting my ADC output values to String and display it to 16×2 LCD.. Im using keil compiler.. i have the code and its almost done…
#include <REG51.H>
#define adc_port P3
#define LCD P2
#define LCD_EN 0x80
#define LCD_RS 0x20sbit ale=P1^0; //address latch enable
sbit oe=P1^3; //output enable
sbit sc=P1^1; //start conversion
sbit eoc=P1^2; //end of conversion
sbit clk=P1^7; // clocksbit ADD_A=P1^4; // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;//LCD Commands
#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SETFUNCTION 0x28
#define LCD_SETDDADDR 0x80
void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char*);void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}void delay(unsigned int count) // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}void select_channel(char c,char b,char a)
{
ADD_A = a;
ADD_B = b;
ADD_C = c;
}void convert()
{
delay(1);
ale=0; //activate the ale PIN
ale=1;
sc=1; //initaite convertion
sc=0;
delay(1);}
void read_adc()
{while(eoc == 0); //end of convertion
oe = 1; //enable adc output
delay(1);
oe = 0;
delay(1);}
void main()
{adc_port = 0xff;
TMOD = 0x22; //timer0 setting for generating clock of 500KHz using interrupt enable mode.
TH0 = 0xFD;
IE = 0x82;
TR0 = 1;
lcd_init();while(1)
{
select_channel(0,0,1);
convert();
read_adc();
lcd_cmd(0x80); // 1st line address
lcd_str(“WindV: ” );lcd_cmd(0xC0); // 2nd line address
lcd_str(“BattV: “);
}
}void delayus(unsigned char delay)
{
while(delay–);
}void delayms(unsigned char delay)
{
while(delay–)
delayus(149);
}void lcd_reset()
{
LCD = 0xFF;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x02+LCD_EN;
LCD = 0x02;
delayms(5);
}void lcd_init ()
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode – 1 line – 5×7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor – no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment – No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}void lcd_cmd (char cmd)
{
LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
LCD = ((cmd >> 4) & 0x0F);LCD = (cmd & 0x0F)|LCD_EN;
LCD = (cmd & 0x0F);
delayus(250);
delayus(250);
}void lcd_data (unsigned char dat)
{
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
LCD = (((dat >> 4) & 0x0F)|LCD_RS);
LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
LCD = ((dat & 0x0F)|LCD_RS);
delayus(250);
delayus(250);
}void lcd_str (unsigned char *str)
{
while(*str)
{
lcd_data(*str++);
}
}March 15, 2011 at 12:05 pm #5752dagakshayParticipantto display the numbers on LCD you have to add 48 in the asii number..
for example you have unsigned char i=1;
LCD_write(i+48);just try that…(i din’t put my hand in your magii….. {code})…
March 15, 2011 at 1:16 pm #5755romel emperadoParticipantwhy it is displaying weird characters?
float volt;volt = ((volt * 5)/256) * 4.2;
lcd_data(volt+48);pls give some example.. this is my first project…
March 16, 2011 at 4:33 am #5765dagakshayParticipantApril 4, 2011 at 2:25 am #5868romel emperadoParticipantit’s now okay.. I just use mikroC builtit Library.. hehe
April 4, 2011 at 4:49 am #5874dagakshayParticipantusing inbuilt library is a good option but you must know how actully the thing works…
April 4, 2011 at 2:49 pm #5884romel emperadoParticipantyeah.. i might know that if you teach me.. hehe
April 5, 2011 at 5:13 am #5895dagakshayParticipantmha pleasure….
February 19, 2014 at 8:48 am #11057shruthikandakatlaParticipantcan u please mail me the circuit diagram for this code…
-
AuthorPosts
- You must be logged in to reply to this topic.