Serout "onewire.bas"


Closed Thread
Results 1 to 4 of 4
  1. #1
    puru's Avatar
    puru Guest

    Default Serout "onewire.bas"

    I have succesfully tried the "one wire.bas" of the samples area with one ds1820 and a 16f876.
    Now I'd like to transmit the temperature to a pc but I have been able to receive just the label (C) and the dot and not the numerical value.
    Can anybody tell me how to write the serout command in order to read the temperature on the pc?
    Thanks a lot.


    ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
    temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"

  2. #2
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    ' ---------------[University of Bahçeşehir Electrical&Electronics Engineering Final Project]-------------------
    ' ---------------------------------------[Onur BAŞKİRT - 0111745]--------

    ' ------------------------------- [DIGITAL TEMPERATURE MEASUREMENT and CONTROL]--------------------------------

    '------------------------------------------------[Variables]----------------

    temperature VAR WORD ' Temperature storage. (for storing measured value)
    count_remain VAR BYTE ' Count remaining
    count_per_c VAR BYTE ' Count per degree C
    tempc VAR WORD
    DQ VAR PORTC.2 ' One-wire data pin. (Ds1820's Dq line connected to RC2)
    RX VAR BYTE ' Receive byte from PC.
    counter VAR BYTE ' Counter for Automatic Control
    state VAR BYTE
    maxtemp VAR BYTE
    mintemp VAR BYTE

    OUTPUT PORTB.5 ' Red led. (Alarm indicator) (or -> TRISB.5 = 0)
    OUTPUT PORTB.7 ' Green led.(Device) (or -> TRISB.7 = 0)
    INPUT PORTB.1 ' Set portb pin 1 to an input. (or -> TRISB.1 = 1)
    OUTPUT PORTC.5 ' Sound output pin. Set portc pin 5 to an output. (or -> TRISC.5 = 0)
    OUTPUT PORTC.6 ' Serial comm. output pin. Set portc pin 6 to an output. (or -> TRISC.6 = 0)
    INPUT PORTC.7 ' Serial comm. input pin. Set portc pin 7 to an input. (or -> TRISC.7 = 1)

    '---------------------------------------------[Includes/Defines]------------

    DEFINE LCD_DREG PORTD ' I/O port with LCD. (Defining LCD data port)
    DEFINE LCD_DBIT 4 ' When using a 4 bit data bus, (0 or 4) designate beginning of data bits.
    DEFINE LCD_RSREG PORTD ' Defining LCD's register port.
    DEFINE LCD_RSBIT 2 ' Register select pin.
    DEFINE LCD_EREG PORTD ' Defining LCD's enable port.
    DEFINE LCD_EBIT 3 ' Defining LCD's enable pin.
    DEFINE LCD_BITS 4 ' Defining LCD has 4-bit data bus
    DEFINE LCD_LINES 2 ' LCD has two charecter lines
    INCLUDE "modedefs.bas" ' Including serial modes.

    ' Set PORTA and PORTE to digital. Any PICmicro MCU with analog inputs, such as the PIC16C7xx,
    ' PIC16F87x and PIC12C67x series devices, will come up in analog mode.
    ' You must set them to digital if that is how you intend to use them: ADCON1 = 7
    ADCON1 = 7
    PAUSE 100 ' Pause for starting LCD

    '-------------------------------------------------[Main Code]-------------

    HIGH PORTB.7
    counter=0
    state=0
    maxtemp=29
    mintemp=17

    ' OWOut and OWIn commands are detailly explained in PBP official manual.

    ' OWOUT Pin,Mode,[Item...]:
    ' Optionally send a reset pulse to a one-wire device and then writes one or
    ' more bits or bytes of data to it, optionally ending with another reset pulse.
    ' Mode of %001 (decimal 1) means reset before data and byte-sized data.

    ' OWIN Pin,Mode,[Item...]:
    ' Optionally send a reset pulse to a one-wire device and then read one or
    ' more bits or bytes of data from it, optionally ending with another reset pulse.
    ' Mode of %000 (decimal 0) means no reset and byte-sized data, Mode of %100 (decimal 4)
    ' means no reset and bit-sized data. SKIP for skipping a number of input values.

    mainloop: ' Start temperature conversion (send a reset pulse to a one-wire device
    OWOut DQ, 1, [$CC, $44] ' on PORTC pin 2 followed by the bytes $CC and $44.)

    waitloop:
    OWIn DQ, 4, [count_remain] ' Check for still busy converting Read busy-bit
    IF count_remain = 0 THEN waitloop ' Still busy..?

    OWOut DQ, 1, [$CC, $BE] ' Read the measured temperature (send a reset pulse to a one-wire device
    ' on PORTC pin 2 followed by the bytes $CC and $BE.)

    ' This statement would receive bytes from a one-wire device on PORTC pin 0
    ' with no reset pulse being sent. It would receive 2 bytes skip the next 4 bytes and then read
    ' the final 2 bytes into separate variables.
    OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

    ' Calculate temperature in degrees C to 2 decimal places
    ' Below formula is given in Ds1820's datasheet. LCDOut prints the values on LCD's screen.
    temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)

    ' tempc is binary part of after point. Actual data type of digital temperature sensor.
    ' For example #tempc is decimal part of after point for example 23.45 C --> #tempc is 23 C
    tempc = (temperature / 100)

    ' SDEC sends signed decimal part of temperature value and SDEC2 sends signed value of temperature before point.
    LCDOut $fe, 1, "TEMP: ", SDEC (temperature / 100), ".", SDEC2 temperature, " C"

    IF tempc < maxtemp AND tempc > mintemp THEN
    LCDOut $fe, $c0, "STATUS OK"
    ENDIF
    SEROUT PORTC.6, T2400, [#tempc,10]
    GOTO automatic

    '-----------------------------------------[Automatic and Manuel Control]----------------------------------------

    ' If temperature is equal or higher than maximum temperature or lower than minimum temperature then led status off and
    ' Buzzer generates sound also LCD monitors Alarm. Else led status is on, buzzer status off, LCD monitors status OK.

    automatic:
    IF PORTB.1 = 1 THEN ' Test button value. If button is pressed.
    LOW PORTB.7 ' device status is off.
    counter=0
    SEROUT PORTC.6, T2400, ["disabled",10]
    IF tempc >= maxtemp OR tempc <= mintemp THEN ' Test temperature value.
    SOUND PORTC.5,[80,10,60,10] ' If temperature higher than maxtemp or lower than mintemp than buzzer generates
    ' sound that is between 80 & 60 frequency band about 120 ms seconds interval.
    LCDOut $fe, $c0, "ALARM!!!" ' LCD monitors ALARM.
    Pause 200
    ENDIF
    GOTO mainloop ' Do it forever
    ENDIF

    IF PORTB.1 = 0 THEN
    SEROUT PORTC.6, T2400, ["notdisabled",10]
    ENDIF

    IF state = 1 OR state = 2 THEN
    IF tempc >= maxtemp OR tempc <= mintemp THEN ' Test temperature value.
    HIGH PORTB.5 ' (Alarm indicator) red Led status is on.
    SOUND PORTC.5,[40,10,60,10] ' If temperature higher than maxtemp or lower than mintemp buzzer generates
    ' sound that is between 80 & 60 frequency band about 120 ms seconds interval.
    LCDOut $fe, $c0, "ALARM!!!" ' LCD monitors ALARM.
    ENDIF
    IF tempc < maxtemp AND tempc > mintemp THEN ' Test temperature value.
    LOW PORTB.5 ' (Alarm indicator) red Led status is off.
    ENDIF
    GOTO serial
    ENDIF

    IF tempc >= maxtemp OR tempc <= mintemp THEN ' Test temperature value.
    HIGH PORTB.5 ' LED status is on.
    SOUND PORTC.5,[40,10,60,10] ' If temperature higher than maxtemp or lower than mintemp than buzzer generates
    ' sound that is between 80 & 60 frequency band about 120 ms seconds interval.
    LCDOut $fe, $c0, "ALARM!!!" ' LCD monitors ALARM.
    counter = (counter + 1) ' Increase +1 automatic control counter.
    IF counter = 20 THEN
    LOW PORTB.7 ' (Device) green led status is off.
    SEROUT PORTC.6, T2400, ["automatic", 10, 13] ' Send automatic data to pc for display warning in pc program.
    ENDIF
    GOTO serial ' Do it forever
    ENDIF

    IF tempc < maxtemp AND tempc > mintemp THEN ' Test temperature value.
    LOW PORTB.5 ' (Alarm indicator) red Led status is off.
    HIGH PORTB.7 ' (Device) green led status is on.
    counter=0 ' Reset automatic control counter.
    GOTO serial
    ENDIF

    '------------------------------------------------[Serial Communication]-----------------------------------------

    serial:
    ' ***** [Receive the menu selection from PC] ***************
    SERIN PORTC.7, T2400,RX ' Receive menu number
    RX = RX - $30 ' Convert ASCII number to decimal (0 = $30, 1 = $31, etc).

    SELECT CASE RX
    CASE 0
    goto zero
    CASE 1
    goto one
    CASE 2
    goto two
    CASE 3
    goto disconnect
    CASE IS > 3
    goto error
    CASE IS < 0
    goto error
    CASE ELSE
    goto mainloop
    END SELECT

    error:
    GOTO mainloop

    zero:
    state=0
    GOTO mainloop

    one:
    LOW PORTB.7 ' (Device) green led status is off.
    state=1
    GOTO mainloop

    two:
    HIGH PORTB.7 ' (Device) green led status is on.
    state=2
    GOTO mainloop

    disconnect:
    LCDOut $fe, $c0, "TURNED OFF "
    PAUSE 1000
    GOTO mainloop
    '---------------------------------------------------------------------------------------------------------------
    END ' End of program.
    Attached Files Attached Files

  3. #3
    puru's Avatar
    puru Guest


    Did you find this post helpful? Yes | No

    Smile

    Thank you very much obaskirt for the exaustive program example you sent.
    It solves my problem and seems to have most of the features I was planning
    for my project.

  4. #4
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Smile

    I am happy for solving your problem, for accomplishing this program, I worked so much. At the beginning of this project, I have not so much info about pic programming.

    Anyway, Do your best for your project. Congratulations... n Good Luck.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts