Sie sind auf Seite 1von 67

PIC24HJ256GP210

Prajin Palangsantikul
presentation v0.01
Date 2015/09/23

PIC24HJ256GP210
USB

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

PIC24 Programming
Include Head file (.h)
#include <p24Hxxxx.h>

Configuration Bits
C:\Program Files(x86)\Microchip\xc16\v1.24\
docs\ config_docs\24HJ256GP210.htm

Configure Oscillator Clock


oscConfig()
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

1.I/O Ports: What?

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

1.I/O Ports: What?


Parallel I/O (PIO) Ports
The voltage on a digital input pin can be between 0.3V to 5.6V

Open-Drain Configuration
This is controlled by the Open-Drain Control
register, ODCx, associated with each port.
The open-drain feature allows the generation of
outputs higher than VDD(e.g., 5V) on any desired
digital only pins by using external pull-up resistors
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

1.I/O Ports: What?


Configuring Analog Port Pins
The use of the ADxPCFGH, ADxPCFGL and TRIS
registers control the operation of the Analog-to-Digital
port pins.

I/O Port Write/Read Timing


One instruction cycle is required between a port
direction change or port write operation and a read
operation of the same port. Typically, this instruction
would be a NOP.

Input Change Notification


9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

1.I/O Ports: What?


Input Change Notification
Depending on the device pin count, there are up
to 24 external signals (CN0 through CN23) that
can be selected (enabled) for generating an
interrupt request on a change-of-state.
There are four control registers associated with
the CN module.
The CNEN1 and CNEN2
The CNPU1 and CNPU2
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

1.I/O Ports: Control Register

TRISx: Data Direction register


PORTx: I/O Port register
LATx: I/O Latch register
ODCx: Open-Drain control register
The open-drain feature allows the generation of
outputs higher than VDD(e.g., 5V) on any desired
digital only pins by using external pull-up resistors.

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

10

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

11

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

12

1.I/O Ports: The Change Notification (CN) pins

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

13

1.I/O Ports: CN Configuration and Operation


1.
2.
3.
4.
5.

Set TRISx, digital input


Set CEN1/CEN2, Enable Interrupt
Set CNPU1/CNPU2, On the weak pull-up
Clear CNIF (IFSx register), Clear interrupt flag
Select CNIP<2:0> (IPCx register), Interrupt
priority
6. Set CNIE (IECx register), Enable Interrupt
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

14

1.I/O Ports: Peripheral Libraries


C:\Program Files (x86)\Microchip\xc16\v1.24\
docs\periph_libs\16-bit Peripheral
Libraries.htm

PIC24H

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

15

1.I/O Ports: Examples


Input/Output
LAB_02_Blink.C
LAB_02_SW.C

Output
Input

Input Change Notification (Interrupt)


LAB_04_CN5_6.C

CNx

External Interrupt
LAB_04_INT3.C

9/23/2015

INTx

Prajin Palangsantikul (www.appsofttech.com)

16

LAB_04_CN5_6
(RB3/CN5, RB4/CN6)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

17

LAB_04_INT3
(RA14/INT3)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

18

2.Timers
Type A timer
Timer1

Type B timer
Timer2, Timer4, Timer6 and Timer8

Type C timer
Timer3, Timer5, Timer7 and Timer9

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

19

2.Timers: Control Register


TMRx
16-bit Timer Count register

PRx
16-bit Timer Period register associated with the
timer

TxCON
16-bit Timer Control register associated with the
timer
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

20

2.Timers: Interrupt Control Register


Interrupt Enable Control bit (TxIE)
Interrupt Flag Status bit (TxIF)
Interrupt Priority Control bits (TxIP<2:0>)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

21

2.Timers: Type A Timer

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

22

2.Timers: Type B Timer

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

23

2.Timers: Type C Timer

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

24

2.Timers: Timer1 (Type A Timer)


Timer1 operate in three modes
16-bit Timer
16-bit Synchronous Counter
16-bit Asynchronous Counter

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

25

2.Timers: Type A Timer Control Register


T1CON register

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

26

2.Timers: Tick
T =
1/f
=
1/(FOSC/2)/prescale value
=
1/(40MHz/2)/256
=
0.013 ms
1ms?
0.013ms =
1 Tick
1ms
=
1/0.013
=
76
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

27

2.Timers: To configure Timer1 for operation


1. Set the TON bit (= 1) in the T1CON register.
2. Select the timer prescaler ratio using the TCKPS<1:0> bits in
the T1CON register.
3. Set the Clock and Gating modes using the TCS and TGATE
bits in the T1CON register.
4. Set or clear the TSYNC bit in T1CON to select synchronous or
asynchronous operation.
5. Load the timer period value into the PR1 register.
6. If interrupts are required, set the interrupt enable bit, T1IE.
Use the priority bits, T1IP<2:0>, to set the interrupt priority.

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

