Bài Tập Bài 3
Trang 2Bài 4: LCD
Trang 3Bài 4: LCD
D 5
D 6
D 7
R S T 9
X T A L 2
1 8
X T A L 1
1 9
P S E N 2 9
A L E / P R O GE A / V P P 3 0
3 1
P 1 0 1
P 1 1 2
P 1 2 3
P 1 3 4
P 1 4 5
P 1 5 6
P 1 6 7
P 1 7 8
P 2 0 / A 8 2 1
P 2 1 / A 9 2 2
P 2 2 / A 1 0 2 3
P 2 3 / A 1 1 2 4
P 2 4 / A 1 2 2 5
P 2 5 / A 1 3 2 6
P 2 6 / A 1 4 2 7
P 2 7 / A 1 5 2 8
P 3 0 / R X D
1 0
P 3 1 / T X D
1 1
P 3 2 / I N T 0
1 2
P 3 3 / I N T 1
1 3
P 3 4 / T 0
1 4
P 3 5 / T 1
1 5
P 3 6 / W R
1 6
P 3 7 / R D
1 7
P 0 0 / A D 0 3 9
P 0 1 / A D 1 3 8
P 0 2 / A D 2 3 7
P 0 3 / A D 3 3 6
P 0 4 / A D 4 3 5
P 0 5 / A D 5 3 4
P 0 6 / A D 6 3 3
P 0 7 / A D 7 3 2
U 1
A T 8 9 C 5 1
R 1 1 0 K
5 V
V C C
J 1
L C D
R 2
5 K
Y 1
1 2 M h z
C 1
3 3 p
C 2
3 3 p
R 3
1 0 K
5 V
LCD16x02
C A P A C I T O R P O L
5 V
C 6
1 0 4
D 0
D 1
D 2
D 3
D 4
Trang 4#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
Trang 5void wait(void) {
LCDdata=0xff;
while(BF){EN=0;delay(100);EN=1;delay(100);} RW=0;
}
Bài 4: LCD
Trang 6void LCDwrite(unsigned char c) {
EN=1;
RS=1;
RW=1;
wait();
LCDdata=c;
EN=0;
}
Bài 4: LCD
Trang 7void LCDcontrol(unsigned char x) {
EN=1;
RS=0;
RW=1;
wait();
LCDdata=x;
EN=0;
}
Bài 4: LCD
Trang 8void 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
Trang 9void 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 ;
}
Bài 4: LCD
Trang 10void 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);
Bài 4: LCD
Trang 11void main(void) {
// char x;
// P2=0x00;
LCDinit();
LCDputs(“DKS_Group",1); LCDputs(“BKHN",2);
delay(30000);
while(1) {
} }
Trang 12Bà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); }
Trang 13Bài 3: LED_7_SEG
void main() {
while(1) {
display(1234);
} }