I have updated the code as per Bruce and Al's suggestions.
The lights stay on for a short period after the last button is released then go out.
I am interested in reading the value of RB0-RB3 only from PORTB to a byte variable on the first PIC, then sending that over the wire to be written to PORTA on the second PIC.
I ONLY want to read RB0-RB3 though, and ONLY want to write to RA0-RA3. Is there a statement that will allow this?
Charles, I am very interested in using HSERIN in a future version of the project as it would be nice to let the PIC do something else besides wait for a signal. If you can point me at any example code it would be very much appreciated.
Anyway, this is the code so far:
Code:
'****************************************************************
'* Name : Output15.pbp *
'* Author : Greensasquatch *
'* Date : 10/11/2008 *
'* Chip : PIC16F628A *
'* Version : 1.5 *
'* Notes : To output a number corresponding to which button *
'* : was pressed via serial communication *
'****************************************************************
'* This Program is part 1 of 2. The other half receives a
'* number and lights a corresponding LED.
'****************************************************************
'* REVISIONS: comparators disabled
'*
'*
'****************************************************************
'*
'* Connections are as follows:
'*
'* N/C -01-|####|-18- N/C
'* N/C -02-|####|-17- SEROUT Line
'* N/C -03-|####|-16- N/C
'* MCLR 10K to V+ -04-|####|-15- N/C
'* Gnd -05-|####|-14- V+
'* Butt1 -06-|####|-13- N/C
'* Butt1 -07-|####|-12- N/C
'* Butt1 -08-|####|-11- N/C
'* Butt1 -09-|####|-10- Green Power LED
'*
'****************************************************************
INCLUDE "MODEDEFS.BAS"
'uses internal oscillator (should use crystal but ran out)
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
CMCON=7 'disable comparators
GreenLED var PORTB.4
Butt1 var PORTB.0
Butt2 var PORTB.1
Butt3 var PORTB.2
Butt4 var PORTB.3
Pause 2000 'wait to begin
high greenled 'turn on status light
Loop:
IF BUTt1 = 1 THEN SEROUT PORTA.0,T1200,[9,1] 'sends 9 and 1 if butt1 is high
IF BUTt2 = 1 THEN SEROUT PORTA.0,T1200,[9,2] 'sends 9 and 2 if butt2 is high
IF BUTt3 = 1 THEN SEROUT PORTA.0,T1200,[9,3] 'sends 9 and 3 if butt3 is high
IF BUTt4 = 1 THEN SEROUT PORTA.0,T1200,[9,4] 'sends 9 and 4 if butt4 is high
GOTO LOOP
end
And
Code:
'****************************************************************
'* Name : Input15.pbp *
'* Author : Greensasquatch *
'* Date : 10/11/2008 *
'* Chip : PIC16F628A *
'* Version : 1.5 *
'* Notes : To read a number via serial communication and *
'* : light a corresponding LED *
'****************************************************************
'* This Program is part 2 of 2. The other half sends a
'* number corresponding to a button state.
'****************************************************************
'* REVISIONS: comparators disabled, lights out if no signal received
'*
'*
'****************************************************************
'*
'* Connections are as follows:
'*
'* LED3 -01-|####|-18- LED2
'* LED4 -02-|####|-17- LED1
'* N/C -03-|####|-16- N/C
'* MCLR 10K to V+ -04-|####|-15- N/C
'* Gnd -05-|####|-14- V+
'* Serial In -06-|####|-13- N/C
'* Green Power LED -07-|####|-12- N/C
'* N/C -08-|####|-11- N/C
'* N/C -09-|####|-10- N/C
'*
'****************************************************************
INCLUDE "MODEDEFS.BAS"
'uses internal oscillator (should use crystal but ran out)
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
CMCON=7 'disable comparators
GreenLED var PORTB.1
LED1 var PORTA.0
LED2 var PORTA.1
LED3 var PORTA.2
LED4 var PORTA.3
NET var byte 'holding variable for input
Pause 2000 'wait to begin
high greenled 'turn on status light
Loop:
'waits for a "9" and writes the next value to NET, turn off LEDs if no signal
SERIN PORTB.0,T1200,500,OffLed,[9],NET
IF NET = 1 THEN HIGH led1
IF NET = 2 THEN HIGH led2
IF NET = 3 THEN HIGH led3
IF NET = 4 THEN HIGH led4
GOTO LOOP
OffLED:
low led1
low led2
low led3
low led4
Goto Loop
end
And thanks again to all who have contributed.
Bookmarks