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

how to output a 16bit value to two 8 bit ports

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



Joined: 23 Jan 2007
Posts: 12

View user's profile Send private message

how to output a 16bit value to two 8 bit ports
PostPosted: Tue Jan 23, 2007 8:23 am     Reply with quote

Hi

I would like to know if its possible to output a 16bit value to two 8 bit ports and how to do it. The pic that I'm using is: pic16f917

My aim is to control 16 led's connected to port A and port B with a single hex value. I was successful with controlling port A with a single hex value.

here is my setup code with two code arrays:

#include <16F917>
#fuses INTRC_IO,NOPROTECT,NOWDT,PUT
#use delay(clock=8000000)
#use standard_io(a)
#use standard_io(b)
#use standard_io(c)
#use standard_io(d)
#case

const unsigned int A[10] = {0xFFF8, 0xFFFC, 0x0186, 0x0183, 0x0181, 0x0181, 0x0183, 0x0186, 0xFFFC, 0xFFF8}; //A

const unsigned int a[5] = {0x7C, 0x12, 0x11, 0x12, 0x7C}; //a

void main()
{
setup_lcd(LCD_DISABLED); // disables lcd display to access digital outputs
for (;;)
{
delay_ms(1000);
output_a(a[0]); // 1st line of a
}

}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 23, 2007 8:29 am     Reply with quote

How about using make8() to split the bytes, and dealing with each byte seperately?
_________________
The search for better is endless. Instead simply find very good and get the job done.
brood



Joined: 23 Jan 2007
Posts: 12

View user's profile Send private message

PostPosted: Tue Jan 23, 2007 9:01 am     Reply with quote

I think that might just do the trick

Thank you very much Wink
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 23, 2007 9:24 am     Reply with quote

you could also try fastio.
set the tris.
use a #byte to define where it is placed.
((or overlayed, how ever you want to think of it))
It uses the location and the next. ie: portA and port B
Code:
#use fast_io(A)
#use fast_io(B)
struct PINS
{
   int16 leds;
};
struct PINS my;
#byte my= 0x05   //note: no semicolin    0x05=A0 on a 16F877

my.leds=0xABCD;

I chopped apart my code... I hope it still works

Don't forget to set tris A and B it isn't shown in this code.
mrpicing



Joined: 22 Oct 2005
Posts: 20

View user's profile Send private message

an other way
PostPosted: Sun Jan 28, 2007 11:10 am     Reply with quote

you can do it as below.

Code:
unsigned long port16;  //it will accupy two bytes. byte 5, byte 6
#byte port16=5  /* porta address. check porta adress form device data sheet*/
/* other code*/

port16= 0xffff;  //put ur data as this
/* other code*/
brood



Joined: 23 Jan 2007
Posts: 12

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 3:30 pm     Reply with quote

Thank you for all the replies it solved lots of problems that I had. Everything is up and running now. I used make8() in the end and passed two 8bit values to my output function.

Wink
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