kevlar129bp
- 10th December 2006, 04:41
I am a newbie, to say the least, to pic programming. I have a bit of vb software that i would like to use to control simple outputs on a pic. I believe the application is commonly referred to as a relay controller. I don't really need design help, moreover serin command help. I am using an example from http://www.rentron.com/PIC16F84.htm. I'll be using a PIC16F871.
Here's some of the code...
INCLUDE "bs2defs.bas"
DEFINE OSC 20
address VAR b2 'board number storage variable
relay VAR b3 'relay number storage variable
stat VAR b4 'relay status ON/OFF variable
serpin VAR porta.0 'serial input pin
trisa = %00000001
trisb = %11111111
trisc = %00000000
trisd = %00000000
trise = %00000000
addr = portb
If address = addr Then
SERIN serpin,N9600,board,relay,stat
SELECT CASE relay
CASE 1
IF stat = 1 THEN HIGH PORTA.1
LOW PORTA.1
CASE 2
IF stat = 1 THEN HIGH PORTA.2
LOW PORTA.2
CASE 3
IF stat = 1 THEN HIGH PORTA.3
LOW PORTA.3
CASE 4
AND SO ON.....
My question is in regards to the use of portb as the 8 bit address for the pic itself. I would like to send a command from the pc to the pic similar to:
MSComm1.Output = address + relay + stat
I would like the pic to allow further processing only upon matching the portb status to the incoming address. Wow, I hope I explained that well enough!?
My goal is to have a few of these boards on the same serial bus, and be able to address each output individually. Well, hopefully one of you gurus can steer me in the right direction.
Thanks to all,
Chris
Here's some of the code...
INCLUDE "bs2defs.bas"
DEFINE OSC 20
address VAR b2 'board number storage variable
relay VAR b3 'relay number storage variable
stat VAR b4 'relay status ON/OFF variable
serpin VAR porta.0 'serial input pin
trisa = %00000001
trisb = %11111111
trisc = %00000000
trisd = %00000000
trise = %00000000
addr = portb
If address = addr Then
SERIN serpin,N9600,board,relay,stat
SELECT CASE relay
CASE 1
IF stat = 1 THEN HIGH PORTA.1
LOW PORTA.1
CASE 2
IF stat = 1 THEN HIGH PORTA.2
LOW PORTA.2
CASE 3
IF stat = 1 THEN HIGH PORTA.3
LOW PORTA.3
CASE 4
AND SO ON.....
My question is in regards to the use of portb as the 8 bit address for the pic itself. I would like to send a command from the pc to the pic similar to:
MSComm1.Output = address + relay + stat
I would like the pic to allow further processing only upon matching the portb status to the incoming address. Wow, I hope I explained that well enough!?
My goal is to have a few of these boards on the same serial bus, and be able to address each output individually. Well, hopefully one of you gurus can steer me in the right direction.
Thanks to all,
Chris