28

2.Timers: 16-Bit Timer1


Timer Mode
LAB_05_Timer.c

Counter Mode
LAB_05_Counter.c

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

29

2.Timers: Type B/Type C

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

30

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

31

2.Timers: 32-Bit Timer Access

the most significant word (msw)


the least significant word (lsw)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

32

2.Timers: 32-Bit Timer


Timer Mode
LAB_05_Timer32.c

Counter Mode
LAB_05_Counter32.c

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

33

3. 10-Bit Analog-to-Digital Converter (ADC)


The PIC24H family devices have up to 32 A/D
input channels.
These devices also have up to two ADC
modules (ADCx, where x = 1 or 2), each with
its own set of Special Function Registers
(SFRs).

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

34

3. 10-Bit Analog-to-Digital Converter (ADC)


The 10-bit or 12-bit Operation Mode (AD12B)
bit in the ADCx Control 1(ADxCON1) register
allows each of the ADC modules to be
configured by the user application as either a
10-bit, 4 Sample/Hold (S/H) ADC (default
configuration) or a 12-bit, 1 Sample/Hold ADC.

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

35

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

36

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

37

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

38

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

39

LAB_07_ADC_AN2.c
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

40

4.Input Capture

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

41

4.Input Capture: Input Capture Event Generation

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

42

4.Input Capture: Timer Value Capture

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

43

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

44

4.Input Capture: Example


Input Capture
LAB_08_InputCapture.C

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

(See: Figure12-5)

45

5.Output Compare

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

46

5.Output Compare: operating modes

Active Low One-Shot mode


Active High One-Shot mode
Toggle mode
Delayed One-Shot mode
Continuous Pulse mode
PWM mode
without fault protection
with fault protection

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

47

5.Output Compare:

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

48

5.Output Compare: Output Compare Registers


OCxCON
Output Compare Control register

OCxR
Output Compare register

OCxRS
Secondary Output Compare register

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

49

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

50

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

51

5.Output Compare: Examples


Toggle mode (See: Figure13-5)
LAB_09_OutputCompare_Toggle.C

PWM mode without fault protection


(See: Figure13-12)
LAB_09_OutputCompare_PWM.C

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

52

6. Serial Peripheral Interface (SPI)


The SPI module is a full duplex synchronous
serial interface useful for communicating with
other peripherals or microcontrollers in
master/slave relationship and it can transfer
data over short distances at high speeds.

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

53

6. Serial Peripheral Interface (SPI)


The peripheral devices may be serial
EEPROMs, shift registers, display drivers,
analog-to-digital converters, etc.
The SPI module is compatible with Motorolas
SPI and SIOP interfaces.

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

54

6. Serial Peripheral Interface (SPI)


The SPI serial interface consists of four pins,
which are further sub-divided into data and
control lines:
Data lines:
MOSI Master Data Output, Slave Data Input
MISO Master Data Input, Slave Data Output

Control lines:
SCLK Serial Clock
/SS Slave Select (no addressing)
9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

55

6. Serial Peripheral Interface (SPI)

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

56

LAB_10_74HC595.c

PIC24H
74HC595
------------------------------SDO1/RF8 -> DS pin
SCK1/RF6 -> SH_CP pin
RF5
-> ST_CP pin

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

57

LAB_10_74HC595.c

PIC24H
SDO1/RF8
RF5
SCK1/RF6

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

58

7. Inter-Integrated Circuit I2C

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

59

7. Inter-Integrated Circuit I2C

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

60

7. Inter-Integrated Circuit I2C


256K I2C Serial EEPROM

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

61

7. Inter-Integrated Circuit I2C


EEPROM 24LCxxxx
24LCxxxx

PCF8574
PCF
8574A
A I/O expander

PCF8591
PCF
8591 8
8bit
bit A/D and D/A
DS
DS1307
1307 RealReal-Time Clock

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

62

LAB_11_PCF8574A.c

PIC24 PCF8574A
-------------------------xx ->
SDA
xx ->
SCL

P0-P7 LED 8

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

63

LAB_11_PCF8574A.c

PIC24H
xx
xx

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

64

SD card/FAT32 ()

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

65

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

66

Ref.
www.microchip.com
PIC24HJXXXGP-X06-X08-X10 datasheet
ETT manPIC32-START-KIT manual

9/23/2015

Prajin Palangsantikul (www.appsofttech.com)

67

Das könnte Ihnen auch gefallen