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