Serin serout problem


Results 1 to 40 of 337

Threaded View

  1. #34
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    Ok now I used your pogram and changed the serin line :

    serin portB.2 , t2400 , temp1 -----works

    It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work


    Ok, I'm back. In the last program I posted, I had the values hardcoded in the transmitter side, so since they displayed correctly, now try a couple of dummy values hardcoded in the receiver side. Try out these programs and let me know what happens....

    Things I changed since the last programs posted a couple of days ago:

    Removed the hardcoded '444' and '888' on the transmitter side

    Added a hardcoded '444' and '888' on the receiver side.

    On both the transmit and receive side, I split the serout and serin into 4 seperate lines, each sending (or receiving) one byte. I don't know if this will fix the problem or not.

    I also added a couple of lines in there to 'sync' up the transmit and receive sides in the case that the receive side starts receiving in the middle of a transmission (which could happen). Very simple setup - 6 bytes are sent, 1st byte - $aa , 2nd-3rd-tempC, 4th-5th-tempF, 6th byte-$55. 1st and 6th byte should add up to $FF. If it doesn't, it was received in the wrong order is values are thrown out. (actually, the 2 numbers from the transmit side could be any pair, as long as they add up to $ff, the receiver will take it, which could mess up the values at the receiver if the right temperature combination comes along, but we'll stay with this for now)

    If the receive side shows '444' and '888', remove the lines and comments, and try it again. It just might work...

    Of course then again, over the past couple of days, you might've gotten it fixed, which would be a sweet deal overall...

    Added a line to idle the transmit line high between characters. This might fix the whole problem...?(see next post)

    'RECEIVE PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    'try1 = count of times waiting for data, try2 = count of bytes received
    try1 var byte : try2 var byte : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    leader var byte : trailer var byte
    input portb.2 : pause 2500
    try1 = 0 : try2 = 0

    loop:
    lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
    temp = 0 : tempf = 0 : leader = 0 : trailer = 0 'clear out old values
    temp1 = 0 : temp2 = 0 : temp3 = 0 : temp4 = 0 'clear out old values
    serin portb.2 , t2400 , [ leader ] 'get leader byte
    serin portb.2 , t2400 , [ temp1 ]:serin portb.2 , t2400 , [ temp2 ] 'get data
    serin portb.2 , t2400 , [ temp3 ]:serin portb.2 , t2400 , [ temp4 ] 'get data
    serin portb.2 , t2400 , [ trailer ] 'get trailer byte

    'remove the line below if 444 and 888 show up on the LCD
    temp1 = 1 : temp2 = 188 : temp3 = 3 : temp4 = 120
    'remove the line above if 444 and 888 show up on the LCD

    if ( leader + trailer ) <> $ff then 'if leader + trailer doesn't add up right...
    lcdout $fe , $c0 , "No Sync..", DEC3 try1 , "," , DEC3 try2
    pause 200 : goto loop 'try again
    endif

    temp.highbyte = temp1 : temp.lowbyte = temp2 'put the received values
    tempf.highbyte = temp3 : tempf.lowbyte = temp4 'where they need to be
    if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
    lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
    lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
    goto loop
    End











    'TRANSMIT PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 33333

    try1 var byte : try2 var byte : output portb.2 : high portb.2 : input portb.3
    dq var portb.4 : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    pause 2500
    try1 = 0 : try2 = 0

    loop:
    lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
    owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
    tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
    lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
    high portb.2 : serout portb.2, t2400 , [ $aa ] 'send a leader byte
    temp1 = temp.highbyte : temp2 = temp.lowbyte
    high portb.2 : serout portb.2 , t2400 , [ temp1 ]
    high portb.2 : serout portb.2 , t2400 , [ temp2 ] 'send data
    temp3 = tempf.highbyte : temp4 = tempf.lowbyte
    high portb.2 : serout portb.2 , t2400 , [ temp3 ]
    high portb.2 : serout portb.2 , t2400 , [ temp4 ] 'send data
    high portb.2 : serout portb.2 , t2400 , [ $ff ] 'send a trailer byte
    high portb.2 : try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
    goto loop
    Last edited by skimask; - 26th December 2006 at 14:17. Reason: increase char_pacing value in transmit section and added lines to idle portb.2 high

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. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 0

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