Professional Documents
Culture Documents
Day - 3 - Input and Output Ports - en - 1696772874
Day - 3 - Input and Output Ports - en - 1696772874
WORKDAYS
Welcome to the training
days for the PIC16F887!
Day 1: The Programming Language in C
On Day 1, we will cover the programming language in C.
Day 5: INTERRUPT
Prepare to dive into interrupts on Day 5.
OVERVIEW OF WORKDAYS
WORKDAYS OVERVIEW
Welcome!
Tên: Elec
Name: Elec
Tuổi: có danh nhưng chưa có tuổi Tên: 2PP
Tính tình: Hay bắt bẻ, thích làm Name: 2PP
khó học viên, thích đặt câu hỏi, Tuổi: giống thằng
Age: has a reputation but not yet trên :v
old. Personality: Likes to Age: same as the guy
challenge, enjoys making it above :v
difficult for students, likes to ask Tính tình: Dễ tính,
questions, likes to twist things hiền khô, thích giúp
around, likes puzzles! đỡ học viên, thích
thích vặn vẹo, thích thách đố! Personality:
Likes to challenge, enjoys Easygoing, kind-
making it difficult for students, hearted, enjoys
likes to twist things around, likes helping students,
puzzles! likes being praised,
appreciates feedback. BUT we know what we need to do to
được tung hô, thích cảm ơn, thích make the reading materials at
được Feedback Elec2PCB.com easier to understand,
Enjoys being praised, appreciates more intuitive, and closely aligned with
gratitude, likes receiving feedback. each topic.
tiết, tạo sự phấn khích, sự nghi ngờ, sự
“Xin chào các bạn! tìm tòi, sự hiếu kì cho các bạn!
Tớ là Elec và tớ là 2PP We aim to create excitement, curiosity,
I'm Elec and I'm 2PP. and a sense of exploration for you!
Bọn tớ được tạo ra từ Elec2PCB.com Bọn tớ có
nhiệm vụ vô cùng vô cùng ... Nhớ nhé! Chúng tớ được tạo ra là để
We were created by Elec2PCB.com. Our mission is Remember! We were created to help you
extremely important... study more effectively. "
... Vô cùng gì nhỉ :v :v giúp các bạn học bài có hiệu quả hơn. “
... Extremely important, huh? :v :v "&
Tiếng Anh:
English:
1. https://www.mikroe.com/ebooks/pic-microcontrollers-
programming-in-c
2. https://forum.mikroe.com/
3. Tim Bailey, An Introduction to the C Programming
6
Language and Software Design, 2005
Tim Bailey, An Introduction to the C Programming
Language and Software Design, 2005
4. Jones and Bartlett, An Introduction to the C Programming
Jones and Bartlett, An Introduction to the C Programming
Language and Software Design, 2021
Language and Software Design, 2021
7
Nội dung
1. Tín hiệu số và tương tự
Digital and Analog Signals
2. Khi nào là Input hay Output
When is it Input or Output?
3. Sơ đồ khối chức năng
Block Diagram of Functions
4. Một số thanh ghi liên quan
8
Some Related Registers
5. Một số chương trình mẫu
Some sample programs
6. Một số mạch phần cứng mẫu
Some sample hardware circuits
9
1. Tín hiệu số và tương tự
Phân biệt tín hiệu số và tương tự
Differentiating between digital and analog signals
8
1. Tín hiệu số và tương tự
Quá trình chuyển đổi giữa tín hiệu tương tự và số
The process of converting between analog and digital
signals
9
1. Tín hiệu số và tương tự
Mức logic của tín hiệu số cho TTL
Logic levels of digital signals for TTL
10
1. Tín hiệu số và tương tự
11
1. Tín hiệu số và tương tự
Chú ý sự tương thích về mức điện áp logic
Pay attention to the compatibility of logic voltage
levels
12
13
2. Khi nào là Input hay Output
14
2. Khi nào là Input hay Output
Xét ví dụ
Consider an example
can
you
find an
error in
this
picture
?
15
3. Sơ đồ khối chức năng
Pin Diagrams
Pin Diagrams
16
3. Sơ đồ khối chức năng
Block Diagram
Block Diagram
17
3. Sơ đồ khối chức năng
Block Diagram (tt)
Block Diagram (tt)
18
4. Một số thanh ghi liên quan
19
4. Một số thanh ghi liên quan
ANSELx: ANALOG SELECT REGISTER
ANSELx: ANALOG SELECT REGISTER
21
4. Một số thanh ghi liên quan
Lưu ý!
Note!
22
4. Một số thanh ghi liên quan
23
4. Một số thanh ghi liên quan
PORTx và TRISx
PORTx and TRISx
22
22
4. Một số thanh ghi liên quan
PORTx và TRISx
PORTx and TRISx
24
4. Một số thanh ghi liên quan
OPTION_REG Register
OPTION_REG Register
25
4. Một số thanh ghi liên quan
WEAK PULL-UP PORTB REGISTER
WEAK PULL-UP PORTB REGISTER
All the port PORTB pins have built in pull-up resistors, which makes them
ideal for connecting to push buttons (keyboard), switches or optocouplers.
In order to connect these resistors to the PORTB pins, the appropriate bit
of the WPUB register should be set
All the port PORTB pins have built-in pull-up resistors, making them ideal
for connecting to push buttons, switches, or optocouplers. To connect these
resistors to the PORTB pins, set the appropriate bit of the WPUB register.
in configured as an output 26
Note
Note
1: Global RBPU bit of the OPTION register must be cleared for
individual pull-ups to be enabled.
1: The global RBPU bit of the OPTION register must be cleared for
individual pull-ups to be enabled.
2: The weak pull-up device is automatically disabled if the pin is
2: The weak pull-up device is automatically disabled if the pin is.
in configured as an output 27
4. Một số thanh ghi liên quan
28
5. Một số chương trình mẫu
Xét 2 yêu cầu sau:
Consider the following two requirements:
1. Configure all pin of PORTA are output
TRISA = 0x00;
PORTA = 0b10010110;
TRISA = 0x80;
If(PORTA.RA7 == 1)
…….
2. Configure pin 7 of PORTA is input
else
And then check value logic at there
……
29
Set pin 7 of PORTA as input and then
check the logic value there.
30
5. Một số chương trình mẫu
Giải pháp chống dội cho nút bấm:
Anti-bounce solution for button:
31
5. Một số chương trình mẫu
Thuật toán tối ưu?
Optimal algorithm?
33
5. Một số chương trình mẫu
Bài 3.1: Nhấp nháy LED
Exercise 3.1: Blinking LED
34
5. Một số chương trình mẫu
Bài 3.2: Nút bấm và LED
Exercise 3.2: Button and LED
35
5. Một số chương trình mẫu
Bài 3.3: Đếm 0-9 trên 1 LED 7 đoạn
Exercise 3.3: Counting 0-9 on a 7-segment LED
display
36
37
5. Một số chương trình mẫu
Bài 3.4: Hiển thị 1234 trên 4 LED 7 đoạn
Exercise 3.4: Display 1234 on 4 seven-segment
LEDs.
38
39
5. Một số chương trình mẫu
Bài 3.5 : Đếm 0 lên 9999 trên 4 LED 7 đoạn
Exercise 3.5: Count from 0 to 9999 on 4 seven-
segment LEDs.
40
41
5. Một số chương trình mẫu
Bài 3.6 : Bấm nút tăng giảm số trên 1 LED 7 đoạn
Exercise 3.6: Press the button to increase or decrease the
number on a single seven-segment LED.
42
5. Một số chương trình mẫu
Bài 3.7 : Bấm nút tăng giảm số trên 4 LED 7 đoạn
Exercise 3.7: Press the button to increase or decrease the
number on 4 seven-segment LEDs.
43
6. Một số mạch phần cứng mẫu
Mạch mô phỏng - Khối mạch LED và LED 7SEG
Circuit simulation - LED circuit and 7-segment LED.
44
6. Một số mạch phần cứng mẫu
Mạch mô phỏng - Khối mạch nút bấm
Circuit simulation - Button circuit.
38
38
6. Một số mạch phần cứng mẫu
Mạch ứng dụng số 1
Application circuit number 1.
39
6. Một số mạch phần cứng mẫu
Mạch ứng dụng số 2
Application circuit number 2.
40
6. Một số mạch phần cứng mẫu
Mạch ứng dụng số 3
Application circuit number 3.
41
42
6. Một số mạch phần cứng mẫu
Mạch ứng dụng số 4
Application circuit number 4
43
6. Một số mạch phần cứng mẫu
Mạch ứng dụng số 5
Application circuit number 5
44
Câu hỏi và góp ý?
“Bạn có chỗ còn chưa được hiểu rõ,
hoặc bạn muốn tìm hiểu sâu thêm
"If you have any unclear points or if
you want to learn more deeply about
any issues in this lecture, please
inform us so that we can know!"
bất kỳ vấn đề nào trong bài giảng này,
Vậy bạn hãy thông tin ngay đến bọn tớ
để bọn tớ được biết nhé!”
"You can discuss with us on the
Fanpage
“Bạn có thể trao đổi với bọn tớ tại Fanpage
https://www.facebook.com/elec2pcb/
Hoặc tại Group
Or in the Group
https://www.facebook.com/groups/elec2pcb/”
"
“Với mong muốn các khoá học tại Elec2PCB.com ngày một hoàn thiện hơn
về nội dung lẫn phương thức truyền đạt đến các bạn. Bọn tớ rất mong bạn
cho ý kiến phản hồi liên quan về nội dung bài học, chất lượng bài giảng và
video ...
"With the desire for courses at Elec2PCB.com to be continuously improved
in terms of content and teaching methods for you. We really hope to receive
feedback related to the lesson content, lecture quality, and videos ...
Mọi ý kiến đóng góp xin gửi về: bạn nhé!
elec2pcb@gmail.comPlease send all feedback and suggestions to:
& 44
& 44
https://elec2pcb.com/dang-ky/
45
Website
Website
46
Website: elec2pcb.com - Email: - Mobile: 0905 912 019
elec2pcb@gmail.comWebsite: elec2pcb.com - Email: - Mobile: 0905 912 019
47
Facebook
Facebook
48
https://www.facebook.com/Hoc.Altium.online/
49
FanPage
FanPage
https://www.facebook.com/elec2pcb/ 50
https://www.facebook.com/groups/elec2pcb/ 51
https://www.facebook.com/groups/altium.designer.vietnam
52
53
Số Zalo hỗ trợ giải đáp thắc mắc trong và sau khi học
0905.912.019 54
Zalo number for support and answering questions during and after studying.
0905.912.019 55