Tải bản đầy đủ (.ppt) (37 trang)

Vi điều khiển và ứng dụng

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (558.93 KB, 37 trang )

Chuyên đề II
Vi điều khiển và ứng dụng
TS Nguyễn Hồng Quang


Khởi tạo dự án

2


Chương trình C đầu tiên
#include "p30f4011.h"
int counter; // for TRISB and PORTB declarations
int main (void)
{
counter = 1;
TRISB = 0; // configure PORTB for output
while(1) // do forever
{
PORTB = counter; // send value of ‘counter’ out PORTB
counter++;
}
return 0;
}
3


Thêm file


*.gld


 Ví dụ: p30f4011.gld

 *.h
 Ví dụ: p30f4011.h

4


Khởi đầu bit
 _FOSC(CSW_FSCM_OFF & FRC_PLL4);

//Clock = 32 MHz
 _FWDT(WDT_OFF);
 _FBORPOR(MCLR_EN & PBOR_OFF &
PWMxL_ACT_HI & PWMxH_ACT_HI);
 _FGS(CODE_PROT_OFF);

5


Oscillator configuration
register (FOSC)
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
oscillator, XT – external quartz).
•FOS <1:0> - Definition of the clock
source.
•11 - Primary oscillator selected by
FPR<3:0> 10 -Internal low power RC
oscillator

•01 -Internal fast RC oscillator
•00 - Low power 32kHz internal
oscillator (timer 1)

6


FPR

7


Watchdog timer (FWDT)
 The basic clock 128kHz of the watchdog

timer
 prescaler A and the second prescaler B.
 With this clock an 8-bit register, the
register reaches the maximum of 255, the
watchdog timer resets the microcontroller

8


Examples

9


FWDT


10


WDT algorthims

11


Voltage protection configuration
register (FBORPOR)
 The configuration register of the voltage

protection serves (phục vụ)for defining the
minimum value of the supply voltage
 switching on/off the circuit for reseting the
microcontroller if the supply voltage falls
bellow the specified value
 adjustment of the PWM output

12


Register

13


Program memory protection
configuration register (FGS)


14


Parallel I/O (PIO) Ports
 1. TRIS
 2. LAT
 3. PORT

15

 Data Direction bit is a ‘1’, then

the pin is an input and a ‘0’ is
output
 All port pins are defined as inputs
after a Reset.
 Writes to the latch, write the
latch (LATx)
 The port (PORTx), read the port
pins


16


17


Làm việc với bit


18


Analog pin
 The use of the ADPCFG and TRIS registers

control the operation of the A/D port pins.
 The port pins that are desired as analog
inputs must have their corresponding TRIS
bit set (input).
 If the TRIS bit is cleared (output), the digital
output level (VOH or VOL) will be
converted.

19


Input Change Notification Module
 The Input Change Notification module provides the

dsPIC30F devices the ability to generate interrupt on
selected input pins.
 This module is capable of detecting input change-ofstates even in Sleep mode, when the clocks are
disabled.
 There are 10 external signals (CN0 through CN7, CN17
and CN18) that may be selected (enabled) for
generating an interrupt request on a change-of-state.

20



Ví dụ về LCD

21


Ví dụ về Digital Input

22


8.1.2 Sink or Source curent

23


Bộ đệm dùng IC chuyên dụng

 P0 chỉ chịu dòng tới 26 mA
 P1, P2 and P3 giới hạn 15 mA.
 8051 chỉ chịu dòng 71 mA.
24


Các loại IC đệm

25



×