16F690 and DS18b20

Discussion in 'Embedded Systems and Microcontrollers' started by FroceMaster, Aug 22, 2015.

  1. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Hi
    Have this setup,
    16F690 connected to LCD = WORKS FINE
    Connected a DS18b20 temperatur sensor.
    When Building the code the result just be.

    Error [103] C:\******\ds1820.h; 55.35 #error: DS1820 data pin not defined!

    Here is the code.

    Code (C):
    1.  
    2. #include <htc.h>
    3. #include <stdlib.h>
    4. #include "lcd.h"
    5. #include "ds1820.h"
    6. __CONFIG (FCMEN_ON & IESO_OFF & BOREN_OFF & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);
    7.  
    8. #define _XTAL_FREQ  4000000
    9. #define FOSC 4000000L
    10. #define DS1820_DATAPIN PIN_C2
    11. //global defs
    12.  
    13.  
    14.  
    15. void setup(void)
    16. {
    17.  
    18.   TRISC=0; // c output 0b11111000;//RC0-RC2 out,RC3-RC6 in,RC7 in
    19.   TRISB=0; //All port B output
    20. GIE = 0; // Global interrupt disable just in case
    21. IRCF0=1;
    22. IRCF1=1;
    23. IRCF2=1;
    24. ANSEL=0;
    25.   ANSELH=0;
    26. SCS=1; //internal clock
    27.  
    28.  
    29. //setup LCD
    30.   lcd_init();
    31. lcd_goto(0); // select first line
    32.  
    33. }
    34.  
    35.  
    36. void main (void) //hovedprogram
    37. {
    38. setup();
    39.  
    40. GIE=0;
    41. lcd_clear();
    42. lcd_goto(0x00);
    43. lcd_puts("Godav doo");
    44. lcd_goto(0x40); // linje 2
    45.   lcd_puts("Den virker");
    46.   while (1)
    47.   {
    48.  
    49. }
    50.  
    51. }
    52.  
    53.  
    And here is the ds1820.c file

    Code (C):
    1.  
    2. /*** FILEHEADER ****************************************************************
    3.  
    4. *
    5.  
    6. * FILENAME: ds1820.h
    7.  
    8. * DATE: 25.02.2005
    9.  
    10. * AUTHOR: Christian Stadler
    11.  
    12. *
    13.  
    14. * DESCRIPTION: Driver for DS1820 1-Wire Temperature sensor (Dallas)
    15.  
    16. *
    17.  
    18. ******************************************************************************/
    19.  
    20. /*** HISTORY OF CHANGE *********************************************************
    21.  
    22. *
    23.  
    24. * $Log: /pic/_drv/ds1820.h $
    25.  
    26. *
    27.  
    28. * 9 13.11.10 20:02 Stadler
    29.  
    30. * - changed interrupt lock and delay functions to #defines to remove
    31.  
    32. * function call overhead
    33.  
    34. *
    35.  
    36. * 8 6.11.10 10:24 Stadler
    37.  
    38. * - adjusted 1-wire timing
    39.  
    40. *
    41.  
    42. * 7 5.11.10 22:55 Stadler
    43.  
    44. * - changed driver API
    45.  
    46. *
    47.  
    48. * 6 5.11.10 21:59 Stadler
    49.  
    50. * - added DS18B20 support
    51.  
    52. * - fixed problem with ROM search algorithm
    53.  
    54. *
    55.  
    56. * 5 2.11.10 20:25 Stadler
    57.  
    58. * - changed function DS1820_FindFirstDev to DS1820_FindFirstDevice
    59.  
    60. * - changed function DS1820_FindNextDev to DS1820_FindNextDevice
    61.  
    62. * - updated code style
    63.  
    64. *
    65.  
    66. * 4 31.10.10 17:12 Stadler
    67.  
    68. * - introduced DS1820_DelayUs
    69.  
    70. *
    71.  
    72. * 3 25.10.10 13:09 Stadler
    73.  
    74. * - added interrupt lock
    75.  
    76. *
    77.  
    78. * 2 12.03.05 11:24 Stadler
    79.  
    80. * - added EEPROM write function
    81.  
    82. * - added "Search ROM Algorithm" to control multiple devices
    83.  
    84. *
    85.  
    86. * 1 26.02.05 18:18 Stadler
    87.  
    88. * Driver for DS1820 1-Wire Temperature sensor (Dallas)
    89.  
    90. *
    91.  
    92. ******************************************************************************/
    93.  
    94. #ifndef _DS1820_H
    95.  
    96.  
    97. #define _DS1820_H
    98.  
    99.  
    100.  
    101. /* check configuration of driver */
    102.  
    103. #ifndef DS1820_DATAPIN
    104.  
    105.  
    106. #error DS1820 data pin not defined!
    107.  
    108. #endif
    109.  
    110.  
    111.  
    112. #define TEMP_RES 0x100 /* temperature resolution => 1/256C = 0.0039C */
    113.  
    114.  
    115.  
    116. /* -------------------------------------------------------------------------- */
    117.  
    118. /* DS1820 Timing Parameters */
    119.  
    120. /* -------------------------------------------------------------------------- */
    121.  
    122. #define DS1820_RST_PULSE 480 /* master reset pulse time in [us] */
    123.  
    124. #define DS1820_MSTR_BITSTART 2 /* delay time for bit start by master */
    125.  
    126. #define DS1820_PRESENCE_WAIT 40 /* delay after master reset pulse in [us] */
    127.  
    128. #define DS1820_PRESENCE_FIN 480 /* dealy after reading of presence pulse [us] */
    129.  
    130. #define DS1820_BITREAD_DLY 5 /* bit read delay */
    131.  
    132. #define DS1820_BITWRITE_DLY 100 /* bit write delay */
    133.  
    134.  
    135.  
    136. /* -------------------------------------------------------------------------- */
    137.  
    138. /* DS1820 Registers */
    139.  
    140. /* -------------------------------------------------------------------------- */
    141.  
    142. #define DS1820_REG_TEMPLSB 0
    143.  
    144.  
    145. #define DS1820_REG_TEMPMSB 1
    146.  
    147.  
    148. #define DS1820_REG_CNTREMAIN 6
    149.  
    150.  
    151. #define DS1820_REG_CNTPERSEC 7
    152.  
    153.  
    154. #define DS1820_SCRPADMEM_LEN 9 /* length of scratchpad memory */
    155.  
    156. #define DS1820_ADDR_LEN 8
    157.  
    158.  
    159.  
    160. /* -------------------------------------------------------------------------- */
    161.  
    162. /* DS1820 Commands */
    163.  
    164. /* -------------------------------------------------------------------------- */
    165.  
    166. #define DS1820_CMD_SEARCHROM 0xF0
    167.  
    168.  
    169. #define DS1820_CMD_READROM 0x33
    170.  
    171.  
    172. #define DS1820_CMD_MATCHROM 0x55
    173.  
    174.  
    175. #define DS1820_CMD_SKIPROM 0xCC
    176.  
    177.  
    178. #define DS1820_CMD_ALARMSEARCH 0xEC
    179.  
    180.  
    181. #define DS1820_CMD_CONVERTTEMP 0x44
    182.  
    183.  
    184. #define DS1820_CMD_WRITESCRPAD 0x4E
    185.  
    186.  
    187. #define DS1820_CMD_READSCRPAD 0xBE
    188.  
    189.  
    190. #define DS1820_CMD_COPYSCRPAD 0x48
    191.  
    192.  
    193. #define DS1820_CMD_RECALLEE 0xB8
    194.  
    195.  
    196.  
    197. #define DS1820_FAMILY_CODE_DS18B20 0x28
    198.  
    199.  
    200. #define DS1820_FAMILY_CODE_DS18S20 0x10
    201.  
    202.  
    203.  
    204. /* -------------------------------------------------------------------------- */
    205.  
    206. /* static variables */
    207.  
    208. /* -------------------------------------------------------------------------- */
    209.  
    210. static bool bDoneFlag;
    211.  
    212.  
    213. static uint8 nLastDiscrepancy_u8;
    214.  
    215.  
    216. static uint8 nRomAddr_au8[DS1820_ADDR_LEN];
    217.  
    218.  
    219.  
    220.  
    221.  
    222. /* -------------------------------------------------------------------------- */
    223.  
    224. /* Low-Level Functions */
    225.  
    226. /* -------------------------------------------------------------------------- */
    227.  
    228.  
    229.  
    230. /*******************************************************************************
    231.  
    232. * FUNCTION: DS1820_DelayUs
    233.  
    234. * PURPOSE: Delay for the given number of micro seconds.
    235.  
    236. *
    237.  
    238. * INPUT: dly_us number of micro seconds to delay
    239.  
    240. * OUTPUT: -
    241.  
    242. * RETURN: -
    243.  
    244. ******************************************************************************/
    245.  
    246. #define DS1820_DelayUs(dly_us) delay_us(dly_us)
    247.  
    248.  
    249.  
    250. /*******************************************************************************
    251.  
    252. * FUNCTION: DS1820_DelayMs
    253.  
    254. * PURPOSE: Delay for the given number of milliseconds.
    255.  
    256. *
    257.  
    258. * INPUT: dly_ms number of milliseconds to delay
    259.  
    260. * OUTPUT: -
    261.  
    262. * RETURN: -
    263.  
    264. ******************************************************************************/
    265.  
    266. #define DS1820_DelayMs(dly_ms) delay_ms(dly_ms)
    267.  
    268.  
    269.  
    270. /*******************************************************************************
    271.  
    272. * FUNCTION: DS1820_DisableInterrupts
    273.  
    274. * PURPOSE: Disable interrupts
    275.  
    276. *
    277.  
    278. * INPUT: -
    279.  
    280. * OUTPUT: -
    281.  
    282. * RETURN: -
    283.  
    284. ******************************************************************************/
    285.  
    286. #ifdef DS1820_INTERRUPT_LOCK
    287.  
    288.  
    289. #define DS1820_DisableInterrupts() disable_interrupts(GLOBAL)
    290.  
    291. #else
    292.  
    293. #define DS1820_DisableInterrupts()
    294.  
    295. #endif
    296.  
    297.  
    298.  
    299.  
    300.  
    301. /*******************************************************************************
    302.  
    303. * FUNCTION: DS1820_EnableInterrupts
    304.  
    305. * PURPOSE: Enable interrupts
    306.  
    307. *
    308.  
    309. * INPUT: -
    310.  
    311. * OUTPUT: -
    312.  
    313. * RETURN: -
    314.  
    315. ******************************************************************************/
    316.  
    317. #ifdef DS1820_INTERRUPT_LOCK
    318.  
    319.  
    320. #define DS1820_EnableInterrupts() enable_interrupts(GLOBAL)
    321.  
    322. #else
    323.  
    324. #define DS1820_EnableInterrupts()
    325.  
    326. #endif
    327.  
    328.  
    329.  
    330. /*******************************************************************************
    331.  
    332. * FUNCTION: DS1820_Reset
    333.  
    334. * PURPOSE: Initializes the DS1820 device.
    335.  
    336. *
    337.  
    338. * INPUT: -
    339.  
    340. * OUTPUT: -
    341.  
    342. * RETURN: FALSE if at least one device is on the 1-wire bus, TRUE otherwise
    343.  
    344. ******************************************************************************/
    345.  
    346. bool DS1820_Reset(void)
    347.  
    348. {
    349.  
    350. bool bPresPulse;
    351.  
    352. DS1820_DisableInterrupts();
    353.  
    354.  
    355.  
    356. /* reset pulse */
    357.  
    358. output_low(DS1820_DATAPIN);
    359.  
    360.  
    361. DS1820_DelayUs(DS1820_RST_PULSE);
    362.  
    363. output_high(DS1820_DATAPIN);
    364.  
    365. /* wait until pullup pull 1-wire bus to high */
    366.  
    367. DS1820_DelayUs(DS1820_PRESENCE_WAIT);
    368.  
    369. /* get presence pulse */
    370.  
    371. bPresPulse = input(DS1820_DATAPIN);
    372.  
    373.  
    374. DS1820_DelayUs(424);
    375.  
    376.  
    377.  
    378. DS1820_EnableInterrupts();
    379.  
    380. return bPresPulse;
    381.  
    382. }
    383.  
    384.  
    385.  
    386. /*******************************************************************************
    387.  
    388. * FUNCTION: DS1820_ReadBit
    389.  
    390. * PURPOSE: Reads a single bit from the DS1820 device.
    391.  
    392. *
    393.  
    394. * INPUT: -
    395.  
    396. * OUTPUT: -
    397.  
    398. * RETURN: bool value of the bit which as been read form the DS1820
    399.  
    400. ******************************************************************************/
    401.  
    402. bool DS1820_ReadBit(void)
    403.  
    404. {
    405.  
    406. bool bBit;
    407.  
    408. DS1820_DisableInterrupts();
    409.  
    410.  
    411.  
    412. output_low(DS1820_DATAPIN);
    413.  
    414. DS1820_DelayUs(DS1820_MSTR_BITSTART);
    415.  
    416. input(DS1820_DATAPIN);
    417.  
    418. DS1820_DelayUs(DS1820_BITREAD_DLY);
    419.  
    420. bBit = input(DS1820_DATAPIN);
    421.  
    422.  
    423.  
    424. DS1820_EnableInterrupts();
    425.  
    426. return (bBit);
    427.  
    428. }
    429.  
    430.  
    431.  
    432. /*******************************************************************************
    433.  
    434. * FUNCTION: DS1820_WriteBit
    435.  
    436. * PURPOSE: Writes a single bit to the DS1820 device.
    437.  
    438. *
    439.  
    440. * INPUT: bBit value of bit to be written
    441.  
    442. * OUTPUT: -
    443.  
    444. * RETURN: -
    445.  
    446. ******************************************************************************/
    447.  
    448. void DS1820_WriteBit(bool bBit)
    449.  
    450. {
    451.  
    452. DS1820_DisableInterrupts();
    453.  
    454.  
    455.  
    456. output_low(DS1820_DATAPIN);
    457.  
    458. DS1820_DelayUs(DS1820_MSTR_BITSTART);
    459.  
    460. if (bBit != FALSE)
    461.  
    462. {
    463.  
    464. output_high(DS1820_DATAPIN);
    465.  
    466. }
    467.  
    468. DS1820_DelayUs(DS1820_BITWRITE_DLY);
    469.  
    470. output_high(DS1820_DATAPIN);
    471.  
    472.  
    473.  
    474. DS1820_EnableInterrupts();
    475.  
    476. }
    477.  
    478.  
    479.  
    480. /*******************************************************************************
    481.  
    482. * FUNCTION: DS1820_ReadByte
    483.  
    484. * PURPOSE: Reads a single byte from the DS1820 device.
    485.  
    486. *
    487.  
    488. * INPUT: -
    489.  
    490. * OUTPUT: -
    491.  
    492. * RETURN: uint8 byte which has been read from the DS1820
    493.  
    494. ******************************************************************************/
    495.  
    496. uint8 DS1820_ReadByte(void)
    497.  
    498. {
    499.  
    500. uint8 i;
    501.  
    502. uint8 value = 0;
    503.  
    504. for (i=0 ; i < 8; i++)
    505.  
    506. {
    507.  
    508. if ( DS1820_ReadBit() )
    509.  
    510. {
    511.  
    512. value |= (1 << i);
    513.  
    514. }
    515.  
    516. DS1820_DelayUs(120);
    517.  
    518. }
    519.  
    520. return(value);
    521.  
    522. }
    523.  
    524.  
    525.  
    526. /*******************************************************************************
    527.  
    528. * FUNCTION: DS1820_WriteByte
    529.  
    530. * PURPOSE: Writes a single byte to the DS1820 device.
    531.  
    532. *
    533.  
    534. * INPUT: val_u8 byte to be written
    535.  
    536. * OUTPUT: -
    537.  
    538. * RETURN: -
    539.  
    540. ******************************************************************************/
    541.  
    542. void DS1820_WriteByte(uint8 val_u8)
    543.  
    544. {
    545.  
    546. uint8 i;
    547.  
    548. uint8 temp;
    549.  
    550. for (i=0; i < 8; i++) /* writes byte, one bit at a time */
    551.  
    552. {
    553.  
    554. temp = val_u8 >> i; /* shifts val right 'i' spaces */
    555.  
    556. temp &= 0x01; /* copy that bit to temp */
    557.  
    558. DS1820_WriteBit(temp); /* write bit in temp into */
    559.  
    560. }
    561.  
    562.  
    563. DS1820_DelayUs(105);
    564.  
    565. }
    566.  
    567.  
    568.  
    569.  
    570.  
    571. /* -------------------------------------------------------------------------- */
    572.  
    573. /* API Interface */
    574.  
    575. /* -------------------------------------------------------------------------- */
    576.  
    577.  
    578.  
    579. /*******************************************************************************
    580.  
    581. * FUNCTION: DS1820_AddrDevice
    582.  
    583. * PURPOSE: Addresses a single or all devices on the 1-wire bus.
    584.  
    585. *
    586.  
    587. * INPUT: nAddrMethod use DS1820_CMD_MATCHROM to select a single
    588.  
    589. * device or DS1820_CMD_SKIPROM to select all
    590.  
    591. * OUTPUT: -
    592.  
    593. * RETURN: -
    594.  
    595. ******************************************************************************/
    596.  
    597. void DS1820_AddrDevice(uint8 nAddrMethod)
    598.  
    599. {
    600.  
    601. uint8 i;
    602.  
    603.  
    604.  
    605. if (nAddrMethod == DS1820_CMD_MATCHROM)
    606.  
    607. {
    608.  
    609. DS1820_WriteByte(DS1820_CMD_MATCHROM); /* address single devices on bus */
    610.  
    611. for (i = 0; i < DS1820_ADDR_LEN; i ++)
    612.  
    613. {
    614.  
    615. DS1820_WriteByte(nRomAddr_au8[I]);
    616.  
    617. }
    618.  
    619. }
    620.  
    621. else
    622.  
    623. {
    624.  
    625. DS1820_WriteByte(DS1820_CMD_SKIPROM); /* address all devices on bus */
    626.  
    627. }
    628.  
    629.  
    630. }
    631.  
    632.  
    633.  
    634. /*******************************************************************************
    635.  
    636. * FUNCTION: DS1820_FindNextDevice
    637.  
    638. * PURPOSE: Finds next device connected to the 1-wire bus.
    639.  
    640. *
    641.  
    642. * INPUT: -
    643.  
    644. * OUTPUT: nRomAddr_au8[] ROM code of the next device
    645.  
    646. * RETURN: bool TRUE if there are more devices on the 1-wire
    647.  
    648. * bus, FALSE otherwise
    649.  
    650. ******************************************************************************/
    651.  
    652. bool DS1820_FindNextDevice(void)
    653.  
    654. {
    655.  
    656. uint8 state_u8;
    657.  
    658. uint8 byteidx_u8;
    659.  
    660. uint8 mask_u8 = 1;
    661.  
    662. uint8 bitpos_u8 = 1;
    663.  
    664. uint8 nDiscrepancyMarker_u8 = 0;
    665.  
    666. bool bit_b;
    667.  
    668. bool bStatus;
    669.  
    670. bool next_b = FALSE;
    671.  
    672. /* init ROM address */
    673.  
    674. for (byteidx_u8=0; byteidx_u8 < 8; byteidx_u8 ++)
    675.  
    676. {
    677.  
    678. nRomAddr_au8[byteidx_u8] = 0x00;
    679.  
    680. }
    681.  
    682. bStatus = DS1820_Reset(); /* reset the 1-wire */
    683.  
    684. if (bStatus || bDoneFlag) /* no device found */
    685.  
    686. {
    687.  
    688. nLastDiscrepancy_u8 = 0; /* reset the search */
    689.  
    690. return FALSE;
    691.  
    692. }
    693.  
    694. /* send search rom command */
    695.  
    696. DS1820_WriteByte(DS1820_CMD_SEARCHROM);
    697.  
    698.  
    699. byteidx_u8 = 0;
    700.  
    701. do
    702.  
    703. {
    704.  
    705.  
    706. state_u8 = 0;
    707.  
    708. /* read bit */
    709.  
    710. if ( DS1820_ReadBit() != 0 )
    711.  
    712. {
    713.  
    714. state_u8 = 2;
    715.  
    716. }
    717.  
    718. DS1820_DelayUs(120);
    719.  
    720. /* read bit complement */
    721.  
    722. if ( DS1820_ReadBit() != 0 )
    723.  
    724. {
    725.  
    726. state_u8 |= 1;
    727.  
    728. }
    729.  
    730. DS1820_DelayUs(120);
    731.  
    732. /* description for values of state_u8: */
    733.  
    734. /* 00 There are devices connected to the bus which have conflicting */
    735.  
    736. /* bits in the current ROM code bit position. */
    737.  
    738. /* 01 All devices connected to the bus have a 0 in this bit position. */
    739.  
    740. /* 10 All devices connected to the bus have a 1 in this bit position. */
    741.  
    742. /* 11 There are no devices connected to the 1-wire bus. */
    743.  
    744. /* if there are no devices on the bus */
    745.  
    746. if (state_u8 == 3)
    747.  
    748. {
    749.  
    750. break;
    751.  
    752. }
    753.  
    754. else
    755.  
    756. {
    757.  
    758. /* devices have the same logical value at this position */
    759.  
    760. if (state_u8 > 0)
    761.  
    762. {
    763.  
    764. /* get bit value */
    765.  
    766. bit_b = (bool)(state_u8 >> 1);
    767.  
    768. }
    769.  
    770. /* devices have confilcting bits in the current ROM code */
    771.  
    772. else
    773.  
    774. {
    775.  
    776. /* if there was a conflict on the last iteration */
    777.  
    778. if (bitpos_u8 < nLastDiscrepancy_u8)
    779.  
    780. {
    781.  
    782. /* take same bit as in last iteration */
    783.  
    784. bit_b = ( (nRomAddr_au8[byteidx_u8] & mask_u8) > 0 );
    785.  
    786.  
    787. }
    788.  
    789. else
    790.  
    791. {
    792.  
    793.  
    794. bit_b = (bitpos_u8 == nLastDiscrepancy_u8);
    795.  
    796. }
    797.  
    798. if (bit_b == 0)
    799.  
    800. {
    801.  
    802. nDiscrepancyMarker_u8 = bitpos_u8;
    803.  
    804. }
    805.  
    806. }
    807.  
    808. /* store bit in ROM address */
    809.  
    810. if (bit_b != 0)
    811.  
    812. {
    813.  
    814. nRomAddr_au8[byteidx_u8] |= mask_u8;
    815.  
    816. }
    817.  
    818. else
    819.  
    820. {
    821.  
    822.  
    823. nRomAddr_au8[byteidx_u8] &= ~mask_u8;
    824.  
    825. }
    826.  
    827. DS1820_WriteBit(bit_b);
    828.  
    829. /* increment bit position */
    830.  
    831. bitpos_u8 ++;
    832.  
    833. /* calculate next mask value */
    834.  
    835. mask_u8 = mask_u8 << 1;
    836.  
    837. /* check if this byte has finished */
    838.  
    839. if (mask_u8 == 0)
    840.  
    841. {
    842.  
    843. byteidx_u8 ++; /* advance to next byte of ROM mask */
    844.  
    845. mask_u8 = 1; /* update mask */
    846.  
    847. }
    848.  
    849.  
    850. }
    851.  
    852. } while (byteidx_u8 < DS1820_ADDR_LEN);
    853.  
    854.  
    855.  
    856. /* if search was unsuccessful then */
    857.  
    858. if (bitpos_u8 < 65)
    859.  
    860. {
    861.  
    862. /* reset the last discrepancy to 0 */
    863.  
    864. nLastDiscrepancy_u8 = 0;
    865.  
    866.  
    867. }
    868.  
    869. else
    870.  
    871. {
    872.  
    873. /* search was successful */
    874.  
    875. nLastDiscrepancy_u8 = nDiscrepancyMarker_u8;
    876.  
    877.  
    878. bDoneFlag = (nLastDiscrepancy_u8 == 0);
    879.  
    880. /* indicates search is not complete yet, more parts remain */
    881.  
    882. next_b = TRUE;
    883.  
    884.  
    885. }
    886.  
    887. return next_b;
    888.  
    889. }
    890.  
    891.  
    892.  
    893. /*******************************************************************************
    894.  
    895. * FUNCTION: DS1820_FindFirstDevice
    896.  
    897. * PURPOSE: Starts the device search on the 1-wire bus.
    898.  
    899. *
    900.  
    901. * INPUT: -
    902.  
    903. * OUTPUT: nRomAddr_au8[] ROM code of the first device
    904.  
    905. * RETURN: bool TRUE if there are more devices on the 1-wire
    906.  
    907. * bus, FALSE otherwise
    908.  
    909. ******************************************************************************/
    910.  
    911. bool DS1820_FindFirstDevice(void)
    912.  
    913. {
    914.  
    915. nLastDiscrepancy_u8 = 0;
    916.  
    917. bDoneFlag = FALSE;
    918.  
    919. return ( DS1820_FindNextDevice() );
    920.  
    921. }
    922.  
    923.  
    924.  
    925. /*******************************************************************************
    926.  
    927. * FUNCTION: DS1820_WriteEEPROM
    928.  
    929. * PURPOSE: Writes to the DS1820 EEPROM memory (2 bytes available).
    930.  
    931. *
    932.  
    933. * INPUT: nTHigh high byte of EEPROM
    934.  
    935. * nTLow low byte of EEPROM
    936.  
    937. * OUTPUT: -
    938.  
    939. * RETURN: -
    940.  
    941. ******************************************************************************/
    942.  
    943. void DS1820_WriteEEPROM(uint8 nTHigh, uint8 nTLow)
    944.  
    945. {
    946.  
    947. /* --- write to scratchpad ----------------------------------------------- */
    948.  
    949. DS1820_Reset();
    950.  
    951.  
    952. DS1820_AddrDevice(DS1820_CMD_MATCHROM);
    953.  
    954. DS1820_WriteByte(DS1820_CMD_WRITESCRPAD); /* start conversion */
    955.  
    956. DS1820_WriteByte(nTHigh);
    957.  
    958.  
    959. DS1820_WriteByte(nTLow);
    960.  
    961. DS1820_DelayUs(10);
    962.  
    963. DS1820_Reset();
    964.  
    965. DS1820_AddrDevice(DS1820_CMD_MATCHROM);
    966.  
    967. DS1820_WriteByte(DS1820_CMD_COPYSCRPAD); /* start conversion */
    968.  
    969. delay_ms(10);
    970.  
    971.  
    972. }
    973.  
    974.  
    975.  
    976. /*******************************************************************************
    977.  
    978. * FUNCTION: DS1820_GetTempRaw
    979.  
    980. * PURPOSE: Get temperature raw value from single DS1820 device.
    981.  
    982. *
    983.  
    984. * Scratchpad Memory Layout
    985.  
    986. * Byte Register
    987.  
    988. * 0 Temperature_LSB
    989.  
    990. * 1 Temperature_MSB
    991.  
    992. * 2 Temp Alarm High / User Byte 1
    993.  
    994. * 3 Temp Alarm Low / User Byte 2
    995.  
    996. * 4 Reserved
    997.  
    998. * 5 Reserved
    999.  
    1000. * 6 Count_Remain
    1001.  
    1002. * 7 Count_per_C
    1003.  
    1004. * 8 CRC
    1005.  
    1006. *
    1007.  
    1008. * Temperature calculation for DS18S20 (Family Code 0x10):
    1009.  
    1010. * =======================================================
    1011.  
    1012. * (Count_per_C - Count_Remain)
    1013.  
    1014. * Temperature = temp_raw - 0.25 + ----------------------------
    1015.  
    1016. * Count_per_C
    1017.  
    1018. *
    1019.  
    1020. * Where temp_raw is the value from the temp_MSB and temp_LSB with
    1021.  
    1022. * the least significant bit removed (the 0.5C bit).
    1023.  
    1024. *
    1025.  
    1026. *
    1027.  
    1028. * Temperature calculation for DS18B20 (Family Code 0x28):
    1029.  
    1030. * =======================================================
    1031.  
    1032. * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
    1033.  
    1034. * LSB 2^3 2^2 2^1 2^0 2^-1 2^-2 2^-3 2^-4
    1035.  
    1036. * bit15 bit14 bit13 bit12 bit3 bit2 bit1 bit0
    1037.  
    1038. * MSB S S S S S 2^6 2^5 2^4
    1039.  
    1040. *
    1041.  
    1042. * The temperature data is stored as a 16-bit sign-extended twos
    1043.  
    1044. * complement number in the temperature register. The sign bits (S)
    1045.  
    1046. * indicate if the temperature is positive or negative: for
    1047.  
    1048. * positive numbers S = 0 and for negative numbers S = 1.
    1049.  
    1050. *
    1051.  
    1052. * RETURN: sint16 raw temperature value with a resolution
    1053.  
    1054. * of 1/256C
    1055.  
    1056. ******************************************************************************/
    1057.  
    1058. sint16 DS1820_GetTempRaw(void)
    1059.  
    1060. {
    1061.  
    1062. uint8 i;
    1063.  
    1064. uint16 temp_u16;
    1065.  
    1066. uint16 highres_u16;
    1067.  
    1068. uint8 scrpad[DS1820_SCRPADMEM_LEN];
    1069.  
    1070. /* --- start temperature conversion -------------------------------------- */
    1071.  
    1072. DS1820_Reset();
    1073.  
    1074. DS1820_AddrDevice(DS1820_CMD_MATCHROM); /* address the device */
    1075.  
    1076. output_high(DS1820_DATAPIN);
    1077.  
    1078. DS1820_WriteByte(DS1820_CMD_CONVERTTEMP); /* start conversion */
    1079.  
    1080. //DS1820_DelayMs(DS1820_TEMPCONVERT_DLY); /* wait for temperature conversion */
    1081.  
    1082. DS1820_DelayMs(750);
    1083.  
    1084.  
    1085.  
    1086.  
    1087. /* --- read sratchpad ---------------------------------------------------- */
    1088.  
    1089. DS1820_Reset();
    1090.  
    1091. DS1820_AddrDevice(DS1820_CMD_MATCHROM); /* address the device */
    1092.  
    1093. DS1820_WriteByte(DS1820_CMD_READSCRPAD); /* read scratch pad */
    1094.  
    1095. /* read scratch pad data */
    1096.  
    1097. for (i=0; i < DS1820_SCRPADMEM_LEN; i++)
    1098.  
    1099. {
    1100.  
    1101. scrpad[I] = DS1820_ReadByte();
    1102.  
    1103. }
    1104.  
    1105.  
    1106.  
    1107. /* --- calculate temperature --------------------------------------------- */
    1108.  
    1109. /* Formular for temperature calculation: */
    1110.  
    1111. /* Temp = Temp_read - 0.25 + ((Count_per_C - Count_Remain)/Count_per_C) */
    1112.  
    1113. /* get raw value of temperature (0.5C resolution) */
    1114.  
    1115. temp_u16 = 0;
    1116.  
    1117.  
    1118. temp_u16 = (uint16)((uint16)scrpad[DS1820_REG_TEMPMSB] << 8);
    1119.  
    1120. temp_u16 |= (uint16)(scrpad[DS1820_REG_TEMPLSB]);
    1121.  
    1122. if (nRomAddr_au8[0] == DS1820_FAMILY_CODE_DS18S20)
    1123.  
    1124. {
    1125.  
    1126. /* get temperature value in 1C resolution */
    1127.  
    1128. temp_u16 >>= 1;
    1129.  
    1130.  
    1131.  
    1132.  
    1133. /* temperature resolution is TEMP_RES (0x100), so 1C equals 0x100 */
    1134.  
    1135. /* => convert to temperature to 1/256C resolution */
    1136.  
    1137. temp_u16 = ((uint16)temp_u16 << 8);
    1138.  
    1139.  
    1140.  
    1141.  
    1142. /* now substract 0.25C */
    1143.  
    1144. temp_u16 -= ((uint16)TEMP_RES >> 2);
    1145.  
    1146.  
    1147.  
    1148.  
    1149. /* now calculate high resolution */
    1150.  
    1151. highres_u16 = scrpad[DS1820_REG_CNTPERSEC] - scrpad[DS1820_REG_CNTREMAIN];
    1152.  
    1153.  
    1154. highres_u16 = ((uint16)highres_u16 << 8);
    1155.  
    1156. if (scrpad[DS1820_REG_CNTPERSEC])
    1157.  
    1158. {
    1159.  
    1160. highres_u16 = highres_u16 / (uint16)scrpad[DS1820_REG_CNTPERSEC];
    1161.  
    1162. }
    1163.  
    1164.  
    1165.  
    1166. /* now calculate result */
    1167.  
    1168. highres_u16 = highres_u16 + temp_u16;
    1169.  
    1170.  
    1171. }
    1172.  
    1173. else
    1174.  
    1175. {
    1176.  
    1177. /* 12 bit temperature value has 0.0625C resolution */
    1178.  
    1179. /* shift left by 4 to get 1/256C resolution */
    1180.  
    1181. highres_u16 = temp_u16;
    1182.  
    1183.  
    1184. highres_u16 <<= 4;
    1185.  
    1186. }
    1187.  
    1188. return (highres_u16);
    1189.  
    1190. }
    1191.  
    1192.  
    1193.  
    1194. /*******************************************************************************
    1195.  
    1196. * FUNCTION: DS1820_GetTempFloat
    1197.  
    1198. * PURPOSE: Converts internal temperature value to string (physical value).
    1199.  
    1200. *
    1201.  
    1202. * INPUT: none
    1203.  
    1204. * OUTPUT: none
    1205.  
    1206. * RETURN: float temperature value with as float value
    1207.  
    1208. ******************************************************************************/
    1209.  
    1210. float DS1820_GetTempFloat(void)
    1211.  
    1212. {
    1213.  
    1214. return ((float)DS1820_GetTempRaw() / (float)TEMP_RES);
    1215.  
    1216. }
    1217.  
    1218.  
    1219.  
    1220. /*******************************************************************************
    1221.  
    1222. * FUNCTION: DS1820_GetTempString
    1223.  
    1224. * PURPOSE: Converts internal temperature value to string (physical value).
    1225.  
    1226. *
    1227.  
    1228. * INPUT: tRaw_s16 internal temperature value
    1229.  
    1230. * OUTPUT: strTemp_pc user string buffer to write temperature value
    1231.  
    1232. * RETURN: sint16 temperature value with an internal resolution
    1233.  
    1234. * of TEMP_RES
    1235.  
    1236. ******************************************************************************/
    1237.  
    1238. void DS1820_GetTempString(sint16 tRaw_s16, char *strTemp_pc)
    1239.  
    1240. {
    1241.  
    1242. sint16 tPhyLow_s16;
    1243.  
    1244. sint8 tPhy_s8;
    1245.  
    1246. /* convert from raw value (1/256C resolution) to physical value */
    1247.  
    1248. tPhy_s8 = (sint8)(tRaw_s16/TEMP_RES);
    1249.  
    1250. /* convert digits from raw value (1/256C resolution) to physical value */
    1251.  
    1252. /*tPhyLow_u16 = tInt_s16 % TEMP_RES;*/
    1253.  
    1254. tPhyLow_s16 = tRaw_s16 & 0xFF; /* this operation is the same as */
    1255.  
    1256. /* but saves flash memory tInt_s16 % TEMP_RES */
    1257.  
    1258. tPhyLow_s16 = tPhyLow_s16 * 100;
    1259.  
    1260.  
    1261. tPhyLow_s16 = (uint16)tPhyLow_s16 / TEMP_RES;
    1262.  
    1263. /* write physical temperature value to string */
    1264.  
    1265. sprintf(strTemp_pc, "%d.%02d", tPhy_s8, (sint8)tPhyLow_s16);
    1266.  
    1267. }
    1268.  
    1269. #endif /* _DS1820_H */
    1270.  
    1271.  
    Any hint to why ?


    Moderators note: Please use code tags for pieces of code
     
    Last edited by a moderator: Aug 22, 2015
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    You have to #define DS1820_DATAPIN before including ds1820.h
    The error is generated at line 106 of ds1820.h - the tipoff is the #error message - that is a user generated error which will be in the source file.

    Good luck.
     
  3. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Sure, i am aware of that, but have tried all possibel way to define it
    do i write #define datapin=RA1 or how ?
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    OK.. well, fix that first then resolve the function output_low(DS1820_DATAPIN)
    I don't know if output_low is in the compiler's library- Search the project for it and see what it wants as parameters.
     
  5. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    just dont get it, why is there a million different 1820.h files out on the net.
    when reading it should be so simple to get it to Work,
    Have a analog tmp35 sensor before, and that was pretty easy to get working,
     
  6. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Some thing like this just use your pin names
    Code (Text):
    1. #define Port_18B20          RB4
    2. #define Tx_18B20            TRISB4 = 0
    3. #define Rx_18B20            TRISB4 = 1
     
  7. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    when moving the #define DS1820_DATAPIN to before including ds1820.h
    i get a lots of errors.
    Warning [374] C:\**\ds1820.h; 111.13 missing basic type; int assumed
    Error [372] C:\**\ds1820.h; 111.13 "," expected
    Warning [374] C:\**\ds1820.h; 112.14 missing basic type; int assumed
    Error [372] C:\**\ds1820.h; 112.14 "," expected

    and a LOT more errors,
    should i not include the 1820.h file ?
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    A #define statement is a simple text replacement used by the C pre-processor. The best way to figure out how to write those a software package needs is to consult the documentation of that same package.

    So you need to hunt down this Christian Stadler and hold him down until he explains what his ds1820 stuff needs.

    You may want o see if he has a website before using physical force.
     
  9. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Hi
    Have been putting something together, from stole from net.
    Now i have som working thing, but somehow the temperatur is wrong, and is dropping when Warming up the sensor,
    and rising when cooling Down, any hint on why

    Code (Text):
    1. #include <htc.h>            //include hitech C header file
    2. #include "lcd.h"
    3.  
    4. #define    _XTAL_FREQ            4000000
    5.  
    6. // This configuration bits are for PIC16F690 using internal crystal
    7.  
    8. //__CONFIG(FCMEN_ON & IESO_OFF & BOREN_OFF & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);
    9. #pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
    10. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
    11. #pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
    12. #pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
    13. #pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
    14. #pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
    15. #pragma config BOREN = OFF      // Brown-out Reset Selection bits (BOR disabled)
    16. #pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode is disabled)
    17. #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
    18.  
    19.  
    20. #define SCS_BIT                0x01
    21. #define INT_OSC_8MHZ         (0b01110000 | SCS_BIT)
    22. #define INT_OSC_4MHZ         (0b01100000 | SCS_BIT)
    23. #define INT_OSC_2MHZ         (0b01010000 | SCS_BIT)
    24. #define INT_OSC_1MHZ         (0b01000000 | SCS_BIT)
    25. #define INT_OSC_500KHZ         (0b00110000 | SCS_BIT)
    26. #define INT_OSC_250KHZ         (0b00100000 | SCS_BIT)
    27. #define INT_OSC_125KHZ         (0b00010000 | SCS_BIT)
    28. #define INT_OSC_31KHZ         (0b00000000 | SCS_BIT)
    29.  
    30. #define Skip_ROM             0xCC
    31. #define Convert_T             0x44
    32. #define Read_scratchpad     0xBE
    33.  
    34. #define Port_18B20             RA2
    35. #define Tx_18B20             TRISA2 = 0
    36. #define Rx_18B20             TRISA2 = 1
    37.  
    38. #define WAIT1                1000
    39. #define WAIT2                500
    40.  
    41. #define DS18B20_CONV_TIME    750
    42. #define DS18B20_RESET_PULSE 480
    43. #define DS18B20_WAIT_TIME     60
    44. #define DS18B20_PULLUP_TIME 2
    45.  
    46. #define ONEWIRE_PRESENT     0
    47. #define ONEWIRE_ABSENT         1
    48.  
    49. unsigned char TLow;
    50. unsigned char vDisp[9];
    51. unsigned char DP;
    52.  
    53.  
    54. void init (void)
    55. {
    56.     ANSEL = 0;        //Initialize A/D ports off
    57.     ANSELH = 0;        //Initialize A/D ports off
    58.     CM1CON0 = 0;    //Initialize comp 1 off
    59.     CM2CON0 = 0;    //Initialize comp 2 off
    60.     PORTA = 0x00;    // Clears PORTA
    61.     PORTB = 0x00;    // Clears PORTB
    62.     PORTC = 0x00;    // Clears PORTC
    63.     TRISA = 0x00;    // Sets PORTA to all output
    64.     TRISB = 0x00;    // Sets PORTB to all output
    65.     TRISC = 0x00;    // sets PORTC to all output.
    66.     //TRISA1=1;
    67.  
    68.     // We want 8MHz
    69.     OSCCON = INT_OSC_8MHZ;
    70.  
    71.     // Wait for clock to stabilise.
    72.     __delay_ms(10);
    73. }
    74.  
    75. /*void nibble(unsigned byte)
    76. {
    77.     PORTC = (unsigned)(byte & 0x0f);
    78.     return;
    79. }*/
    80.  
    81. /*void delay_ms(unsigned int ui_value)
    82. {
    83.     while (ui_value-- != 0) {
    84.         __delay_ms(1);                    // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
    85.     }  
    86. }*/
    87.  
    88. unsigned char reset()
    89. {
    90.     Tx_18B20;                            // Tris = 0 (output)
    91.     Port_18B20 = 0;                        // set pin# to low (0)
    92.     __delay_us(DS18B20_RESET_PULSE);    // 1 wire require time delay
    93.     Rx_18B20;                            // Tris = 1 (input)
    94.     __delay_us(DS18B20_WAIT_TIME);        // 1 wire require time delay
    95.  
    96.     if (Port_18B20 == 0)                 // if there is a presence pluse
    97.     {
    98.         __delay_us(DS18B20_RESET_PULSE);// Reset and return
    99.         return ONEWIRE_PRESENT;            // return 0 ( 1-wire is presence)
    100.     }
    101.  
    102.     __delay_us(DS18B20_RESET_PULSE);    // Reset and return
    103.     return ONEWIRE_ABSENT;                // return 1 ( 1-wire is NOT presence)
    104. }
    105.  
    106. void write(char WRT)
    107. {
    108.     char i,Cmd;
    109.     Cmd = WRT;
    110.     Rx_18B20; // set pin# to input (1)
    111.     for(i = 0; i < 8; i++)
    112.     {
    113.         if((Cmd & (1<<i))!= 0)
    114.         {
    115.             // write 1
    116.             Tx_18B20; // set pin# to output (0)
    117.             Port_18B20 = 0; // set pin# to low (0)
    118.             __delay_us(DS18B20_PULLUP_TIME); // 1 wire require time delay
    119.             Rx_18B20; // set pin# to input (release the bus)
    120.             __delay_us(DS18B20_WAIT_TIME); // 1 wire require time delay
    121.         } else  {
    122.             //write 0
    123.             Tx_18B20; // set pin# to output (0)
    124.             Port_18B20 = 0; // set pin# to low (0)
    125.             __delay_us(DS18B20_WAIT_TIME); // 1 wire require time delay
    126.             Rx_18B20; // set pin# to input (release the bus)
    127.         }
    128.     }
    129. }
    130.  
    131. unsigned char read()
    132. {
    133.     char i,result = 0;
    134.     Rx_18B20; // TRIS is input(1)
    135.     for(i = 0; i < 8; i++)
    136.     {
    137.         Tx_18B20; // TRIS is output(0)
    138.         Port_18B20 = 0; // genarate low pluse for 2us
    139.         __delay_us(DS18B20_PULLUP_TIME);
    140.         Rx_18B20; // TRIS is input(1) release the bus
    141.         if(Port_18B20 != 0) {
    142.             result |= 1<<i;
    143.         }
    144.         __delay_us(DS18B20_WAIT_TIME); // wait for recovery time
    145.     }
    146.     return result;
    147. }
    148.  
    149. /*******************************************************************************
    150. * MAIN FUNCTION                                                                *
    151. *******************************************************************************/
    152. int main(void)
    153. {
    154.     //unsigned temp, val;
    155.     unsigned short tempL, tempH; //, fraction;
    156.     //unsigned int i = 0;    // declare a variable to store  
    157.       unsigned int temptotal  ;
    158.     init();
    159.      lcd_init();
    160.     __delay_ms(500);
    161.     lcd_goto(0x00);
    162.     lcd_puts("Try again");
    163.     __delay_ms(2000);
    164.     lcd_clear();
    165.     vDisp[4] = '.';
    166.     vDisp[6] = " ";
    167.      vDisp[7] = "ß";
    168.      vDisp[8] = 'C';
    169.      lcd_goto(0x00);
    170.      lcd_puts("Temp:");
    171.  
    172.     while(1)     // create an infinite loop
    173.     {      
    174.         if (!reset() == ONEWIRE_PRESENT)
    175.         {
    176.          
    177.             write(Skip_ROM);
    178.             write(Convert_T);      
    179.             __delay_ms(DS18B20_CONV_TIME);
    180.            
    181.             reset();
    182.             write(Skip_ROM);      
    183.             write(Read_scratchpad);  
    184.            
    185.             tempL = read();            //read low temp value
    186.             tempH = read();            //read high temp value
    187.            // TLow = read();
    188.             //temptotal = (tempH << 8) + tempL;
    189.  
    190.             DP = tempL & 0x01; // 'Check if Temperature is integer or fractional
    191.          if (tempH){ //If reading is negative
    192.             vDisp[0] = '-';
    193.             tempL = ((~tempL) + 1) >> 1;
    194.          }
    195.          else{
    196.              vDisp[0] = '+';
    197.              tempL = tempL >> 1; // 'Shift one position right (divide by 2) to get integer reading and get rid of decimal point
    198.          }
    199.          vDisp[1] = (tempL / 100) + 48; // 'Get hundreds and convert to ASCII
    200.          vDisp[2] = ((tempL / 10) % 10) + 48; // 'Get tens and convert to ASCII
    201.          vDisp[3] = (tempL % 10) + 48; // 'Get units and convert to ASCII
    202.          if (DP){ // 'If reading is fractional, ie has 0.5 at end
    203.             vDisp[5] = '5';
    204.          }
    205.          else{ // 'If reading is a whole number
    206.             vDisp[5] = '0';
    207.          }
    208.          lcd_goto(0x08);
    209.          lcd_putch(vDisp[0]);
    210.          lcd_putch(vDisp[1]);
    211.          lcd_putch(vDisp[2]);
    212.          lcd_putch(vDisp[3]);
    213.          lcd_putch(vDisp[4]);
    214.          lcd_putch(vDisp[5]);
    215.          lcd_putch(vDisp[6]);
    216.          lcd_putch(vDisp[7]);
    217.          lcd_putch(vDisp[8]);
    218.          lcd_goto(0x40);
    219.        
    220.        
    221.            
    222.            
    223.  
    224.        
    225.         }
    226.     }
    227.  
    228.    
    229. }
    230.  
     
  10. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Can someone help me,
    HAve been struggeling for days now.

    iam not very strong in bit manipulation..
    The string that will be read is
    like this
    0000 0001 1001 0001 should bee +25,0625 and i can see how according to datasheet.
    0000 = always 0 when positive.
    0001 = is bit 8 -7 - 6 -5 together with 1001 should be 25 in dec.
    the last part is the part after the "," fraction of degree, this be 0,0625 - 0,1250 - 0,1875 - 0,2500 ect to 0,9375 and 0.0000 aka 1/16 degree.
    but how can i ex put these binary numbers to a int ? to use i thermometer.
    should bee able to compare the reading to older reading, this is why i need int,
    i am lost.....
     
Loading...