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 support@ccsinfo.com

8-bit microprocessor interface

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



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

8-bit microprocessor interface
PostPosted: Tue Jul 17, 2007 8:38 am     Reply with quote

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).

Rolling Eyes

TIA<
TOM
tom_hanks



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

A numeric expression ???
PostPosted: Wed Jul 18, 2007 9:08 am     Reply with quote

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

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

PostPosted: Wed Jul 18, 2007 9:15 am     Reply with quote

Why use a loop like that? Why not this...

Code:

output_D(data_byte);
tom_hanks



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 9:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 10:10 am     Reply with quote

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

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

PostPosted: Wed Jul 18, 2007 10:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 10:23 am     Reply with quote

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

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

PostPosted: Wed Jul 18, 2007 5:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 18, 2007 6:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 19, 2007 2:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 26, 2007 5:47 am     Reply with quote

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
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