PIC to PIC TX RX and PIC to PC COM RX ..a little help please


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1

    Default PIC to PIC TX RX and PIC to PC COM RX ..a little help please

    Hi all
    (sorry about the long post!)

    Thanks to all those who have helped me and lots of late nights reading and 'PIC'-ing, I have finally reached a stage where I have and LCD connected, a keypad, capturing input from the keypad and have been playing around with SEROUT with the intention of transmitting a byte or a few bytes wirelessly.
    To begin testing (after playing around with serout) I have interconnected my two pics (16f887 and 18f4520) by mean of wires.
    Like this :
    PIC 16f887 PIC 18F4520
    PORTC.6(TX)-----PORTC.7(RX)
    PORTC.7(RX)-----PORTC.6(TX)

    I have setup my code to send "key pressed or received value is" as a loop text string using serout from
    PIC 16f887 to the 18f4520.
    Code:
    loopy:
    high LED ' First LED on
            Pause 1000       ' Delay for .5 seconds
    	low led
             Pause 1000       ' Delay for .5 seconds
              SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx]
            pause 1000
               Goto loopy  ' Go back to loop and blink LED forever
            End
    The 18f4520 is set to receive using serin
    Code:
    SerIn PORTC.7,T2400,DataRX
    I press a key on the 4x4 keypad connected to the 18f4520,
    the keypress is stored as a variable (myvar) and myvar is made to equal datatx)
    I then display datatx (the keypress) on the lcd)
    Then I fetch the input (RX) from the other PIC using SERIN
    The input is held in variable datarx.
    I then display datarx on the LCD

    Once that's done I send the same variable datarx to the PC's com port using serout.

    And end off with the string "end of transmission" on LCD.
    I then use the serout line

    Well .... it works.

    Problem is it only happens once ! yes one time and then LCD goes blank and no matter how many keystrokes I press nothing else happens :-(

    So.... I think perhaps the serout/serin where my problems lie.
    Maybe full RX buffers or something else.
    Maybe I'm not passing the variables correctly.

    I would really appreciate if somone could have a quick look at my code and possibly tell me what I am missing or doing wrong.

    Kind regards

    Dennis

    Here is the code for each PIC
    PIC16f887
    Code:
    '*************************************
    'Transmit to PIC 18f4520 serout loop
    '*************************************
     '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
     
    'Ocsillator selections here
      'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
    '        OSCCON = %01110001           'Int CLK 8MHz
    '        ANSEL= %11111111       '$0F = disable A/D converter
    '        option_reg = 7     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
     '       define osc 8        '8MHz
    'END of timer/oscillator defines
    'clear the ports
    
    
    
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111    <<   'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10000000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
                       
    'variables begin here
            myvar var byte
            datatx var byte
            datarx var byte
    'end of variables
    
    
    LED var PORTd.0   ' Alias PORTD.0 to LED
    
    
        
    loopy:
    high LED '  LED on
            Pause 1000       ' Delay for .5 seconds
    	low led 'LED off
             Pause 1000       ' Delay for .5 seconds
              SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx]
            pause 1000
               Goto loopy  ' Go back to loop and blink LED forever
            End
    'End of all code
    PIC 18F4520
    Code:
    '*************************************
    'Keypress display on LCD and TX to wherever
    '*************************************
    
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111       'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10000000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
                       
    'variables begin here
            myvar var byte
            datatx var byte
            datarx var byte
    'end of variables
    
    'LCD defines begin here   
            DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
            DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
            DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
            DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
            DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
            DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
            DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
            'DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
            'DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
            DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
            DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
    
    'Keypad code begins here
            DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
            DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
            DEFINE KEYPAD_ROW_BIT    0        ' ROW0 = PORTB.4
            DEFINE KEYPAD_COL        4        ' 4 COL keypad
            DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
            DEFINE KEYPAD_COL_BIT    4        ' COL0 = PORTB.0
            DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
            DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature
    'end keypad code
    
    'Main code begins here       
    
            Pause 2000       ' Wait for LCD to startup
    start:
            'read keypress variable 
            @ READKEYPAD _myvar 
            LOOKUP  myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
            datatx = myvar 'pass the variable to solve strange character problem
            lcdout datatx 'display the variable on the LCD
                
            lcdout $fe,1          'clear lcd screen
       'receive section 
             SerIn PORTC.7,T2400,DataRX  'receive data from other pic (16f887) and store as variable datarx    
             LCDOUT datarx          'displays data received from serin datarx
             pause 2000             
             lcdout $fe,1          'clear lcd screen
        'receive section ends
        
       
       'transmit section
            'send datarx(received data from toher pic) to pc serial port 
            serout PORTC.6,T2400,["the key pressed or received value is ",datarx] 'SerOut PinNumber2,T2400,DataRec (FIXED!!
            pause 1000
       'transmit section ends
            LCDout "end of transmission"
            lcdout $fe,1          'clear lcd screen
            
    goto start
    
    'End of all code

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


    Did you find this post helpful? Yes | No

    Default

    A little history to get you started...
    http://www.picbasic.co.uk/forum/show...highlight=idle
    let us know if the above helps.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default ok .... now my options ?

    Hi Dave

    thanks for the history lesson re serin ..very informative ...
    The posting was a little confusing in that (unless I missed it!) it is not clear on how to get the port to dile low IDLE high or IDLE low.
    Is is as simple as somthing like
    portX.Y low or high after the serin line ?
    Note that I am not sending anything over RF yet ... the two PIC's are just wired together at this stage.

    Should I rather try DEBUG or serin/out 2 ?
    Do they suffer from the same issues?

    I would like to make sure I get everything ready before I attach the wireless RF and TX , maximizing both power and rate on the TX/RX pairs, other wise why bother ...not so ?

    Any further help would be much appreciated :-)

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    For PIC to PIC Debug is not the way. SERIN is good for basic stuff. SERIN2 has a whole lot more options and uses the same syntax as HSERIN when you need it. The nice thing about the SERIN/2 is it can be set for TRUE or INVERTED while HSERIN is TRUE only requiring an inverter to connect to things like a PC, but that is a minor thing with the other benifits of hardware serial.

    http://www.melabs.com/resources/samples.htm
    Scroll down to the ser2mod examples for...examples....

    When it comes time to idle low or high that can be done with a resistor 100K. Or in your code.
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default OK so suggested method for TX RX is of choice is ...

    SERIN2
    or
    HWSER right ?

    You mentioned being able to set the IDLE in software if I am going to be using SERIN...
    That's what I was asking in the last post :-)

    In the post you pointed me to it mentions the issues/problems with SERIN and to set it IDLE ...
    SO my question is how do you set the IDLE using software ?

    Is there a document regarding the IDLE setting methods ?

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Normally the mode takes care of the idle state
    http://www.picbasic.co.uk/forum/show...92&postcount=7
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Direct PIC to PC without MAX232
    By acjacques in forum Serial
    Replies: 14
    Last Post: - 23rd October 2014, 21:32
  2. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  3. PIC or xbee times out after Tx 504 bytes
    By archendekta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd November 2009, 08:45
  4. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  5. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13

Members who have read this thread : 3

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