Bài Tập Bài 3
Bài 4: LCD
Bài 4: LCD
VC C
5V
10K
LCD16x02
1
R 1
C 6
J1
5V
LC D
R 3
10K
Y 1
12M hz
C 2
33p
VC C
GN D
C 3
C A P A C IT O R P O L
P 1 .0
P 0 .0 /A D 0
P 1 .1
P 0 .1 /A D 1
P 1 .2
P 0 .2 /A D 2
P 1 .3
P 0 .3 /A D 3
P 1 .4
P 0 .4 /A D 4
P 1 .5
P 0 .5 /A D 5
P 1 .6
P 0 .6 /A D 6
P 1 .7
P 0 .7 /A D 7
R ST
E A /V P P
P 3 .0 /R XD A L E /P R O G
P 3 .1 /T XD
PSEN
P 3 .2 /IN T 0 P 2 .7 /A 1 5
P 3 .3 /IN T 1 P 2 .6 /A 1 4
P 3 .4 /T 0
P 2 .5 /A 1 3
P 3 .5 /T 1
P 2 .4 /A 1 2
P 3 .6 /W R
P 2 .3 /A 1 1
P 3 .7 /R D
P 2 .2 /A 1 0
XTA L2
P 2 .1 /A 9
XTA L1
P 2 .0 /A 8
A T89C 51
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
5V
D 7
D 6
D 5
R 2
5K
D
D
D
D
D
4
3
2
1
0
20
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
EN
Rw
RS
U 1
40
10
9
8
7
6
5
4
3
2
104
C 1
33p
EN
Rw
RS
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;
P0=0x00;led2=1;
P0=0x00;led3=1;
P0=0x00;led4=1;
}
P1 = maled7[i]; delay(100);
P1 = maled7[j]; delay(100);
P1 = maled7[k]; delay(100);
P1 = maled7[l]; delay(100);
Bài 3: LED_7_SEG
void main()
{
while(1)
{
display(1234);
}
}