Serin2 - All I Need Is 8 Numbers....


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2006
    Location
    WADSWORTH OHIO USA
    Posts
    37

    Unhappy Serin2 - All I Need Is 8 Numbers....

    I know the answer is right in front of me, if someone could please direct me.

    This is only a small part of a larger project of 8 pics in all. This stage requires me to adjust and communicate two four digit numbers across serial lines. I have read, sturred, thought, and am now totally confused.

    I am using two 16f870 ref'ed as PIC6 & PIC7.

    Here is the code as follows

    PIC6 RECIVER / DISPLAY CODE


    DEFINE OSC 20 'DEFINE OSCILLATOR
    DEFINE SER2_BITS 8

    'DEFINE VARIABLES
    C VAR WORD
    B VAR BYTE
    F VAR BYTE
    TRC VAR BYTE[4]
    ARC VAR BYTE[4]

    'EQUATES SECTION
    TRISA = %00111110 'SET PORTS I/O
    TRISB = %00000000
    TRISC = %00000000
    ADCON0 = %00000000
    ADCON1 = %00000011 'PORTA ALL DIGITAL

    C = 0 'INITIATE VARIABLES
    B = 0
    F = 1

    'IT ALL STARTS HERE

    PAUSE 200
    EEPROM 0,[129,243,73,97,51,37,5,241,1,49] 'STORE CONSTANTS

    LOOP: 'GET T & A FROM PIC 7
    IF PORTA.4 = 1 THEN
    SERIN2 PORTA.0 \PORTA.1,16468,[TRC,ARC]
    ENDIF
    'DISPLAY T & A
    FOR C = 0 TO 3
    READ TRC[C], PORTB
    LOOKUP C,[$7F,$BF,$DF,$EF],PORTC 'SET DIGIT
    PAUSE f
    PORTC = $FF
    NEXT C
    FOR B = 0 TO 3
    READ ARC[B], PORTB
    LOOKUP B,[$FE,$FD,$FB,$F7],PORTC
    PAUSE f
    PORTC = $FF
    NEXT B
    GOTO LOOP


    PIC7 ADJUSTMENT/TRANSMITTER

    DEFINE OSC 20 'DEFINE OSCILLATOR
    DEFINE SER2_BITS 8

    AMP VAR WORD 'DEFINE VARIABLES
    AMPS VAR WORD
    ARX VAR BYTE[4]
    TDIR VAR BYTE
    CDIR VAR BYTE
    SDIR VAR BYTE
    STR1 VAR BYTE
    TIME VAR WORD
    TIMES VAR WORD
    TRX VAR BYTE[4]
    C VAR BYTE
    X VAR BYTE

    'EQUATES SECTION
    TRISA = %00110001 'SET PORTS I/O
    TRISB = %10011101
    TRISC = %00001111
    ADCON0 = %00000000
    ADCON1 = %00000011 'PORTA ALL DIGITAL

    AMP = 50 'INITIATE VARIABLES
    AMPS = 50
    CDIR = 0
    STR1 = 0
    SDIR = 0
    TIME = 1000
    TIMES = 1000
    TDIR = 0

    'IT ALL STARTS HERE

    PAUSE 2500
    GOSUB SND6 'RESTORE PREVIOUS VALUES
    READ 0,TIMES
    READ 1,AMPS
    READ 2,TIME
    READ 3,AMP
    GOSUB SND6
    PAUSE 2500
    FOR C=0 TO 3
    ARX[C] = C+1
    TRX[C]= C+5
    NEXT C
    GOSUB SND6 'SEND TO PIC6
    PAUSE 2500

    LOP1: 'MAIN LOOP
    'IF PORTA.4 = 1 AND PORTA.5 = 0 THEN SND5 'SEND T&C TO PIC5
    IF PORTC.1 = 1 THEN TADJ 'TIME ADJUST
    IF STR1 = 1 AND PORTC.1 = 0 THEN TADW 'SAVE TIME WHEN DONE
    IF PORTC.2 = 1 THEN CADJ 'AMPS ADJUSTMENT
    IF STR1 = 2 AND PORTC.2 =0 THEN CADW 'SAVE AMPS WHEN DONE
    GOTO LOP1

    TADJ: 'ADJUST TIME SETTING
    IF PORTB.3 = 0 AND PORTB.4 = 0 THEN TDIR = 2 'ZERO NOTCH
    IF TDIR = 2 THEN
    IF PORTB.3 = 1 AND PORTC.3 = 0 THEN TR3
    IF PORTB.4 = 1 AND PORTC.3 = 0 THEN TR4
    IF PORTB.3 = 1 AND PORTC.3 = 1 THEN TR5
    IF PORTB.4 = 1 AND PORTC.3 = 1 THEN TR6
    ENDIF
    TDIR = 1
    GOTO LOP1

    TR3: TIME = TIME + 10
    GOTO TDN
    TR4: TIME = TIME - 10
    GOTO TDN
    TR5: TIME = TIME + 1
    GOTO TDN
    TR6: TIME = TIME - 1
    TDN: STR1 = 1
    GOSUB SND6 'T OR C CHANGED
    GOTO LOP1

    TADW: READ 0, TIMES 'STORE TIME
    IF TIMES <> TIME THEN WRITE 0, TIME
    STR1 = 0
    GOTO LOP1

    CADJ:
    IF PORTB.3 = 0 AND PORTB.4 = 0 THEN CDIR = 2 'ZERO NOTCH
    IF CDIR = 2 THEN
    IF PORTB.3 = 1 AND PORTC.3 = 0 THEN CR3
    IF PORTB.4 = 1 AND PORTC.3 = 0 THEN CR4
    IF PORTB.3 = 1 AND PORTC.3 = 1 THEN CR5
    IF PORTB.4 = 1 AND PORTC.3 = 1 THEN CR6
    ENDIF
    CDIR = 1
    GOTO LOP1

    CR3: AMP = AMP + 10
    GOTO CDN
    CR4: AMP = AMP - 10
    GOTO CDN
    CR5: AMP = AMP + 1
    GOTO CDN
    CR6: AMP = AMP - 1
    CDN: STR1 = 2
    GOSUB SND6 'T OR C CHANGED
    GOTO LOP1

    CADW: READ 1, AMPS 'STORE AMPS
    IF AMPS <> AMP THEN WRITE 1, AMP
    STR1 = 0
    GOTO LOP1

    SND5: 'SEND TO PIC5
    WRITE 0, TIME
    WRITE 1, AMP
    SEROUT2 PORTC.5\PORTC.6,16468,[TIME,AMP]
    GOTO LOP1

    'SUBPROGRAM SECTION

    SND6: 'SEND DIGITS TO PIC6
    HIGH PORTB.2
    FOR X=0 TO 3
    TRX[X] = TIME DIG X
    ARX[X] = AMP DIG X
    NEXT X
    Serout2 PORTB.5 \PORTB.6,84,[TRX/4,ARX/4]
    PAUSEUS 20
    LOW PORTB.2
    RETURN

    THANK ALL THAT CAN HELP
    hope the favor can be returned
    Attached Files Attached Files
    Thanks !
    SOMRU
    TWE/TFP/EE

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by SOMRU
    I know the answer is right in front of me, if someone could please direct me.

    PIC6 RECIVER / DISPLAY CODE

    LOOP: 'GET T & A FROM PIC 7
    IF PORTA.4 = 1 THEN
    SERIN2 PORTA.0 \PORTA.1,16468,[TRC,ARC]
    ENDIF
    'DISPLAY T & A


    PIC7 ADJUSTMENT/TRANSMITTER

    'SUBPROGRAM SECTION

    SND6: 'SEND DIGITS TO PIC6
    HIGH PORTB.2
    FOR X=0 TO 3
    TRX[X] = TIME DIG X
    ARX[X] = AMP DIG X
    NEXT X
    Serout2 PORTB.5 \PORTB.6,84,[TRX/4,ARX/4]
    PAUSEUS 20
    LOW PORTB.2
    RETURN

    THANK ALL THAT CAN HELP
    hope the favor can be returned

    You're SerIn2'ing at 16484, and SerOut2'ing at 84. Good problem right there...
    JDG

  3. #3
    Join Date
    Dec 2006
    Location
    WADSWORTH OHIO USA
    Posts
    37

    Unhappy sorry

    With all serin/outs at 84 no luck,
    but did add fix to display ie.

    FOR C = 0 TO 3
    READ TRC[C] DIG 0, PORTB
    LOOKUP C,[$7F,$BF,$DF,$EF],PORTC 'SET DIGIT
    PAUSE f
    PORTC = $FF
    NEXT C

    thanks, still no change
    Thanks !
    SOMRU
    TWE/TFP/EE

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by SOMRU
    With all serin/outs at 84 no luck,
    but did add fix to display ie.

    FOR C = 0 TO 3
    READ TRC[C] DIG 0, PORTB
    LOOKUP C,[$7F,$BF,$DF,$EF],PORTC 'SET DIGIT
    PAUSE f
    PORTC = $FF
    NEXT C

    thanks, still no change


    Well, for one thing, your receiver has 'random' (not really random, but the transmitter doesn't know that) pauses in it. It's not always sitting there waiting for a serial input. It might be off doing something else (like pausing), which might cause it to miss a serial byte, maybe not the whole byte, but it only takes a missed start bit to ruin the whole byte.

    My advice - get rid of the SerIn, and use the hardware serial module, the timer module, and some hardware interrupts to get the job done. Especially if you are dealing with something to do with timing where it actually counts. (get it...counts...timing...ha...joke...ok I'm done).
    Good luck...
    JDG

  5. #5
    Join Date
    Dec 2006
    Location
    WADSWORTH OHIO USA
    Posts
    37

    Post pic 2 pic comm

    Alrighty then, at this stage of the project rerouting of pins is not an option. But that's my nightmare. I have slowed thing down a bit so that perhaps I can "see" what's going on. I know I am close. Here are snipits of my serin/out;

    pic7 program ********************************************

    SND6: 'SEND DIGITS TO PIC6
    HIGH PORTA.1
    HIGH PORTB.2
    FOR X=0 TO 3
    TRX[X] = (TIME DIG X)
    ARX[X] = (AMP DIG X)
    NEXT X
    Serout2 PORTB.5 \PORTB.6,3318,[STR TRX\4 ,STR ARX\4]
    LOW PORTB.2
    LOW PORTA.1
    RETURN

    pic6 program *******************************************

    'RECIEVE AND DISPLAY DIGITS
    EEPROM 0,[129,243,73,97,51,37,5,241,1,49] 'STORE CONSTANTS
    LOOP: 'GET T & A FROM PIC 7
    IF PORTA.4 = 1 THEN
    SerIN2 PORTA.0 \PORTA.1,3318,[STR TRC\4 ,STR ARC\4]

    ENDIF 'DISPLAY T & A
    FOR C = 0 TO 3
    READ (TRC[C] DIG 0), PORTB
    LOOKUP C,[$7F,$BF,$DF,$EF],PORTC 'SET DIGIT
    PAUSE f
    PORTC = $FF
    NEXT C
    FOR B = 0 TO 3
    READ (ARC[B] DIG 0), PORTB
    LOOKUP B,[$FE,$FD,$FB,$F7],PORTC
    PAUSE f
    PORTC = $FF
    NEXT B
    GOTO LOOP

    I believe my problem is "other than the meds for my sanity" in the data array's
    I'm trying to send/recieve ie. TRC VAR BYTE[4] . At this speed I can visually see "scope" the transfer as well as as a confermation by I/O. ??? Who happened to my data ????

    Thanks!!
    Last edited by SOMRU; - 14th December 2006 at 16:41.
    Thanks !
    SOMRU
    TWE/TFP/EE

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 10:47
  2. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 21:10
  3. Replies: 4
    Last Post: - 15th April 2009, 02:54
  4. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 09:47
  5. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th January 2007, 00:15

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