Forum Replies Created
-
AuthorPosts
-
chuducParticipant
My english is very bad I can not express their answers, Here is my code written for lcd16x2, hope it is for your help
#include “reg52.h”
const unsigned char clr=1,home=2,d_on=15,d_off=12,set=56;
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;/* P0 noi voi LCD data
noi 3 bit thap cua P2 voi chan cam LCD_CONTROL
co the su dung board thi nghiem 89_v2 de chay chuong trinh
cac lenh su dung:
int_lcd(); cai dat lcd
lenh(clr); xoa lcd
lenh(home); dua con tro ve dau dong
lenh(d_on); mo display,blink
lenh(set); che do 16×2
dat(1 ki tu); xuat 1 ki tu ra lcd
dat_str(“chuoi”); xuat 1 chuoi ki tu ra lcd
*/void delay(unsigned int msec) // chuong trinh con tao thoi gian tre ms
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
//
void busy() //chuong trinh con kiem tra lcd co ban ko
{
rs=0;
rw=1;
P0_7=1;
while(P0_7!=0)
{
e=0;
e=1;
}
}
//
void lenh(unsigned char ma) //chuong trinh con xuat lenh len LCD
{
busy();rs=0;
rw=0;
e=1;
P0=ma;
e=0;
}
//
void dat(unsigned char ma) //chuong trinh con xuat du lieu len LCD
{
busy();
rs=1;
rw=0;
e=1;
P0=ma;
e=0;
}
//
void mov(unsigned char row, unsigned char col) //chuong trinh di chuyen con tro
{
lenh(128 | (row << 6) | col); //row =0 la hang dau,=1 la hang 2
}
//
void dat_str(unsigned char *str) //chuong trinh xuat ra LCD mot chuoi ki tu
{
while (*str!=’