Skip to content

Commit 4d8941c

Browse files
committed
Able to read a temperature from DS18B20.
1 parent 00328ae commit 4d8941c

File tree

7 files changed

+92
-89
lines changed

7 files changed

+92
-89
lines changed

DS18B20.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void OneWireHigh(void); // sets the bus high
4848
void OneWireRelease(void); // releases the bus
4949

5050

51-
5251
float OneWireTemp(){
5352

5453
OneWireReset(); // Reset Pulse

DS18B20.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ OTHER DEALINGS IN THE SOFTWARE.
3737
#ifndef DS18B20_H
3838
#define DS18B20_H
3939

40-
#include <stdio.h>
41-
#include <stdlib.h>
42-
#include <math.h>
43-
#include <xc.h>
44-
#include <p18f25k20.h>
40+
#include "mcc_generated_files/mcc.h"
41+
4542

4643
// This configuration is required to make a PIC be in open drain
47-
#define BUSDIR LATAbits.LA5 // Set direction: input or output
48-
#define BUSOUT TRISAbits.RA5 // Set output: high or low
49-
#define BUSIN PORTAbits.RA5 // Read input
44+
//#define BUSDIR LATAbits.LA5 // Set direction: input or output
45+
//#define BUSOUT TRISAbits.RA5 // Set output: high or low
46+
//#define BUSIN PORTAbits.RA5 // Read input
47+
48+
#define BUSDIR IO_W1T0_LAT
49+
#define BUSOUT IO_W1T0_TRIS
50+
#define BUSIN IO_W1T0_PORT
51+
5052

51-
#define _XTAL_FREQ 8000000
53+
//#define _XTAL_FREQ 8000000 // Define in mcc_generated_files/device_config.h
5254

5355
// Available Functions:
5456
float OneWireTemp(void); // Returns the temperature in celsius

MyConfig.mc3

Lines changed: 61 additions & 61 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>ECCP</string>
29-
<string>class com.microchip.mcc.mcu8.modules.eccp.ECCP</string>
30-
</entry>
3127
<entry>
3228
<string>RESET</string>
3329
<string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string>
3430
</entry>
31+
<entry>
32+
<string>ECCP</string>
33+
<string>class com.microchip.mcc.mcu8.modules.eccp.ECCP</string>
34+
</entry>
3535
<entry>
3636
<string>Interrupt Module</string>
3737
<string>class com.microchip.mcc.mcu8.interruptManager.InterruptManager</string>
@@ -128,16 +128,16 @@
128128
</entry>
129129
<entry>
130130
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="ccpr"/>
131-
<value>499</value>
132-
</entry>
133-
<entry>
134-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPSTAT" settingAlias="CKE" alias="enabled"/>
135-
<value>1</value>
131+
<value>0</value>
136132
</entry>
137133
<entry>
138134
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPAS" settingAlias="PSSBD" alias="low"/>
139135
<value>0</value>
140136
</entry>
137+
<entry>
138+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPSTAT" settingAlias="CKE" alias="enabled"/>
139+
<value>1</value>
140+
</entry>
141141
<entry>
142142
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="WPUC" settingAlias="WPUC2"/>
143143
<value>clear</value>
@@ -338,14 +338,14 @@
338338
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="IOCAF" settingAlias="IOCAF1" alias="disabled"/>
339339
<value>0</value>
340340
</entry>
341-
<entry>
342-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SBCDE" alias="disabled"/>
343-
<value>0</value>
344-
</entry>
345341
<entry>
346342
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="CCPM" alias="Output Polarity Non-Inverted"/>
347343
<value>8</value>
348344
</entry>
345+
<entry>
346+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SBCDE" alias="disabled"/>
347+
<value>0</value>
348+
</entry>
349349
<entry>
350350
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="PSTRCON" settingAlias="STRD" alias="P1D_to_CCP1M"/>
351351
<value>1</value>
@@ -358,14 +358,14 @@
358358
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="IOCAN" settingAlias="IOCAN1" alias="disabled"/>
359359
<value>0</value>
360360
</entry>
361-
<entry>
362-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPSTAT" settingAlias="BF" alias="RCinprocess_TXcomplete"/>
363-
<value>0</value>
364-
</entry>
365361
<entry>
366362
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="ECCP" registerAlias="PWMCON"/>
367363
<value>129</value>
368364
</entry>
365+
<entry>
366+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPSTAT" settingAlias="BF" alias="RCinprocess_TXcomplete"/>
367+
<value>0</value>
368+
</entry>
369369
<entry>
370370
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON1" settingAlias="SSPOV" alias="no_overflow"/>
371371
<value>0</value>
@@ -718,14 +718,14 @@
718718
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="straPin"/>
719719
<value>disabled</value>
720720
</entry>
721-
<entry>
722-
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="I2CSLAVE" name="pubSubI2CSLAVE_I2C/Functions"/>
723-
<value>2434.4141571504474</value>
724-
</entry>
725721
<entry>
726722
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="CCPM" alias="off/reset"/>
727723
<value>0</value>
728724
</entry>
725+
<entry>
726+
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="I2CSLAVE" name="pubSubI2CSLAVE_I2C/Functions"/>
727+
<value>6628.214295956764</value>
728+
</entry>
729729
<entry>
730730
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA4"/>
731731
<value>clear</value>
@@ -939,11 +939,11 @@
939939
<value>0</value>
940940
</entry>
941941
<entry>
942-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="RSEN" alias="disabled"/>
942+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="PSTRCON" settingAlias="STRC" alias="P1C_to_port"/>
943943
<value>0</value>
944944
</entry>
945945
<entry>
946-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="PSTRCON" settingAlias="STRC" alias="P1C_to_port"/>
946+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="RSEN" alias="disabled"/>
947947
<value>0</value>
948948
</entry>
949949
<entry>
@@ -1200,7 +1200,7 @@
12001200
</entry>
12011201
<entry>
12021202
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="DCB"/>
1203-
<value>3</value>
1203+
<value>0</value>
12041204
</entry>
12051205
<entry>
12061206
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="WDT" registerAlias="WDTCON0" settingAlias="WDTPS" alias="1:262144"/>
@@ -1388,7 +1388,7 @@
13881388
</entry>
13891389
<entry>
13901390
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="ECCP" registerAlias="CCPRL"/>
1391-
<value>124</value>
1391+
<value>0</value>
13921392
</entry>
13931393
<entry>
13941394
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="DHEN"/>
@@ -1476,7 +1476,7 @@
14761476
</entry>
14771477
<entry>
14781478
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="dutyCycle"/>
1479-
<value>50.0</value>
1479+
<value>0.0</value>
14801480
</entry>
14811481
<entry>
14821482
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS" alias="1:9"/>
@@ -1526,14 +1526,14 @@
15261526
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS" alias="1:6"/>
15271527
<value>5</value>
15281528
</entry>
1529-
<entry>
1530-
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="MSSP" name="sdipin"/>
1531-
<value>enabled</value>
1532-
</entry>
15331529
<entry>
15341530
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPAS" settingAlias="PSSBD" alias="high"/>
15351531
<value>1</value>
15361532
</entry>
1533+
<entry>
1534+
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="MSSP" name="sdipin"/>
1535+
<value>enabled</value>
1536+
</entry>
15371537
<entry>
15381538
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA3" alias="clear"/>
15391539
<value>0</value>
@@ -1630,14 +1630,14 @@
16301630
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="System Module" registerAlias="CONFIG1" settingAlias="PWRTE"/>
16311631
<value>OFF</value>
16321632
</entry>
1633-
<entry>
1634-
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SDAHT"/>
1635-
<value>100ns</value>
1636-
</entry>
16371633
<entry>
16381634
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="PSTRCON" settingAlias="STRB" alias="P1B_to_port"/>
16391635
<value>0</value>
16401636
</entry>
1637+
<entry>
1638+
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SDAHT"/>
1639+
<value>100ns</value>
1640+
</entry>
16411641
<entry>
16421642
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPAS" settingAlias="PSSAC" alias="high"/>
16431643
<value>1</value>
@@ -1978,21 +1978,21 @@
19781978
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="INTERNAL OSCILLATOR" name="T1oscen"/>
19791979
<value>disabled</value>
19801980
</entry>
1981-
<entry>
1982-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON1" settingAlias="SSPM" alias="FOSC/4"/>
1983-
<value>0</value>
1984-
</entry>
19851981
<entry>
19861982
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ECCP" registerAlias="CCPCON" settingAlias="CCPM" alias="P1A,P1C: active high; P1B,P1D: active low"/>
19871983
<value>13</value>
19881984
</entry>
1985+
<entry>
1986+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON1" settingAlias="SSPM" alias="FOSC/4"/>
1987+
<value>0</value>
1988+
</entry>
19891989
<entry>
19901990
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="IOCAN" settingAlias="IOCAN4"/>
19911991
<value>disabled</value>
19921992
</entry>
19931993
<entry>
19941994
<key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="ECCP" registerAlias="CCPCON"/>
1995-
<value>63</value>
1995+
<value>15</value>
19961996
</entry>
19971997
<entry>
19981998
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="WPUA" settingAlias="WPUA5" alias="set"/>
@@ -2314,14 +2314,14 @@
23142314
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="RC3"/>
23152315
<value>disabled</value>
23162316
</entry>
2317-
<entry>
2318-
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="PEN"/>
2319-
<value>disabled</value>
2320-
</entry>
23212317
<entry>
23222318
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ECCP" registerAlias="CCPRH" settingAlias="CCPRH"/>
23232319
<value>0</value>
23242320
</entry>
2321+
<entry>
2322+
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="PEN"/>
2323+
<value>disabled</value>
2324+
</entry>
23252325
<entry>
23262326
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATC" settingAlias="LATC4" alias="clear"/>
23272327
<value>0</value>
@@ -2538,14 +2538,14 @@
25382538
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATA" settingAlias="LATA2" alias="set"/>
25392539
<value>1</value>
25402540
</entry>
2541-
<entry>
2542-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SDAHT" alias="100ns"/>
2543-
<value>0</value>
2544-
</entry>
25452541
<entry>
25462542
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="eccpMode"/>
25472543
<value>Enhanced PWM</value>
25482544
</entry>
2545+
<entry>
2546+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SDAHT" alias="100ns"/>
2547+
<value>0</value>
2548+
</entry>
25492549
<entry>
25502550
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="WDT" registerAlias="WDTCON0" settingAlias="WDTPS" alias="1:4194304"/>
25512551
<value>17</value>
@@ -2788,7 +2788,7 @@
27882788
</entry>
27892789
<entry>
27902790
<key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ECCP" registerAlias="CCPRL" settingAlias="CCPRL"/>
2791-
<value>124</value>
2791+
<value>0</value>
27922792
</entry>
27932793
<entry>
27942794
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="customNameUserSet RA5"/>
@@ -2826,26 +2826,26 @@
28262826
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="INTERNAL OSCILLATOR" registerAlias="BORCON" settingAlias="SBOREN" alias="disabled"/>
28272827
<value>0</value>
28282828
</entry>
2829-
<entry>
2830-
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Interrupt Module" name="IVT_NAME"/>
2831-
<value>IVT1</value>
2832-
</entry>
28332829
<entry>
28342830
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG1" settingAlias="CP" alias="OFF"/>
28352831
<value>128</value>
28362832
</entry>
28372833
<entry>
2838-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SBCDE" alias="enabled"/>
2839-
<value>1</value>
2834+
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Interrupt Module" name="IVT_NAME"/>
2835+
<value>IVT1</value>
28402836
</entry>
28412837
<entry>
2842-
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="ACKSTAT" alias="received"/>
2843-
<value>0</value>
2838+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON3" settingAlias="SBCDE" alias="enabled"/>
2839+
<value>1</value>
28442840
</entry>
28452841
<entry>
28462842
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ECCP" name="strEn"/>
28472843
<value>disabled</value>
28482844
</entry>
2845+
<entry>
2846+
<key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="MSSP" registerAlias="SSPCON2" settingAlias="ACKSTAT" alias="received"/>
2847+
<value>0</value>
2848+
</entry>
28492849
<entry>
28502850
<key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="trisUserSetRA4"/>
28512851
<value>disabled</value>
@@ -2976,17 +2976,17 @@
29762976
<file>mcc_generated_files/pin_manager.h</file>
29772977
<hash>c9760a0d252096e98590259258ec9c0a6098c61bc6aa27bc584691e2f7667d66</hash>
29782978
</entry>
2979-
<entry>
2980-
<file>main.c</file>
2981-
<hash>8293d01650f4d6e132ff891dca6e4043647276c2ba64a1b826ca6d2bbcdef972</hash>
2982-
</entry>
29832979
<entry>
29842980
<file>mcc_generated_files/drivers/i2c_slave.c</file>
29852981
<hash>7fc8fae419885a8c031ea68f98841a4b06039d294d5fabf56606d737b4380683</hash>
29862982
</entry>
2983+
<entry>
2984+
<file>main.c</file>
2985+
<hash>8293d01650f4d6e132ff891dca6e4043647276c2ba64a1b826ca6d2bbcdef972</hash>
2986+
</entry>
29872987
<entry>
29882988
<file>mcc_generated_files/epwm.c</file>
2989-
<hash>1666d907228befb677450b141c4c61b37655ca4e8339f8abf3aa0f89e3273df0</hash>
2989+
<hash>7ddfcdee36dc1eb6546c43af64638da2f589d73b840089419bd7258e54902ecd</hash>
29902990
</entry>
29912991
<entry>
29922992
<file>mcc_generated_files/tmr2.h</file>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Temperature from DS18B20 for PWM Control on PIC16F1823, implemented via Microchip Code Configurator (MCC)
2+

main.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*/
4343

4444
#include "mcc_generated_files/mcc.h"
45+
#include "DS18B20.h"
4546

4647
/*
4748
Main application
@@ -66,23 +67,20 @@ void main(void)
6667
// Disable the Peripheral Interrupts
6768
//INTERRUPT_PeripheralInterruptDisable();
6869

69-
70-
70+
7171
uint16_t i = 0;
72-
73-
72+
7473
while (1)
7574
{
76-
// Add your application code
75+
float temp = OneWireTemp();
76+
//sprintf(str,"Temp: %3.2fC", temp);
77+
if (temp > 35.)
78+
{
79+
i += 10000;
80+
EPWM_LoadDutyValue(i);
81+
}
7782

78-
// __delay_ms(1000);
79-
// IO_FAN_SetHigh();
80-
// __delay_ms(1000);
81-
// IO_FAN_SetLow();
82-
83-
EPWM_LoadDutyValue(i);
84-
i += 10000;
85-
__delay_ms(1000);
83+
__delay_ms(1000);
8684
}
8785
}
8886
/**

0 commit comments

Comments
 (0)