0% found this document useful (0 votes)
32 views13 pages

Bai 4

This document describes code for displaying text and numbers on a 16x02 LCD screen connected to a microcontroller. It includes functions to initialize the LCD, write characters and control commands to the LCD, display strings at specific rows, and display integers by breaking them into individual digits. The main function calls the initialization function, displays two sample strings at different rows, and includes a loop to continuously display the number 1234 on the LCD by breaking it into individual digits.

Uploaded by

van hoan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views13 pages

Bai 4

This document describes code for displaying text and numbers on a 16x02 LCD screen connected to a microcontroller. It includes functions to initialize the LCD, write characters and control commands to the LCD, display strings at specific rows, and display integers by breaking them into individual digits. The main function calls the initialization function, displays two sample strings at different rows, and includes a loop to continuously display the number 1234 on the LCD by breaking it into individual digits.

Uploaded by

van hoan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Bài Tập Bài 3

Bài 4: LCD
Bài 4: LCD
VC C
5V

R 1 10K LCD16x02

1
C 6
J1

5V LC D
104

9
8
7
6
5
4
3
2

9
8
7
6
5
4
3
2
1
16
15
14
13
12
11
10
10
U 1

40

EN
Rw
RS
1 39
2 P 1 .0 P 0 .0 /A D 0 38

VC C
3 P 1 .1 P 0 .1 /A D 1 37 5V
4 P 1 .2 P 0 .2 /A D 2 36
5 P 1 .3 P 0 .3 /A D 3 35
6 P 1 .4 P 0 .4 /A D 4 34
+ C 3 7 P 1 .5 P 0 .5 /A D 5 33
C A P A C IT O R P O L 8 P 1 .6 P 0 .6 /A D 6 32
9 P 1 .7 P 0 .7 /A D 7 31
10 R ST E A /V P P 30 R 2
11 P 3 .0 /R XD A L E /P R O G 29
P 3 .1 /T XD PSEN 5K
12 28 D 7
R 3 13 P 3 .2 /IN T 0 P 2 .7 /A 1 5 27 D 6
10K 14 P 3 .3 /IN T 1 P 2 .6 /A 1 4 26 D 5
15 P 3 .4 /T 0 P 2 .5 /A 1 3 25 D 4
16 P 3 .5 /T 1 P 2 .4 /A 1 2 24 D 3
17 P 3 .6 /W R P 2 .3 /A 1 1 23 D 2
18 P 3 .7 /R D P 2 .2 /A 1 0 22 D 1
19 XTA L2 P 2 .1 /A 9 21 D 0
XTA L1 P 2 .0 /A 8
GN D

Y 1
12M hz A T89C 51
20

C 2 C 1
33p 33p

Rw RS
EN
Bài 4: LCD

#include <REGX52.H>
#include <string.h>
#define LCDdata P2
sbit BF=P2^7;
sbit RS=P3^7;
sbit RW=P3^6;
sbit EN=P3^5;
Bài 4: LCD

void wait(void)
{
LCDdata=0xff;
while(BF){EN=0;delay(100);EN=1;delay(100);}
RW=0;
}
Bài 4: LCD

void LCDwrite(unsigned char c)


{
EN=1;
RS=1;
RW=1;
wait();
LCDdata=c;
EN=0;
}
Bài 4: LCD

void LCDcontrol(unsigned char x)


{
EN=1;
RS=0;
RW=1;
wait();
LCDdata=x;
EN=0;
}
Bài 4: LCD
void LCDinit(void)
{
LCDcontrol(0x30);
LCDcontrol(0x30);
LCDcontrol(0x30);
LCDcontrol(0x38);//2 dong ma tran 5x7
LCDcontrol(0x0c);//bat con tro
LCDcontrol(0x06); //tang con tro sang fai
LCDcontrol(0x01); //xoa man hinh
}
Bài 4: LCD
void LCDputs(unsigned char *s,unsigned char
row)
{
int len;
if(row==1)LCDcontrol(0x80);
else LCDcontrol(0xc0);
len=strlen(s);
while(len!=-1)
{
LCDwrite(*s);delay(5000);
len--;
s++ ;
}
}
Bài 4: LCD
void LCDwritei(int d)
{
int i,j,k,l;
i=d%10;
d=d/10;
j=d%10;
d=d/10;
k=d%10;
l=d/10;
LCDwrite(l);
LCDwrite(k);
LCDwrite(j);
LCDwrite(i);
}
void main(void)
{
// char x;
// P2=0x00;
LCDinit();
LCDputs(“DKS_Group",1);
LCDputs(“BKHN",2);
delay(30000);
while(1)
{
}
}
Bài 3: LED_7_SEG

void display(int x)
{
convert(x);
P0=0x00;led1=1; P1 = maled7[i]; delay(100);
P0=0x00;led2=1; P1 = maled7[j]; delay(100);
P0=0x00;led3=1; P1 = maled7[k]; delay(100);
P0=0x00;led4=1; P1 = maled7[l]; delay(100);
}
Bài 3: LED_7_SEG

void main()
{
while(1)
{
display(1234);
}
}

You might also like