Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Addressing I/O in Sections (http://www.chiefdelphi.com/forums/showthread.php?t=39653)

astro1652 15-09-2005 22:38

Addressing I/O in Sections
 
I was wondering if it is possible to address sections of the I/O of the RC all at once. For example, I have a parallel LCD which uses 8 I/O lines for data. Thus, I want 8 pins of the I/O to be assigned either high or low at the same time instead of addressing them individually.

Code:

LCD_port = 5;
Assuming you can assign LCD_port a number of I/O pins, then telling it to assign 5 would turn on pins (bits) 0 and 2 (5 in binary is 101).

Is there anyway to do this that I am unaware of? Similarly, can I access just the upper and lower half of an unsigned int somehow? Please pardon me if these sound like n00b questions, as I am certainly a beginner in the C language.

BrianBSL 16-09-2005 00:11

Re: Addressing I/O in Sections
 
Just a quick disclaimer - I'm not a programmer.

Are you looking to do it for ease or because you don't want the delay?

Have you tried it just doing them one-by-one? The digital IO of the PIC changes so quickly that I can't see it really being an issue doing them one by one. Otherwise, I'm pretty sure it would not be possible to do, as there are not 8 digital out's all on the same 8-bit port, except relay outputs, all 8 fowards are on port E and all 8 reverse's are on port D. If you used the relay outputs, you could just assign to the output byte for the respectable port (i think). If you just wanted ease, couldn't you write a function to split up your char input and assign it to the correct digital out bits?

sciguy125 16-09-2005 00:43

Re: Addressing I/O in Sections
 
I fully agree with Brian's assessment. Here's a little primer on PICs:

All the I/O lines are grouped into "ports". Each port can be viewed as a memory address. Each line corresponds to a bit in the char stored at the address. If you change whatever is at the address, you change the respective lines. If you look at the block of code in ifi_aliases.h starting at line 109, you can see which digital I/Os correspond to which ports on the processor. You'll notice that the biggest set of digital I/Os is only 7 bits wide.

As Brian pointed out, if you really need all 8 bits, it shouldn't be too hard to just write a function to handle each bit individually. Maybe something along the lines of
Code:

digital_io_01 = my_char >> 7;
digital_io_02 = (my_char & 64) >> 6; //64 is binary 010000000
digital_io_03 = (my_char & 32) >> 5; //32 is binary 001000000
...

Google "bitwise operators" if you don't know about them.

Ryan M. 16-09-2005 15:35

Re: Addressing I/O in Sections
 
First off, I agree with Briand and sciguy. :)

However... theoretically, it may be possible to do what you want. There are a couple of things which have to be true: (and may not be, I've never tried doing this.)
  • The PIC ports have to be controlled by actual memory locations, not some seperate internal thing. (I think that's true.)
  • The PIC port memory locations have to be in consectutive locations every compile.
Assuming that both of those are true, you can probably create a char pointer to the first port that controls your LCD, then assign that the integer you want.

Rickertsen2 16-09-2005 17:06

Re: Addressing I/O in Sections
 
I'm assuming you are using an HD44780 compatible LCD. You don't need 8 pins that can be adressed as a group, only 4 if you use the LCD in 4-bit mode. All you have to do is setup the IO correctly and write to to the appropriate port register. Really, you don't actually need to have them written to at once since data is read in by the LCD only when you tell it to. I have controlled an HD44780 LCD using toggle switches before. Obviously, timing does not matter at all.

You will of course still need 3 more pins for E, R/W, and RS.

devicenull 16-09-2005 22:23

Re: Addressing I/O in Sections
 
I think he's more going for ease of use.. in which case:

#define LCD_Port digital_io_01 = digital_io_02 = digital_io_03 ...etc

Kevin Watson 16-09-2005 23:01

Re: Addressing I/O in Sections
 
Quote:

Originally Posted by astro1652
...I have a parallel LCD which uses 8 I/O lines for data...

If your LCD uses the Hitachi HD44780 controller, the C18 libraries contain functions to handle the interface for you. I keep the latest version of the C18 library documentation here: http://kevin.org/frc. See page 75.

-Kevin

Rickertsen2 18-09-2005 19:28

Re: Addressing I/O in Sections
 
Quote:

Originally Posted by Kevin Watson
If your LCD uses the Hitachi HD44780 controller, the C18 libraries contain functions to handle the interface for you. I keep the latest version of the C18 library documentation here: http://kevin.org/frc. See page 75.

-Kevin

wow. I'm getting rusty. I can't believe i forgot all about those.


All times are GMT -5. The time now is 04:31.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi