View previous topic :: View next topic |
Author |
Message |
brood
Joined: 23 Jan 2007 Posts: 12
|
how to output a 16bit value to two 8 bit ports |
Posted: Tue Jan 23, 2007 8:23 am |
|
|
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
|
|
Posted: Tue Jan 23, 2007 8:29 am |
|
|
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
|
|
Posted: Tue Jan 23, 2007 9:01 am |
|
|
I think that might just do the trick
Thank you very much |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Jan 23, 2007 9:24 am |
|
|
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
|
an other way |
Posted: Sun Jan 28, 2007 11:10 am |
|
|
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
|
|
Posted: Sun Jan 28, 2007 3:30 pm |
|
|
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.
|
|
|
|