Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 805 (Phần 4) - Hồ Trung Mỹ

Hiệu đính từ slide của thầy Hồ Trung Mỹ  
Bộ môn Điện tử - DH BK TPHCM  
CHƯƠNG 3  
HỌ VI ĐiỀU KHIỂN 8051  
1
3.6 Cổng nối tiếp  
(Serial Port)  
2
Các hoạt động cổng nối tiếp của 8051  
• Giới thiệu  
• Chuẩn EIA(Electronic Industries  
Association)-232E hoặc RS232  
• Giao tiếp cổng nối tiếp MCS-51/52  
• Ứng dụng của chế độ 0  
• Ứng dụng của chế độ 1  
• Ứng dụng của chế độ 2 & 3  
3
Truyền dữ liệu nối tiếp  
• Truyền dữ liệu khoảng cách xa  
• Tốc độ truyền dữ liệu thấp  
• Truyền dữ liệu nối tiếp đồng bộ  
– Dùng tín hiệu clock riêng để đồng bộ hóa mạch thu  
và phát.  
– Thường dùng khung dữ liệu lớn hơn và nhanh hơn.  
• Truyền dữ liệu nối tiếp bất đồng bộ  
– Không cần tín hiệu clock riêng để đồng bộ hoá  
chuyển dữ liệu.  
– Dựa trên ký tự. Mỗi ký tự được đóng khung bằng  
“start bit” và “stop bit”.  
– Bên thu cần nhận dạng “start bit” và “stop bit” để  
nhận đúng ký tự dữ liệu.  
4
Truyền dữ liệu nối tiếp đồng bộ (synchronous)  
và bất đồng bộ (asynchronous) với 8051  
Đường truyền dữ liệu cơ bản  
DTE: Data Terminal Equipment  
Communication link  
DCE: Data Communications Equipmnent  
DTE  
DCE  
DCE  
DTE  
Computer or  
terminal  
Modem  
Modem  
Computer or  
terminal  
• Người ta có thể sử dụng đường điện thoại công cộng  
hoặc dành riêng làm môi trường truyền dữ liệu nối  
tiếp bất đồng bộ.  
• Modem được dùng để chuyển đổi dữ liệu số thành  
dạng sóng analog thích hợp cho việc truyền trên  
đường dây điện thoại và ngược lại.  
• Có 2 kiểu đường truyền: Điểm đến điểm và Đa điểm.  
6
Đường truyền Điểm đến điểm  
và Đa điểm  
Rx  
Tx  
StationRx  
Station  
Tx  
Peer  
Peer  
Master  
Slave 1  
Slave 2  
Slave n  
Address 1  
Address 2  
Address n  
7
Cơ bản về các đường truyền  
• Hệ thống 2 dây và 4 dây:  
– 2 dây: tín hiệu và đất.  
– 4 dây: 2 bộ 2 dây.  
• Các kiểu đường truyền:  
– Đơn công (Simplex link): đường dây dành riêng  
cho thu hoặc phát chứ không cả hai.  
– Bán song công (Half-duplex link): đường dây có  
thể dùng cho phát hoặc thu nhưng mỗi lần chỉ  
có 1 chiều.  
– Song công (Full-duplex link): Phát và thu có thể  
tiến hành đồng thời. Đường truyền cần 4 dây.  
8
Cơ bản về các đường truyền  
Signal pattern for letter “A” (41H)  
Start bit  
Stop bit  
5V  
0V  
Serial port  
0 1 0 0 0 0 0 1 0  
1
D0 D1 D2 D3 D4 D5 D6 D7  
>+3V  
<-3V  
RS232  
mark  
space  
9
EIA-232-E or RS-232  
• EIA-232-E or RS-232 can apply to the  
following data communication schemes:  
– Serial communications  
– Synchronous and asynchronous  
– Dedicated leased or private lines  
– Switched service  
– Two wire or four wire  
– Point to point or multipoint  
• 4 aspects in EIA-232-E interface:  
mechanical, functional, procedural, and  
electrical.  
10  
EIA-232-E Mechanical  
Characteristics  
• 25-pin DB25 /9-pin DB9 plug connector.  
11  
DB-9 Signals  
12  
EIA-232-E Connector and Pin  
Assignment  
Signal direction  
Signal Name  
Signal Name  
Signal direction  
14 1  
15 2  
16 3  
17 4  
18 5  
19 6  
20 7  
21 8  
22 9  
23 10  
24 11  
25 12  
13  
to DCE  
to DTE  
to DTE  
to DTE  
Secondary TxD  
Tx clock  
protective ground  
TxD  
Both  
to DCE  
to DTE  
to DCE  
to DTE  
to DTE  
Both  
Secondary RxD  
Rx clock  
RxD  
Request To Send  
Clear To Send  
Data Set Ready  
Signal ground  
Carrier Detect  
Reserved  
unassigned  
to DCE  
to DCE  
to DTE  
to DTE  
Both  
Secondary Request To Send  
Data Terminal Ready  
Signal Quality Detect  
Ring indicator  
to DTE  
Data Rate Select  
Tx clock  
Reserved  
to DCE  
Unassigned  
Secondary Carrier Detect  
unassigned  
to DTE  
Secondary Clear To Send to DTE  
13  
Functions of EIA-232-E Interchange Circuits  
1
-
Shield  
2
BA  
Transmitted data  
3
BB  
Received data  
4
5
CA/CJ  
CB  
Request to send/ready for receiving  
Clear to send  
6
CC  
DCE  
7
AB  
Signal common  
8
CF  
-
Received line signal detector  
(Reserved for testing, unassigned)  
Secondary received line signal detection/data range selector (DCE source)  
Secondary clear to send  
Secondary transmitted data  
Transmitter signal element timing (DCE source)  
Secondary received data  
Received signal element timing  
Local loopback  
Secondary request to send  
DTE ready  
Remote loopback/signal quality detector  
Ring indicator  
9,10,11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
SCF/CI  
SCB  
SBA  
DB  
SBB  
DD  
LL  
SCA  
CD  
RL/CG  
CE  
CH/CI  
DA  
Data signal rate selector (DTE/DCE source)  
Transmitter signal element timing (DTE source)  
TM  
Test mode  
14  
EIA-232-E Procedural Characteristics  
DTE  
Y
DCE  
X
DCE  
Y
DTE  
X
EIA-232  
EIA-232  
Signal GND (7)  
DTE ready (20)  
Signal GND (7)  
<- DTE ready (20)  
->  
<- DCE ready (6)  
-> carrier on  
<- clear to send (5)  
-> data send  
->  
-> EOT send  
->  
->  
DCE ready (6)  
carrier detect (8)  
->  
->  
Request to send(4)  
data send (2)  
send timing (24)  
EOT send (2)  
send timing (24)  
RTS off (4)  
data receive (3)  
receive timing (17)  
EOT receive (3)  
->  
->  
->  
->  
receive timing (17)  
error check  
->  
carrier off  
carrier off (8)  
-< CTS off (5)  
<- carrier detect (8)  
<- RTS (4)  
carrier on  
clear to send (5)  
->  
<- ACK message (3) modulated ACK MSG <- ACK message (2)  
<-receive timing (17)  
<- EOT received (3)  
<- receive timing (17)  
<- carrier off (8)  
<- send timing (24)  
<- EOT send (2)  
<- send timing (24)  
<-RTS off (4)  
modulate EOT send  
carrier off  
CTS off (5)  
15  
->  
Data Transmission Errors  
• Framing error: when a received  
character is improperly framed by the  
start and stop bits; it is set by the  
absence of stop bit.  
• Receive overrun: one or more  
characters in the data stream were lost.  
• Parity error: received character parity  
error.  
16  
Null Modem Connection  
When 2 DTEs are very close, no need to use modems to connect them.  
Pin Circuit name  
22 Ring indicator  
DTE X  
CE  
DTE Y  
CE  
CD  
CF  
CC  
CB  
CA  
BB  
BA  
DA  
DD  
AB  
20 Data terminal ready CD  
8
6
5
4
3
2
Data carrier detect CF  
Data set ready  
Clear to send  
Request to send  
Receive data  
Transmit data  
CC  
CB  
CA  
BB  
BA  
24 Transmitter timing DA  
17 Receiver timing  
Signal ground  
DD  
AB  
7
17  
Interfacing a μp with 232  
• Transmission:  
– Convert data from parallel to serial format  
– Add start, stop, and optional parity bits to  
the serial data.  
– Translate the voltage levels to those of the  
EIA-232-E standard. (transceiver chip: MAX  
232, MC145403, etc.)  
• Reception:  
– Translate the voltage levels of the incoming  
data stream to those used in the μp.  
– Detect the start and stop bits.  
– Optionally perform parity checking  
– Convert serial data into parallel format.  
18  
Sơ đồ khổi cổng nối tiếp của 8051  
19  
Các đặc tính của cổng nối tiếp 8051  
• Song công (ful-duplex)  
• Có đệm khi thu (bộ đệm 1 byte)  
• Có 4 chế độ làm việc (0 - 3)  
• Lập trình dễ dàng để:  
• Chọn tốc độ (cố định (on-chip OSC/12 hoặc OSC/64),  
hoặc thay đổi được (T1))  
• Chọn chế độ làm việc  
• Cho chạy (SCON)  
• Dễ sử dụng  
• Truyền dữ liệu:  
MOV SBUF, A  
• Nhận dữ liệu: MOV A, SBUF  
20  
Tải về để xem bản đầy đủ
pdf 39 trang myanh 21480 Free
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 805 (Phần 4) - Hồ Trung Mỹ", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pdfbai_giang_vi_xu_ly_chuong_3_ho_vi_dieu_khien_805_phan_4_ho_t.pdf