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

a very simple question

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



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

a very simple question
PostPosted: Sun Dec 05, 2004 3:17 am     Reply with quote

Hi,I have a program to output LED matrix display using 18f452.
set_tris_b(0);
port_b=0;
for(i=0;i<4;i++)
portb=ledarray[i];
Many tries i still get portb nothing output.
in 16f877,the following codes is sucess.
set_tris_b(0);
port_b=0;
portb=0xff;
the portb output really 0xff.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Dec 05, 2004 7:22 am     Reply with quote

Quote:
set_tris_b(0);
port_b=0;
for(i=0;i<4;i++)
portb=ledarray[i];
Many tries i still get portb nothing output.

Wow!! You really must have great eyes when you can see a led blinking at a frequency of over 1 MHz..... Smile
Please insert a delay function so you can see the led's changing state, something like:
Code:
set_tris_b(0);
port_b=0;
for(i=0;i<4;i++)
{
  portb=ledarray[i];
  delay_ms(1000);
}


If this doesn't fix your problem then please post a full copy of your program, important information like the definition of ledarray[] and the #fuses statement are missing.
lgeorge
Guest







a very simple question
PostPosted: Sun Dec 05, 2004 7:48 am     Reply with quote

actually i wants to how to write the code of using portb as output in using 18f452. In using 16f877,the following code is working:
set_tris_b(0);
portb=0xff;
under MPLAB6,portb output ff, but if i use 18f452,the above code fail.
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Sun Dec 05, 2004 9:16 am     Reply with quote

When you switched from the 16F877 to the 18F452, did you change the address of the ports? They are relocated to different addresses on the 452. A typical port address assignment for the 877 would look something like this:

Code:

#byte port_a = 5
#byte port_b = 6
#byte port_c = 7
#byte port_d = 8
#byte port_e = 9

While the address assignment for the 452 would look something like this:
Code:

#byte port_a = 0x0F80
#byte port_b = 0x0F81
#byte port_c = 0x0F82
#byte port_d = 0x0F83
#byte port_e = 0x0F84
lgeorge333
Guest







a very simple question
PostPosted: Sun Dec 05, 2004 9:17 am     Reply with quote

now i solve the program,#byte portb 0xf81 should be used instead of
#byte portb =6
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Dec 05, 2004 9:28 am     Reply with quote

Like I said before, would you have posted a complete program we would have been able to spot your problem much faster.

Another difference between PIC16 and PIC18 ports is that the PIC18 has a latch register added which makes it easier to read back the current port values. Normally on a PIC18 you write to this latch register instead of to the port itself. Very confusing isn't it? In order to make things easier to yourself use the CCS function output_b(). This way you don't have to remember all differences between PIC16 and PIC18, the same code will be running on both families.
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