LTlib LaurTec Library
4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
MCP4822.h
Go to the documentation of this file.
1
/*******************************************************************************
2
3
Author : Mauro Laurenti
4
Version : 1.3
5
6
Created on Date : 08/09/2014
7
Last update : 16/03/2016
8
9
CopyRight 2006-2015 all rights are reserved
10
11
********************************************************
12
SOFTWARE LICENSE AGREEMENT
13
********************************************************
14
15
The usage of the supplied software imply the acceptance of the following license.
16
17
The software supplied herewith by Mauro Laurenti (the Author) is intended for
18
use solely and exclusively on Microchip PIC Microcontroller (registered mark).
19
The software is owned by the Author, and is protected under applicable
20
copyright laws. All rights are reserved.
21
Any use in violation of the foregoing restrictions may subject the
22
user to criminal sanctions under applicable laws, as well as to civil liability
23
for the breach of the terms and conditions of this license.
24
Commercial use is forbidden without a written acknowledgement with the Author.
25
Personal or educational use is allowed if the application containing the
26
following software doesn't aim to commercial use or monetary earning of any kind.
27
28
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
29
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
30
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
32
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
33
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
34
35
36
********************************************************
37
PURPOSES
38
********************************************************
39
40
This library allows the usage of the MCP4822 DAC.
41
42
*******************************************************************************/
43
44
#ifndef LTLIB_MCP4822_H
45
#define LTLIB_MCP4822_H
46
47
#ifdef __XC8
48
#include <xc.h>
49
#endif
50
51
//*****************************************
52
// Library Test
53
//*****************************************
54
#include "
LTlib.h
"
55
56
#ifndef LTLIB_SPI_MODULE_H
57
#error The MCP4822 Library requires the "module_SPI" library to be included.
58
#endif
59
60
61
//*****************************************
62
// SPI Module Switch
63
//*****************************************
64
#if defined (MCP4822_SPI_MODULE_1) || defined (MCP4822_SPI_MODULE_2)
65
66
#else
67
#define MCP4822_SPI_MODULE_1
68
#endif
69
70
71
#ifdef MCP4822_SPI_MODULE_1
72
#define MCP4822_SPI_open SPI1_open
73
#define MCP4822_SPI_baudrate SPI1_baudrate
74
#define MCP4822_SPI_mode SPI1_mode
75
#define MCP4822_SPI_write_byte SPI1_write_byte
76
#define MCP4822_SPI_read_byte SPI1_read_byte
77
#endif
78
79
#ifdef MCP4822_SPI_MODULE_2
80
#define MCP4822_SPI_open SPI2_open
81
#define MCP4822_SPI_baudrate SPI2_baudrate
82
#define MCP4822_SPI_mode SPI2_mode
83
#define MCP4822_SPI_write_byte SPI2_write_byte
84
#define MCP4822_SPI_read_byte SPI2_read_byte
85
#endif
86
87
//**************************************************
88
// Device Settings
89
//**************************************************
90
91
#ifdef _PIC18
92
//CS pin
93
#define MCP4822_CS_TRIS TRISAbits.RA5
94
#define MCP4822_CS_PORT LATAbits.LATA5
95
96
//LAT pin
97
#define MCP4822_LDAC_TRIS TRISEbits.RE0
98
#define MCP4822_LDAC_PORT LATEbits.LATE0
99
#endif
100
101
#ifndef _PIC18
102
//CS pin
103
#define MCP4822_CS_TRIS TRISAbits.TRISA5
104
#define MCP4822_CS_PORT PORTAbits.RA5
105
106
//LAT pin
107
#define MCP4822_LDAC_TRIS TRISEbits.TRISE0
108
#define MCP4822_LDAC_PORT PORTEbits.RE0
109
#endif
110
111
//**************************************************
112
// Constants
113
//**************************************************
114
115
#define MCP4822_PULSE_DELAY _delay(1)
116
117
#define MCP4822_DAC_A 0x00
118
#define MCP4822_DAC_B 0x80
119
120
#define MCP4822_GAIN_1 0x20
121
#define MCP4822_GAIN_2 0x00
122
123
#define MCP4822_OUT_DEFAULT_VALUE 0x00
124
125
#define MCP4822_SHUTDOWN_ON 0x00
126
#define MCP4822_SHUTDOWN_OFF 0x10
127
128
#define MCP4822_CLOCK_FOSC_64 SPI_CLK_OSC_64
129
#define MCP4822_CLOCK_FOSC_16 SPI_CLK_OSC_16
130
#define MCP4822_CLOCK_FOSC_4 SPI_CLK_OSC_4
131
#define MCP4822_CLOCK_FOSC_TMR2 SPI_TIMER_OUT_CLK
132
133
#define MCP4822_CS_DISABLED 0x01
134
#define MCP4822_CS_ENABLED 0x00
135
136
#define MCP4822_LDAC_DISABLED 0x01
137
#define MCP4822_LDAC_ENABLED 0x00
138
152
void
MCP4822_initialize
(
unsigned
char
clock);
153
#define initialize_MCP4822 MCP4822_initialize
154
155
171
void
MCP4822_set_value
(
unsigned
int
value,
unsigned
char
channel);
172
#define set_value_MCP4822 MCP4822_set_value
173
174
189
void
MCP4822_set_amplitude
(
unsigned
int
value,
unsigned
char
channel);
190
#define set_amplitude_MCP4822 MCP4822_set_amplitude
191
192
203
void
MCP4822_latch_pulse
(
void
);
204
#define latch_pulse_MCP4822 MCP4822_latch_pulse
205
206
223
void
MCP4822_set_options
(
unsigned
char
gain,
unsigned
char
power,
unsigned
char
channel);
224
#define set_options_MCP4822 MCP4822_set_options
225
226
#endif
LTlib_v_4.0.3
inc
MCP4822.h
Generated on Wed Aug 3 2016 19:57:31 for LTlib LaurTec Library by
1.8.3.1