Skip to content

Commit bbc4268

Browse files
committed
Config the floating-point computation to XC8 compiler.
1 parent 4d8941c commit bbc4268

File tree

7 files changed

+117
-106
lines changed

7 files changed

+117
-106
lines changed

DS18B20.c

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,86 +30,76 @@ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
3030
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
3131
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
3232
OTHER DEALINGS IN THE SOFTWARE.
33-
34-
3533
*/
36-
37-
#include "DS18B20.h"
38-
39-
// Available Functions:
40-
float OneWireTemp(void); // Returns the temperature in celsius
41-
unsigned int OneWireReset(void); // Sends a reset pulse to the sensor
42-
void OneWireWriteBit(unsigned char); // write a single bit to the OneWire
43-
unsigned char OneWireReadBit(void); // reads a single bit
44-
void OneWireWriteByte(unsigned char); // writes a byte
45-
unsigned char OneWireReadByte(void); // reads a byte
46-
unsigned char OneWireRead(void); // reads the current status of the bus
47-
void OneWireHigh(void); // sets the bus high
48-
void OneWireRelease(void); // releases the bus
49-
50-
51-
float OneWireTemp(){
52-
34+
35+
#include "DS18B20.h"
36+
37+
38+
int16_t OneWireTemp() {
5339
OneWireReset(); // Reset Pulse
5440
OneWireWriteByte(0xCC); // Issue skip ROM command (CCh)
55-
OneWireWriteByte(0x44); // Convert T command (44h)
56-
while(!BUSIN); // DS will hold line low while making measurement
41+
OneWireWriteByte(0x44); // Convert T command (44h), start conversion
42+
while (!BUSIN); // DS will hold line low while making measurement
5743
OneWireReset(); // Start new command sequence
5844
OneWireWriteByte(0xCC); // Issue skip ROM command
5945
OneWireWriteByte(0xBE); // Read Scratchpad (BEh) - 15 bits
60-
unsigned char LSB = OneWireReadByte();
61-
unsigned char MSB = OneWireReadByte();
46+
uint16_t lsb = OneWireReadByte();
47+
uint16_t msb = OneWireReadByte();
6248
OneWireReset(); // Stop Reading
63-
unsigned int data = MSB;
64-
float temperature = (data << 8) | LSB;
65-
return (temperature/16);
66-
49+
50+
return (msb << 8) | lsb;
51+
}
52+
53+
float countToCelsius(int16_t count) {
54+
// XC Global options -> XC Compiler -> C Standard = C 90
55+
// XC Global options -> XC Linker -> Memory Model -> Size of Float = 24-bit
56+
return count / 16.0f;
6757
}
6858

69-
void OneWireHigh(){
59+
void OneWireHigh() {
7060
BUSDIR = 0; // Set as output
7161
BUSOUT = 1; // Set high
7262
}
7363

74-
void OneWireRelease(){
64+
void OneWireRelease() {
7565
BUSDIR = 0; // Set as output
7666
BUSOUT = 0; // Set low
7767
}
7868

79-
unsigned char OneWireRead(){
69+
unsigned char OneWireRead() {
8070
return BUSIN;
8171
}
8272

83-
unsigned int OneWireReset(){
73+
unsigned int OneWireReset() {
8474
OneWireRelease();
85-
__delay_us(240); // 480uS Delay
86-
__delay_us(240);
75+
__delay_us(480); // 480uS Delay
76+
// __delay_us(240);
77+
// __delay_us(240);
8778
OneWireHigh();
8879
__delay_us(70); // wait 70 uS before reading
8980
unsigned int OW = OneWireRead(); // check for OneWire
90-
__delay_us(205); // 410 uS delay
91-
__delay_us(205);
81+
__delay_us(410); // 410 uS delay
82+
// __delay_us(205);
83+
// __delay_us(205);
9284
OneWireHigh(); // give bus back to OneWire
93-
return OW;
85+
return OW;
9486
}
9587

96-
97-
void OneWireWriteBit(unsigned char b){
98-
if(b){
88+
void OneWireWriteBit(unsigned char b) {
89+
if (b) {
9990
OneWireRelease();
10091
__delay_us(6); // wait 6uS
10192
OneWireHigh();
10293
__delay_us(64); // wait 64uS
103-
}
104-
else{
94+
} else {
10595
OneWireRelease();
10696
__delay_us(60); // wait 60uS
10797
OneWireHigh();
10898
__delay_us(10); // wait 10uS
10999
}
110100
}
111101

112-
unsigned char OneWireReadBit(){
102+
unsigned char OneWireReadBit() {
113103
OneWireRelease();
114104
__delay_us(6); // wait 6uS
115105
OneWireHigh();
@@ -119,19 +109,19 @@ unsigned char OneWireReadBit(){
119109
return out;
120110
}
121111

122-
void OneWireWriteByte(unsigned char b){
123-
for(int i = 0; i < 8; i++){
112+
void OneWireWriteByte(unsigned char b) {
113+
for (int i = 0; i < 8; i++) {
124114
OneWireWriteBit(b & 0x01); // send LS bit first
125115
b = b >> 1;
126116
}
127117
}
128118

129-
unsigned char OneWireReadByte(void){
130-
unsigned char out;
131-
for(int i = 0; i < 8; i++){ // read in LS bit first
119+
unsigned char OneWireReadByte(void) {
120+
unsigned char out;
121+
for (int i = 0; i < 8; i++) { // read in LS bit first
132122
out = out >> 1; // get out ready for next bit
133-
if(OneWireReadBit() & 0x01) // if its a one
123+
if (OneWireReadBit() & 0x01) // if its a one
134124
out = out | 0x80; // place a 1
135125
}
136126
return out;
137-
}
127+
}

DS18B20.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2929
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
3030
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
3131
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32-
OTHER DEALINGS IN THE SOFTWARE.
33-
34-
32+
OTHER DEALINGS IN THE SOFTWARE.
3533
*/
3634

3735
#ifndef DS18B20_H
@@ -53,14 +51,16 @@ OTHER DEALINGS IN THE SOFTWARE.
5351
//#define _XTAL_FREQ 8000000 // Define in mcc_generated_files/device_config.h
5452

5553
// Available Functions:
56-
float OneWireTemp(void); // Returns the temperature in celsius
57-
unsigned int OneWireReset(void); // Sends a reset pulse to the sensor
58-
void OneWireWriteBit(unsigned char); // write a single bit to the OneWire
59-
unsigned char OneWireReadBit(void); // reads a single bit
60-
void OneWireWriteByte(unsigned char); // writes a byte
61-
unsigned char OneWireReadByte(void); // reads a byte
62-
unsigned char OneWireRead(void); // reads the current status of the bus
63-
void OneWireHigh(void); // sets the bus high
64-
void OneWireRelease(void); // releases the bus
54+
int16_t OneWireTemp(void); // Returns the temperature in count, fixed 4-bit-decimal point
55+
float countToCelsius(int16_t count); // Convert a count value to celsius
56+
57+
unsigned int OneWireReset(void); // Sends a reset pulse to the sensor
58+
void OneWireWriteBit(unsigned char); // write a single bit to the OneWire
59+
unsigned char OneWireReadBit(void); // reads a single bit
60+
void OneWireWriteByte(unsigned char); // writes a byte
61+
unsigned char OneWireReadByte(void); // reads a byte
62+
unsigned char OneWireRead(void); // reads the current status of the bus
63+
void OneWireHigh(void); // sets the bus high
64+
void OneWireRelease(void); // releases the bus
6565

66-
#endif // DS18B20_H
66+
#endif // DS18B20_H

MyConfig.mc3

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
<string>I2CSLAVE</string>
2525
<string>class com.microchip.mcc.foundationservices.modules.softwaredriver.I2CSlave.I2CSLAVE</string>
2626
</entry>
27-
<entry>
28-
<string>RESET</string>
29-
<string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string>
30-
</entry>
3127
<entry>
3228
<string>ECCP</string>
3329
<string>class com.microchip.mcc.mcu8.modules.eccp.ECCP</string>
3430
</entry>
31+
<entry>
32+
<string>RESET</string>
33+
<string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string>
34+
</entry>
3535
<entry>
3636
<string>Interrupt Module</string>
3737
<string>class com.microchip.mcc.mcu8.interruptManager.InterruptManager</string>
@@ -64,7 +64,7 @@
6464
</entry>
6565
<entry>
6666
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="pwmDelay"/>
67-
<value>1.25E-7</value>
67+
<value>0.0</value>
6868
</entry>
6969
<entry>
7070
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="WDT" registerAlias="WDTCON0" settingAlias="WDTPS" alias="1:128"/>
@@ -228,7 +228,7 @@
228228
</entry>
229229
<entry>
230230
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="APFCON" settingAlias="SDOSEL"/>
231-
<value>RA4</value>
231+
<value>RC2</value>
232232
</entry>
233233
<entry>
234234
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="ANSELA" settingAlias="ANSA0" alias="digital"/>
@@ -360,7 +360,7 @@
360360
</entry>
361361
<entry>
362362
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="ECCP" registerAlias="PWMCON"/>
363-
<value>129</value>
363+
<value>128</value>
364364
</entry>
365365
<entry>
366366
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPSTAT" settingAlias="BF" alias="RCinprocess_TXcomplete"/>
@@ -378,14 +378,14 @@
378378
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="System Module" registerAlias="CONFIG2" settingAlias="BORV"/>
379379
<value>LO</value>
380380
</entry>
381-
<entry>
382-
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="I2CSLAVE" name="eepromMode"/>
383-
<value>Generic I2C Slave</value>
384-
</entry>
385381
<entry>
386382
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="inputMode"/>
387383
<value>periodMode</value>
388384
</entry>
385+
<entry>
386+
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="I2CSLAVE" name="eepromMode"/>
387+
<value>Generic I2C Slave</value>
388+
</entry>
389389
<entry>
390390
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPI" settingAlias="order"/>
391391
<value>-1</value>
@@ -448,7 +448,7 @@
448448
</entry>
449449
<entry>
450450
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ECCP" registerAlias="PWMCON" settingAlias="PDC"/>
451-
<value>1</value>
451+
<value>0</value>
452452
</entry>
453453
<entry>
454454
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="INTERNAL OSCILLATOR" registerAlias="OSCCON"/>
@@ -508,7 +508,7 @@
508508
</entry>
509509
<entry>
510510
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="Pin Module" registerAlias="TRISA"/>
511-
<value>31</value>
511+
<value>63</value>
512512
</entry>
513513
<entry>
514514
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON1" settingAlias="WCOL" alias="collision"/>
@@ -528,7 +528,7 @@
528528
</entry>
529529
<entry>
530530
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA5"/>
531-
<value>clear</value>
531+
<value>set</value>
532532
</entry>
533533
<entry>
534534
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="PSTRCON" settingAlias="STRSYNC" alias="start_at_begin"/>
@@ -724,7 +724,7 @@
724724
</entry>
725725
<entry>
726726
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="I2CSLAVE" name="pubSubI2CSLAVE_I2C/Functions"/>
727-
<value>6628.214295956764</value>
727+
<value>6093.758096336508</value>
728728
</entry>
729729
<entry>
730730
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA4"/>
@@ -812,7 +812,7 @@
812812
</entry>
813813
<entry>
814814
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="Pin Module" registerAlias="WPUA"/>
815-
<value>0</value>
815+
<value>32</value>
816816
</entry>
817817
<entry>
818818
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="ioc RA0"/>
@@ -1024,7 +1024,7 @@
10241024
</entry>
10251025
<entry>
10261026
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="TRISA" settingAlias="TRISA5"/>
1027-
<value>output</value>
1027+
<value>input</value>
10281028
</entry>
10291029
<entry>
10301030
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="ACKEN" alias="enabled"/>
@@ -1776,7 +1776,7 @@
17761776
</entry>
17771777
<entry>
17781778
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="CCPM"/>
1779-
<value>P1A,P1C: active low; P1B,P1D: active low</value>
1779+
<value>P1A,P1C: active high; P1B,P1D: active high</value>
17801780
</entry>
17811781
<entry>
17821782
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="PM" alias="fullbridge_Fwd"/>
@@ -1992,7 +1992,7 @@
19921992
</entry>
19931993
<entry>
19941994
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="ECCP" registerAlias="CCPCON"/>
1995-
<value>15</value>
1995+
<value>12</value>
19961996
</entry>
19971997
<entry>
19981998
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA5" alias="set"/>
@@ -2116,7 +2116,7 @@
21162116
</entry>
21172117
<entry>
21182118
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="pwmpinspolarity"/>
2119-
<value>P1A,P1C: active low; P1B,P1D: active low</value>
2119+
<value>P1A,P1C: active high; P1B,P1D: active high</value>
21202120
</entry>
21212121
<entry>
21222122
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="TRISA" settingAlias="TRISA4" alias="input"/>
@@ -2352,7 +2352,7 @@
23522352
</entry>
23532353
<entry>
23542354
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="trisUserSetRC3"/>
2355-
<value>disabled</value>
2355+
<value>enabled</value>
23562356
</entry>
23572357
<entry>
23582358
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="RC5"/>
@@ -2524,7 +2524,7 @@
25242524
</entry>
25252525
<entry>
25262526
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="RA5"/>
2527-
<value>output</value>
2527+
<value>input</value>
25282528
</entry>
25292529
<entry>
25302530
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="ANSELA" settingAlias="ANSA4"/>
@@ -2664,7 +2664,7 @@
26642664
</entry>
26652665
<entry>
26662666
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="Pin Module" registerAlias="APFCON"/>
2667-
<value>64</value>
2667+
<value>0</value>
26682668
</entry>
26692669
<entry>
26702670
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="IOCAN" settingAlias="IOCAN0"/>
@@ -2976,17 +2976,17 @@
29762976
<file>mcc_generated_files/pin_manager.h</file>
29772977
<hash>c9760a0d252096e98590259258ec9c0a6098c61bc6aa27bc584691e2f7667d66</hash>
29782978
</entry>
2979-
<entry>
2980-
<file>mcc_generated_files/drivers/i2c_slave.c</file>
2981-
<hash>7fc8fae419885a8c031ea68f98841a4b06039d294d5fabf56606d737b4380683</hash>
2982-
</entry>
29832979
<entry>
29842980
<file>main.c</file>
29852981
<hash>8293d01650f4d6e132ff891dca6e4043647276c2ba64a1b826ca6d2bbcdef972</hash>
29862982
</entry>
2983+
<entry>
2984+
<file>mcc_generated_files/drivers/i2c_slave.c</file>
2985+
<hash>7fc8fae419885a8c031ea68f98841a4b06039d294d5fabf56606d737b4380683</hash>
2986+
</entry>
29872987
<entry>
29882988
<file>mcc_generated_files/epwm.c</file>
2989-
<hash>7ddfcdee36dc1eb6546c43af64638da2f589d73b840089419bd7258e54902ecd</hash>
2989+
<hash>11e0d73bac666718344684bacd84a1077e0ef5768b00806cc935a5c63d05777f</hash>
29902990
</entry>
29912991
<entry>
29922992
<file>mcc_generated_files/tmr2.h</file>
@@ -3026,7 +3026,7 @@
30263026
</entry>
30273027
<entry>
30283028
<file>mcc_generated_files/pin_manager.c</file>
3029-
<hash>22c84907affb68ee2438d478312fa3cd0aff379ea247e9b4544d86496da22820</hash>
3029+
<hash>30a38774988a8f0f111ea77ada5178a0fd060945f42de1e2a4113948b8fb2c5c</hash>
30303030
</entry>
30313031
</generatedFileHashHistoryMap>
30323032
<mc3libFileHashHistoryMap class="java.util.HashMap"/>

0 commit comments

Comments
 (0)