View previous topic :: View next topic |
Author |
Message |
lgeorge123
Joined: 05 Dec 2004 Posts: 31
|
a very simple question |
Posted: Sun Dec 05, 2004 3:17 am |
|
|
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
|
|
Posted: Sun Dec 05, 2004 7:22 am |
|
|
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.....
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 |
Posted: Sun Dec 05, 2004 7:48 am |
|
|
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
|
|
Posted: Sun Dec 05, 2004 9:16 am |
|
|
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 |
Posted: Sun Dec 05, 2004 9:17 am |
|
|
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
|
|
Posted: Sun Dec 05, 2004 9:28 am |
|
|
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. |
|
|
|