View previous topic :: View next topic |
Author |
Message |
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
8-bit microprocessor interface |
Posted: Tue Jul 17, 2007 8:38 am |
|
|
Dear,
Can anyone provide me some suggestion or example to build a 8-bit uProcessor interface..
System is using PIC18F4320 and 8-bit uP interface(pheripheral chip).
TIA<
TOM |
|
|
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
A numeric expression ??? |
Posted: Wed Jul 18, 2007 9:08 am |
|
|
to write a 8 bit data on D7-D0, i am using following code...
but for a command "output_low(DATA_BIT.D[i]);" compiler is genrating following error.
Error " A numeric expression must appear here "
how can I eliminate this error...
Code: |
while (! input(uP_CLK)); //wait till CLK is low
//write 8bit control byte on D7-D0
for(i=0;i<number_of_bits;++i)
{
if((data_byte & 1) ==0) //AND the LSB bit with one
output_low(DATA_BIT.D[i]);
else
output_high(DATA_BIT.D[i]);
data_byte=data_byte>>1;//shift the bits
} |
|
|
|
Bill Boucher
Joined: 04 Feb 2005 Posts: 34 Location: Chatham,ON,CA
|
|
Posted: Wed Jul 18, 2007 9:15 am |
|
|
Why use a loop like that? Why not this...
Code: |
output_D(data_byte);
|
|
|
|
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
|
Posted: Wed Jul 18, 2007 9:28 am |
|
|
data lines are split between different ports...
like:
D4-D0 RA4-RA0(PortA)
D7-D5 RB3-RB1(PortB)
i tried to use union and #define
but still it not working
cheers,
tom
Code: |
#define DATA_BIT_D[0] PIN_A0
#define DATA_BIT_D[1] PIN_A1
#define DATA_BIT_D[2] PIN_A2
#define DATA_BIT_D[3] PIN_A3
#define DATA_BIT_D[4] PIN_A4
#define DATA_BIT_D[5] PIN_B1
#define DATA_BIT_D[6] PIN_B2
#define DATA_BIT_D[7] PIN_B3
for(i=0;i<number_of_bits;++i)
{
if((data_byte & 1) ==0) //AND the LSB bit with one
output_low(DATA_BIT_D[i]);
else
output_high(DATA_BIT_D[i]);
data_byte=data_byte>>1; //shift the bits
} |
Error
"Duplicate #define" (for #define statment)
" Expecting an identifier"(for output_low(DATA_BIT_D[i]);)
"A numeric expression must appear here" (for output_low(DATA_BIT_D[i]);)
"
" |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 18, 2007 10:10 am |
|
|
Quote: | 8-bit uP interface(pheripheral chip). |
What's the manufacturer and part number of this chip ? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Jul 18, 2007 10:14 am |
|
|
I would do something like this
Code: |
//===== my_output =====//
my_output( int8 data )
{
if(bit_test(data,0)) output_high(PIN_A0); else output_low(PIN_A0);
if(bit_test(data,1)) output_high(PIN_A1); else output_low(PIN_A1);
if(bit_test(data,2)) output_high(PIN_A2); else output_low(PIN_A2);
if(bit_test(data,3)) output_high(PIN_A3); else output_low(PIN_A3);
if(bit_test(data,4)) output_high(PIN_A4); else output_low(PIN_A4);
if(bit_test(data,5)) output_high(PIN_B1); else output_low(PIN_B1);
if(bit_test(data,6)) output_high(PIN_B2); else output_low(PIN_B2);
if(bit_test(data,7)) output_high(PIN_B3); else output_low(PIN_B3);
} |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 18, 2007 10:23 am |
|
|
Port D has a special Parallel Slave Port (PSP) function for interfacing to an 8-bit microcontroller. A waste not to use a feature like that when you get it for free. |
|
|
Bill Boucher
Joined: 04 Feb 2005 Posts: 34 Location: Chatham,ON,CA
|
|
Posted: Wed Jul 18, 2007 5:01 pm |
|
|
tom_hanks wrote: | data lines are split between different ports...
like:
D4-D0 RA4-RA0(PortA)
D7-D5 RB3-RB1(PortB)
i tried to use union and #define
but still it not working
cheers,
tom
Code: |
#define DATA_BIT_D[0] PIN_A0
#define DATA_BIT_D[1] PIN_A1
#define DATA_BIT_D[2] PIN_A2
#define DATA_BIT_D[3] PIN_A3
#define DATA_BIT_D[4] PIN_A4
#define DATA_BIT_D[5] PIN_B1
#define DATA_BIT_D[6] PIN_B2
#define DATA_BIT_D[7] PIN_B3
for(i=0;i<number_of_bits;++i)
{
if((data_byte & 1) ==0) //AND the LSB bit with one
output_low(DATA_BIT_D[i]);
else
output_high(DATA_BIT_D[i]);
data_byte=data_byte>>1; //shift the bits
} |
Error
"Duplicate #define" (for #define statment)
" Expecting an identifier"(for output_low(DATA_BIT_D[i]);)
"A numeric expression must appear here" (for output_low(DATA_BIT_D[i]);)
"
" |
The problem with this...
Code: |
#define DATA_BIT_D[0] PIN_A0
|
is that the string of text "DATA_BIT_D[0]" is equated to the number represented by "PIN_A0". It's not treated as a variable. Whereever "DATA_BIT_D[0]" appears in your program, the text "PIN_A0" is simply substituted. Of course this produces syntax errors.
You have to define an array variable like...
Code: |
int8 DATA_BIT_D[8] = {PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4,PIN_A5,PIN_A6,PIN_A7};
|
and that would work inside your "for loop" using...
Code: |
output_high(DATA_BIT_D[i]);
|
however you have to be aware that older versions of the compiler will not accept a variable in the output_high(), output_low(), or output_toggle() functions. Also, sticking a variable into one of these functions slows it down a lot because the compiler generates significantly more code to determine where the output will go.
I think the solution posted by treitmey is easily the best so far. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 18, 2007 6:00 pm |
|
|
I am betting that his "8-bit uProcessor interface" will turn out to be
an ordinary 16x2 LCD. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 19, 2007 2:14 am |
|
|
PCM programmer wrote: | I am betting that his "8-bit uProcessor interface" will turn out to be
an ordinary 16x2 LCD. | If this is true than he should have a look at the post LCD Control Wires Split Across 2 PORTS. |
|
|
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
|
Posted: Thu Jul 26, 2007 5:47 am |
|
|
thank you every one for your help...
lots of my doubts are clear now..
i have chnged the ckt and now using a Port D for data lines...
cheers,
tom |
|
|
|