PIC18 LaurTec Library  3.3.1
Open Source C Library for PIC18 Microcontrollers based on C18 - XC8 Compilers
 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.1
5 
6 Created on Date : 08/09/2014
7 Last update : 15/12/2014
8 
9 CopyRight 2006-2014 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 MCP4822_H
45 #define MCP4822_H
46 
47 #define USE_OR_MASKS
48 #include <spi.h>
49 
50 #ifdef __XC8
51  #include <xc.h>
52 
53  #ifndef _PIC18
54  #error The MCP4822 Library supports only PIC18 devices
55  #endif
56 #endif
57 
58 #ifdef __XC8
59  #include <stdlib.h>
60  #define MCP4822_PULSE_DELAY _delay(1)
61 #endif
62 
63 #ifndef __XC8
64  #include <delays.h>
65  #define MCP4822_PULSE_DELAY Delay1TCY(1)
66 #endif
67 
68 
69 //**************************************************
70 // Pin initializations
71 //**************************************************
72 
73 //#define MCP4822_SDO_BIT 7
74 #define MCP4822_SDO_BIT 5
75 #define MCP4822_SDO_TRIS TRISC
76 #define MCP4822_SDO_PORT LATC
77 
78 //#define MCP4822_SCK_BIT 1
79 //#define MCP4822_SCK_TRIS TRISB
80 //#define MCP4822_SCK_PORT LATB
81 #define MCP4822_SCK_BIT 3
82 #define MCP4822_SCK_TRIS TRISC
83 #define MCP4822_SCK_PORT LATC
84 
85 #define MCP4822_CS_BIT 5
86 #define MCP4822_CS_TRIS TRISA
87 #define MCP4822_CS_PORT LATA
88 
89 #define MCP4822_LDAC_BIT 0
90 #define MCP4822_LDAC_TRIS TRISE
91 #define MCP4822_LDAC_PORT LATE
92 
93 
94 //**************************************************
95 // Constants
96 //**************************************************
97 #define MCP4822_DAC_A 0x00
98 #define MCP4822_DAC_B 0x80
99 
100 #define MCP4822_GAIN_1 0x20
101 #define MCP4822_GAIN_2 0x00
102 
103 #define MCP4822_OUT_DEFAULT_VALUE 0x00
104 
105 #define MCP4822_SHUTDOWN_ON 0x00
106 #define MCP4822_SHUTDOWN_OFF 0x10
107 
108 #define MCP4822_CLOCK_FOSC_64 SPI_FOSC_64
109 #define MCP4822_CLOCK_FOSC_16 SPI_FOSC_16
110 #define MCP4822_CLOCK_FOSC_4 SPI_FOSC_4
111 #define MCP4822_CLOCK_FOSC_TMR2 SPI_FOSC_TMR2
112 
113 
127 void MCP4822_initialize (unsigned char clock);
128 #define initialize_MCP4822 MCP4822_initialize
129 
130 
146 void MCP4822_set_value (unsigned int value, unsigned char channel);
147 #define set_value_MCP4822 MCP4822_set_value
148 
149 
164 void MCP4822_set_amplitude (unsigned int value, unsigned char channel);
165 #define set_amplitude_MCP4822 MCP4822_set_amplitude
166 
167 
178 void MCP4822_latch_pulse (void);
179 #define latch_pulse_MCP4822 MCP4822_latch_pulse
180 
181 
198 void MCP4822_set_options (unsigned char gain, unsigned char power, unsigned char channel);
199 #define set_options_MCP4822 MCP4822_set_options
200 
201 #endif