libpic170x  0.2
Ease of use library for PIC16(L)1705/1709 chips
freq.h
Go to the documentation of this file.
1 /*
2  Copyright 2018 Paul Konstantin Gerke
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
67 #ifndef FREQ_H
68 #define FREQ_H
69 
70 #include <stdint.h>
71 #include <stdbool.h>
72 #include <string.h>
73 
74 #ifndef _XTAL_FREQ
75 #error "_XTAL_FREQ must be set to a valid value"
76 #endif
77 
78 #ifdef __LIBPIC170X_DOXYGEN
79  #define OSCCON_BITS 0
81  #define __LIBPIC170X_DEVICE_NAME "PIC16LF1705"
83 #endif
84 
85 #if _XTAL_FREQ == 32000000
86  #define OSCCON_BITS 0b11110010
87 
88  #define TIMER0_MS_INC 8
89  #define TIMER0_US_INC 192
90  #define TIMER0_PRESCALE_BITS 0x07
91 #elif _XTAL_FREQ == 16000000
92  #define OSCCON_BITS 0b01111010
93 
94  #define TIMER0_MS_INC 16
95  #define TIMER0_US_INC 384
96  #define TIMER0_PRESCALE_BITS 0x07
97 #elif _XTAL_FREQ == 8000000
98  #define OSCCON_BITS 0b01110010
99 
100  #define TIMER0_MS_INC 32
101  #define TIMER0_US_INC 768
102  #define TIMER0_PRESCALE_BITS 0x07
103 #elif _XTAL_FREQ == 4000000
104  #define OSCCON_BITS 0b01101010
105 
106  #define TIMER0_MS_INC 65
107  #define TIMER0_US_INC 536
108  #define TIMER0_PRESCALE_BITS 0x07
109 #elif _XTAL_FREQ == 2000000
110  #define OSCCON_BITS 0b01100010
111 
112  #define TIMER0_MS_INC 131
113  #define TIMER0_US_INC 072
114  #define TIMER0_PRESCALE_BITS 0x07
115 #elif _XTAL_FREQ == 1000000
116  #define OSCCON_BITS 0b01011010
117 
118  #define TIMER0_MS_INC 131
119  #define TIMER0_US_INC 072
120  #define TIMER0_PRESCALE_BITS 0x06
121 #elif _XTAL_FREQ == 500000
122  #define OSCCON_BITS 0b00111010
123 
124  #define TIMER0_MS_INC 131
125  #define TIMER0_US_INC 072
126  #define TIMER0_PRESCALE_BITS 0x05
127 #else
128  #if _XTAL_FREQ < 500000
129  #error "Invalid frequency (frequencies < 500kHz not supported)"
130  #else
131  #error "Invalid frequency"
132  #endif
133 #endif
134 
135 #ifdef _16LF1705
136  #define __LIBPIC170X_DEVICE_NAME "PIC16LF1705"
137 #elif _16F1705
138  #define __LIBPIC170X_DEVICE_NAME "PIC16F1705"
139 #elif _16LF1709
140  #define __LIBPIC170X_DEVICE_NAME "PIC16ÖF1709"
141 #elif _16F1709
142  #define __LIBPIC170X_DEVICE_NAME "PIC16F1709"
143 #else
144  #error "Unsupported chip"
145 #endif
146 
148 extern const uint32_t __LIBPIC170X_BUILT_XTAL_FREQ;
150 extern const char* __LIBPIC170X_BUILT_DEVICE_NAME;
151 
168  return
171 }
172 
173 #endif /* FREQ_H */
174 
#define __LIBPIC170X_DEVICE_NAME
Processor name internally used by libpic170x_check_library_build_arguments()
Definition: freq.h:82
const char * __LIBPIC170X_BUILT_DEVICE_NAME
Stores the device name (as string) used to build the static libpic170x library.
Definition: freq.c:4
#define _XTAL_FREQ
Project is configured for 8 MHz operation.
Definition: main.c:54
static bool libpic170x_check_library_build_arguments()
Verify matching configuration parameters between main project and static library. ...
Definition: freq.h:167
const uint32_t __LIBPIC170X_BUILT_XTAL_FREQ
Stores the _XTAL_FREQ that was used while building the static libpic170x library. ...
Definition: freq.c:3