CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modbus address selected with dip switches

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
YeyoPIC



Joined: 13 Dec 2012
Posts: 2

View user's profile Send private message

Modbus address selected with dip switches
PostPosted: Thu Dec 13, 2012 4:48 am     Reply with quote

Hi all, this is my first post here and I want to know how can I make preprocessors directives after of dip switches read.
For example, I am using modbus.c library for some test and I want to read a dip switch connected to portb to assign the modbus address and baudrate. I will take ex_modbus_slave.c, something like this...



Code:

...

#define MODBUS_BUFFER_SIZE 32
#define MODBUS_ADDRESS 1 //here I want to asign the dip switch value
#define MODBUS_SERIAL_BAUD //and here too

...


If I do this could change the address without rewrite the Pic with each address.

How I can do that?

Thanks in advance.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Modbus address selected with dip switches
PostPosted: Thu Dec 13, 2012 6:03 am     Reply with quote

YeyoPIC wrote:
Hi all, this is my first post here and I want to know how can I make preprocessors directives after of dip switches read.
For example, I am using modbus.c library for some test and I want to read a dip switch connected to portb to assign the modbus address and baudrate. I will take ex_modbus_slave.c, something like this...



Code:

...

#define MODBUS_BUFFER_SIZE 32
#define MODBUS_ADDRESS 1 //here I want to asign the dip switch value
#define MODBUS_SERIAL_BAUD //and here too

...


If I do this could change the address without rewrite the Pic with each address.

How I can do that?

Thanks in advance.


If you think a bit more about what you are asking you would realise it is a silly question.

You are asking how a compile time directive can be changed based on the reading of a DIP switch setting at run time. Unless you have implemented in your code, some form of communication system for passing data through worm holes traversing parallel universes, it is not possible.

Instead should be asking yourself, how can I populate a variable at run time from the setting of DIP switches than can then be used to configure the modbus address.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
YeyoPIC



Joined: 13 Dec 2012
Posts: 2

View user's profile Send private message

PostPosted: Thu Dec 13, 2012 6:23 am     Reply with quote

Sorry, I'm wrong.

My question is exactly that "how can I populate a variable at run time from the setting of DIP switches than can then be used to configure the modbus address."

Do you know how I can do that?.

Thanks in advance.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 13, 2012 6:50 am     Reply with quote

comment..
a quick look in the 'examples' folder that CCS supplies shows several programs that do what you want.
One, I think named ' patg.c' should have the code snippet you need.


If it's not that program, check some of the others....or read the FAQ section of the onscreen Help files(press F11 when project is open).

All you're doing is reading an I/O port or part of one, then writing the data into a variable(RAM).
Obviously it's up to you as to which I/O port, pins,data manipulation,etc. as it is your program not mine.

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 13, 2012 1:49 pm     Reply with quote

Quote:
how can I populate a variable at run time from the setting of DIP switches

Connect the 8-position DIP switch to an i/o port on the PIC.
Each individual DIP switch circuit should look like this:
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
                              --- GND
                               -   

You can use a larger resistor value. Instead of an external pull-up
resistor, you can enable the built-in pullup resistors on PortB (if the DIP
switch is connected to PortB).

Assuming you're using PortB with the internal pull-ups, the following
code will read the dip switches when the PIC first starts running:
Code:

void main()
{
int8 dipsw_value;

port_b_pullups(0xFF);
delay_ms(1);

dipsw_value = input_b();  // Read dip switches

// Do something here.

while(1);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group