Settings - (Cuuduongthancong - Com)
Settings - (Cuuduongthancong - Com)
Settings - (Cuuduongthancong - Com)
Chuyên đề II
.c
Vi điều khiển và ứng dụng
ng
co
an
TS Nguyễn Hồng Quang
th
o ng
du
u
cu
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Khởi tạo dự án
om
.c
ng
co
an
th
o ng
du
u
cu
2
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Chương trình C đầu tiên
om
#include "p30f4011.h"
int counter; // for TRISB and PORTB declarations
.c
int main (void)
ng
{
co
counter = 1;
an
TRISB = 0; // configure PORTB for output
th
while(1) // do forever ng
{
o
PORTB = counter; // send value of „counter‟ out PORTB
du
counter++;
u
cu
}
return 0;
}
3
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Thêm file
om
*.gld
.c
Ví dụ: p30f4011.gld
ng
*.h
co
Ví dụ: p30f4011.h
an
th
o ng
du
u
cu
4
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Khởi đầu bit
om
_FOSC(CSW_FSCM_OFF & FRC_PLL4);
//Clock = 32 MHz
.c
ng
_FWDT(WDT_OFF);
co
_FBORPOR(MCLR_EN & PBOR_OFF &
an
PWMxL_ACT_HI & PWMxH_ACT_HI);
th
_FGS(CODE_PROT_OFF); ng
o
du
u
cu
5
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Oscillator configuration
register (FOSC)
om
.c
ng
The source can be the internal RC oscillator (FRC – internal fast RC oscillator,
LPRC – internal low power RC oscillator) or external oscillator (ERC – external RC
co
oscillator, XT – external quartz).
an
•FOS <1:0> - Definition of the clock
source.
th
ng
•11 - Primary oscillator selected by
o
FPR<3:0> 10 -Internal low power RC
du
oscillator
u
6
CuuDuongThanCong.com https://fb.com/tailieudientucntt
FPR
om
.c
ng
co
an
th
o ng
du
u
cu
7
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Watchdog timer (FWDT)
om
The basic clock 128kHz of the watchdog timer
.c
prescaler A and the second prescaler B.
ng
With this clock an 8-bit register, the register
co
reaches the maximum of 255, the watchdog timer
an
resets the microcontroller
th
o ng
du
u
cu
8
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Examples
om
.c
ng
co
an
th
o ng
du
u
cu
9
CuuDuongThanCong.com https://fb.com/tailieudientucntt
FWDT
om
.c
ng
co
an
th
o ng
du
u
cu
10
CuuDuongThanCong.com https://fb.com/tailieudientucntt
WDT algorthims
om
.c
ng
co
an
th
o ng
du
u
cu
11
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Voltage protection configuration
register (FBORPOR)
om
The configuration register of the voltage
protection serves (phục vụ)for defining the
.c
minimum value of the supply voltage
ng
co
switching on/off the circuit for reseting the
an
microcontroller if the supply voltage falls bellow
th
the specified value ng
adjustment of the PWM output
o
du
u
cu
12
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Register
om
.c
ng
co
an
th
o ng
du
u
cu
13
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Program memory protection
configuration register (FGS)
om
.c
ng
co
an
th
o ng
du
u
cu
14
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Parallel I/O (PIO) Ports
om
Data Direction bit is a „1‟, then the pin
.c
1. TRIS is an input and a „0‟ is output
ng
2. LAT All port pins are defined as inputs
co
3. PORT after a Reset.
an
Writes to the latch, write the latch
(LATx) th
o ng
The port (PORTx), read the port pins
du
u
cu
15
CuuDuongThanCong.com https://fb.com/tailieudientucntt
om
.c
ng
co
an
th
o ng
du
u
cu
16
CuuDuongThanCong.com https://fb.com/tailieudientucntt
om
.c
ng
co
an
th
o ng
du
u
cu
17
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Làm việc với bit
om
.c
ng
co
an
th
o ng
du
u
cu
18
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Analog pin
om
The use of the ADPCFG and TRIS registers
.c
control the operation of the A/D port pins.
ng
The port pins that are desired as analog inputs
co
must have their corresponding TRIS bit set
an
(input).
th
If the TRIS bit is cleared (output), the digital
ng
output level (VOH or VOL) will be converted.
o
du
u
cu
19
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Input Change Notification Module
The Input Change Notification module provides the dsPIC30F
om
devices the ability to generate interrupt on selected input pins.
.c
This module is capable of detecting input change-of-states even
ng
in Sleep mode, when the clocks are disabled.
co
There are 10 external signals (CN0 through CN7, CN17 and
CN18) that may be selected (enabled) for generating an interrupt
an
request on a change-of-state.
th
o ng
du
u
cu
20
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Ví dụ về LCD
om
.c
ng
co
an
th
o ng
du
u
cu
21
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Digital Input
om
.c
ng
co
an
th
o ng
du
u
cu
22
CuuDuongThanCong.com https://fb.com/tailieudientucntt
8.1.2 Sink or Source curent
om
.c
ng
co
an
th
o ng
du
u
cu
23
CuuDuongThanCong.com https://fb.com/tailieudientucntt
ng
om
.c
ng
co
an
th
o ng
du
i 26 mA
u
n 15 mA.
cu
ng 71 mA.
24
CuuDuongThanCong.com https://fb.com/tailieudientucntt
m
om
.c
ng
co
an
th
o ng
du
u
cu
25
CuuDuongThanCong.com https://fb.com/tailieudientucntt
ng IC TTL/CMOS
om
.c
ng
co
an
th
o ng
(5V) TTL, 0 to 1.5V ~ 0; Logic 1 ~3.5 to 5V.
du
74HC04 - CMOS
74ALS04 - TTL
26
CuuDuongThanCong.com https://fb.com/tailieudientucntt
om
.c
ng
co
an
th
o ng
du
u
cu
27
CuuDuongThanCong.com https://fb.com/tailieudientucntt
ng BJT
om
i DC?
.c
c MOSFET
ng
co
an
th
o ng
du
u
cu
28
CuuDuongThanCong.com https://fb.com/tailieudientucntt
ng PNP, NPN
om
.c
ng
co
an
th
o ng
du
u
cu
29
CuuDuongThanCong.com https://fb.com/tailieudientucntt
m
om
.c
ng
co
an
th
o ng
du
u
cu
30
CuuDuongThanCong.com https://fb.com/tailieudientucntt
t
om
.c
ng
ng
co
–
an
u Dalington
th
i 100A.
o ng
du
u
cu
31
CuuDuongThanCong.com https://fb.com/tailieudientucntt
n IR Led
om
i 100mA
.c
ng
1.5V
co
an
0.4V
th 33o
o ng
du
u
cu
32
CuuDuongThanCong.com https://fb.com/tailieudientucntt
IC driver
om
.c
p
ng
50VDC
co
an
th
ng n
1 μs.
o
du
n
“sink current”
u
cu
33
CuuDuongThanCong.com https://fb.com/tailieudientucntt
ng LED
om
.c
ng
co
an
th
o ng
du
u
cu
34
CuuDuongThanCong.com https://fb.com/tailieudientucntt
n
om
.c
ng
co
an
th
o ng
du
u
cu
35
CuuDuongThanCong.com https://fb.com/tailieudientucntt
c
om
ng SSR (Solid state relay)
.c
n
ng
co
an
th
o ng
du
u
cu
36
CuuDuongThanCong.com https://fb.com/tailieudientucntt
mạch cách ly
om
.c
ng
co
an
th
o ng
du
u
cu
37
CuuDuongThanCong.com https://fb.com/tailieudientucntt