PDA

View Full Version : Serin2 - All I Need Is 8 Numbers....



SOMRU
- 12th December 2006, 20:58
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

skimask
- 12th December 2006, 21:24
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

SOMRU
- 12th December 2006, 21:43
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

skimask
- 13th December 2006, 04:50
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

SOMRU
- 14th December 2006, 14:50
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!!