PIC24_DOG
Hauptseite
Dateien
Auflistung der Dateien
Datei-Elemente
user.c
gehe zur Dokumentation dieser Datei
1
/******************************************************************************/
2
/* Files to Include */
3
/******************************************************************************/
4
5
/* Device header file */
6
#if defined(__XC16__)
7
#include <xc.h>
8
#elif defined(__C30__)
9
#if defined(__PIC24E__)
10
#include <p24Exxxx.h>
11
#elif defined (__PIC24F__)||defined (__PIC24FK__)
12
#include <p24Fxxxx.h>
13
#elif defined(__PIC24H__)
14
#include <p24Hxxxx.h>
15
#endif
16
#endif
17
18
#include <stdint.h>
/* For uint32_t definition */
19
#include <stdbool.h>
/* For true/false definition */
20
21
#include "
user.h
"
/* variables/params used by user.c */
22
#include <pps.h>
23
24
/******************************************************************************/
25
/* User Functions */
26
/******************************************************************************/
27
28
/* <Initialize variables in user.h and insert code for user algorithms.> */
29
30
/* TODO Initialize User Ports/Peripherals/Project here */
31
32
void
InitApp
(
void
)
33
{
34
/******************************************************************************/
35
/* Assigning PPS function */
36
/******************************************************************************/
37
PPSUnLock;
// unlock registers
38
39
// Set the PINs for SPI1
40
// Assign SCK1 to RP10, Pin 21 - OUTPUT
41
PPSOutput(OUT_FN_PPS_SCK1,OUT_PIN_PPS_RP10);
42
43
// Assign SDO1 to RP11, Pin 22 - OUTPUT
44
PPSOutput(OUT_FN_PPS_SDO1, OUT_PIN_PPS_RP11);
45
46
PPSLock;
// lock registers
47
48
/******************************************************************************/
49
/* Setup analog functionality and port direction */
50
/******************************************************************************/
51
LATA = 0x0000;
// set latch levels
52
TRISA = 0x0000;
// set IO as outputs
53
LATB = 0x0000;
// set latch levels
54
TRISB = 0x0000;
55
56
57
/******************************************************************************/
58
/* Initialize peripherals SPI */
59
/******************************************************************************/
60
IFS0bits.SPI1IF = 0;
// Clear the Interrupt flag
61
IEC0bits.SPI1IE = 0;
// Disable the interrupt
62
63
// SPI1CON1 Register Settings
64
SPI1CON1bits.DISSCK = 0;
// Internal serial clock is enabled
65
SPI1CON1bits.DISSDO = 0;
// SDOx pin is controlled by the module
66
SPI1CON1bits.MODE16 = 0;
// Communication is byte-wide (8 bits)
67
SPI1CON1bits.MSTEN = 1;
// Master mode enabled
68
SPI1CON1bits.SMP = 0;
// Inputdata is sampled at the middle of data
69
// output time
70
SPI1CON1bits.CKE = 0;
// Serial output data changes on transition from
71
// Idle clock state to active clock state
72
SPI1CON1bits.CKP = 0;
// Idle state for clock is a low level;
73
// active state is a high level
74
SPI1STATbits.SPIEN = 1;
// Enable SPI module
75
76
// Interrupt Controller Settings
77
IFS0bits.SPI1IF = 0;
// Clear the Interrupt flag
78
// IEC0bits.SPI1IE = 1; // Enable the interrupt
79
80
81
82
83
}
84
InitApp
void InitApp(void)
Definition:
user.c:32
user.h
trunk
pic24_c_DOG.X
user.c
Erzeugt am Don Mär 12 2015 21:59:30 für PIC24_DOG von
1.8.9.1