serial communication problem


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2010
    Posts
    5

    Default serial communication problem

    hi.. i'm doing a project which use mcp9700 to measure temperature interfacing with pic18f46k20, then display on LCD and hyper terminal..here's my code PICBasic below:


    INCLUDE "modedefs.bas"
    define osc 4
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    define LCD_EREG PORTD
    define LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    'HIGH PORTD.1
    C VAR WORD



    DEFINE HSER_BAUD 9600 'Hser baud rate
    DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
    DEFINE HSER_SPBRG 25 'Hser spbrg init
    DEFINE HSER_RCSTA 90h 'Hser receive status init
    DEFINE HSER_TXSTA 20h 'Hser transmit status init
    DEFINE HSER_EVEN 1 'Use only if even parity desired
    DEFINE HSER_ODD 1 'Use only if odd parity desired
    DEFINE HSER_BITS 9 'Use 9th bit for parity



    define ADC_BITS 10
    define ADC_CLOCK 3
    define ADC_SAMPLEUS 50

    lmtemp var word
    temp var word
    quanta con 1250
    TRISE = %111
    ADCON1 = 0


    MAIN:
    ADCIN 6, lmtemp
    temp = ((lmtemp/100)/2)+8-50

    LCDOUT $FE,1
    LCDOUT " Programmed by"
    LCDOUT $FE,$C0
    lcdout "YAN^S TEMP="
    LCDOUT #temp
    LCDOUT " C"
    'HIGH PORTD.1


    HSEROUT [dec temp,10]
    'HSerout ["The Temp Are Now ",#temp,"C",13]


    pause 100
    GOTO MAIN
    end

    is it correct my code??
    LCD is working fine but i have a problem to display at hyper terminal

    i hope somebody can help me...

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    These sorta conflict...
    Code:
    DEFINE HSER_EVEN 1 'Use only if even parity desired
    DEFINE HSER_ODD 1 'Use only if odd parity desired
    Is the PC set for 8,N,1 at 9600?
    What speed is the PIC running at?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2010
    Posts
    5

    Default

    hii..thanx for replying..

    yup, i set the PC for 8,N,1 at 9600 and the speed is 4Mhz

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Try these settings
    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $20   ' Enable transmit, BRGH = 0
    SPBRG = 25    ' 9600 Baud @ 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    Since your temperature will never be higher then 255 °C (I assume) then set your variable "temp" as a byte not word.

    temp var byte

    because serially you cannot Tx word but only byte.

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by aratti View Post
    Since your temperature will never be higher then 255 °C (I assume) then set your variable "temp" as a byte not word.

    temp var byte

    because serially you cannot Tx word but only byte.

    Al.
    Hi Al, Can he not send a word out as 2 bytes, like so . . .
    Hserout [Temp.HighByte, Temp.LowByte,10] ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    Hi Joe, Yes he can. But he would not be able to recombine them back to a word, using hyperterminal.

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by aratti View Post
    Hi Joe, Yes he can. But he would not be able to recombine them back to a word, using hyperterminal.

    Al.
    OK I buy that, I really asked the question so as to get your answer, so when someone wanders into this thread looking for answers, they understand it this way.
    Thanks Al
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Mar 2010
    Posts
    5

    Default

    hi guys.. i still hv a problem..i just change my code..here's below

    INCLUDE "modedefs.bas"
    define FOSC 4
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    define LCD_EREG PORTD
    define LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    'HIGH PORTD.1
    C VAR WORD


    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 25 ' 9600 Baud @ 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


    define ADC_BITS 10
    define ADC_CLOCK 3
    define ADC_SAMPLEUS 50

    lmtemp var word
    temp var byte
    quanta con 1250
    TRISE = %111
    ADCON1 = 0


    MAIN:
    ADCIN 6, lmtemp
    temp = ((lmtemp/100)/2)+8-50
    'PORTD.1=1
    'C=PORTD.1
    'LOW PORTD.1
    LCDOUT $FE,1
    LCDOUT " Programmed by"
    LCDOUT $FE,$C0
    lcdout "YAN^S TEMP="
    LCDOUT #temp
    LCDOUT " C"
    'HIGH PORTD.1


    HSEROUT [dec temp,10]
    HSerout ["The Temp Are Now ",#temp,"C",13]


    pause 100
    GOTO MAIN
    end

    it will display something like this... xøxøxxxxø€øøøxxx€x€€ø€€øxøxxxxø€øøøxxx€

    is it correct my temperature equation??i think it is not..when i measured voltage, i get 0.81V and it's display 36 C..it suppose display 30 C..how analog voltage convert to digital and what exactly temperature equation to be write into my code??

    mcp9700 sensors is an analog signal that is directly proportional (linear) to the temperature and the output voltage is a direct indication of the temperature in 10mV/°C.

    plz help me..it's urgent..the due date is next week 15 march..
    thanx..

  10. #10
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    You should first scale lmtemp to volts

    Volts = Imtemp/205 [ 205 = 1/(5/1023))]

    Than since your sensor Vout = (Tci * Ta) + V0°C

    where: Tci = 10 milliVolts and V0°C = 0.5 Volts

    Ta= (Vout-0.5)/0.01

    Ta = (Vout - 0.5) * 100

    Ta = (Vout*100)-50

    Al.
    Last edited by aratti; - 8th March 2010 at 18:58.
    All progress began with an idea

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Sounds like you need to invert the signal.
    You can use a MAX232 or a transistor with a couple resistors.
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Mar 2010
    Posts
    5

    Default

    hi aratti...i hv tried to change my temp equation from your information but the temperature still not showing correctly..can you plz check my code..

    INCLUDE "modedefs.bas"
    define FOSC 4
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    define LCD_EREG PORTD
    define LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    'HIGH PORTD.1
    C VAR WORD


    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 25 ' 9600 Baud @ 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


    define ADC_BITS 10
    define ADC_CLOCK 3
    define ADC_SAMPLEUS 50

    lmtemp var word
    temp var byte
    vout var byte
    quanta con 1250
    TRISE = %111
    ADCON1 = 0


    MAIN:

    ADCIN 6, lmtemp
    vout = lmtemp/205
    temp = (Vout*100)-50

    LCDOUT $FE,1
    LCDOUT " Programmed by"
    LCDOUT $FE,$C0
    lcdout "YAN^S TEMP="
    LCDOUT #temp
    LCDOUT " C"
    'HIGH PORTD.1


    HSEROUT [dec temp,10]
    HSerout ["The Temp Are Now ",#temp,"C",13]


    pause 100
    GOTO MAIN
    end

    tq very much...

  13. #13
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    Try this way:

    Code:
    ADCIN 6, lmtemp
    vout =(lmtemp*100)/205
    temp = Vout-50
    Or if you need decimals

    Code:
    ADCIN 6, lmtemp
    vout =(lmtemp*49)-5000
    Integer_Byte = Vout/100
    Decimal_Byte = Vout//100
    Hserout ["Temp = ",Dec Integer_Byte,".",Dec2 Decimal_Byte," °C",13,10]
    Make Vout a word variable ; Interger_Byte and Decimal_Byte byte variables

    Al.
    Last edited by aratti; - 9th March 2010 at 17:29.
    All progress began with an idea

  14. #14
    Join Date
    Mar 2010
    Posts
    5

    Default

    hi guys..my project is working now..thanks a lot because helping me...
    i love this forum n i really appreciate that..

Similar Threads

  1. Replies: 18
    Last Post: - 4th July 2017, 14:26
  2. Replies: 5
    Last Post: - 20th March 2006, 01:34
  3. Serial Communication Problem
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 23rd February 2006, 02:11
  4. Problem in Serial Communication
    By uuq1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2005, 07:17
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

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