// program to convert hexadecimal data to decimal format
#include<reg51.h>
#include"lcd.h"
sbit cs=P3^4;
sbit rd=P3^5;
sbit wr=P3^6;
sbit intr=P3^7;
sfr mydata=0x90;
unsigned char k0,k1,k2,k3,k4;
void conv_and_disp(unsigned char);
void conv_and_disp(unsigned char x)
{
init_lcd();
k0=x/10;
k1=x%10;
k2=k0%10;
k3=k0/10;
disp_lcd(k3+0x30);
disp_lcd(k2+0x30);
disp_lcd(k1+0x30);
while(1);
}
void main()
{
unsigned char val;
//val=0xff;
mydata=0xff;
//cs=1;
rd=1;
wr=1;
intr=1;
while(1)
{
//cs=0;
wr=0;
wr=1;
while(intr==1);
rd=0;
val=mydata;
conv_and_disp(val);
rd=1;
}
}
***************lcd.h*********************
#include"delay.h"
sfr dat=0x0a0;
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
void write_lcd(char);
void init_lcd();
void cmd_lcd(char );
void disp_lcd(char );
void str_lcd(char *);
void write_lcd(char cmd)
{
dat=cmd;
rw=0;
en=1;
delay_ms(2);
en=0;
delay_ms(2);
}
void init_lcd()
{
cmd_lcd(0x01);
cmd_lcd(0x38);
cmd_lcd(0x0c);
cmd_lcd(0x80);
cmd_lcd(0x06);
}
void cmd_lcd(char ch)
{
rs=0;
write_lcd(ch);
}
void disp_lcd(char cmd)
{
rs=1;
write_lcd(cmd);
}
void str_lcd(char *str)
{
while(*str)
disp_lcd(*str++);
}
No comments:
Post a Comment