![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
leevise
Joined: 05 Aug 2010 Posts: 89
|
About output_bit() & output_x() discussion |
Posted: Wed Sep 01, 2010 12:50 am |
|
|
Hello guys, I have a question with PIC16f877a.
When I program the C code as follows:
Code: |
#include "D:\PICprogram\12864LCD_20100901.h"
#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(CLOCK=20000000)
#use fast_io(B)
void init_lcd()
{
set_tris_b(0x00);
output_b(0x0f);
}
void main()
{
init_lcd();
while(1);
}
|
My DEMO board PINS are defined as follows:
LED0_RB0-----PIN_B0
LED1_RB1-----PIN_B1
LED2_RB2-----PIN_B2
LED3_RB3-----PIN_B3
The LED1 & LED2 light, the other is not light, this why ?
I have the same question when I use OUTPUT_BIT() in the code as follows:
Code: |
#include "D:\PICprogram\12864LCD_20100901.h"
#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(CLOCK=20000000)
#use fast_io(B)
void init_lcd()
{
set_tris_b(0x00);
output_bit(PIN_B2,1);
output_bit(PIN_B7,1);
output_bit(PIN_B6,1);
output_bit(PIN_B5,1);
output_bit(PIN_B4,1);
output_bit(PIN_B3,1);
output_bit(PIN_B2,1);
output_bit(PIN_B1,1);
output_bit(PIN_B0,1);
}
void main()
{
init_lcd();
while(1);
}
|
I find the PIN_B7,PIN_B6 and PIN_B3 is not output HIGH bit. I know the B7--PGD, B6---PGC, B3---PGM, but how do I set them in order to let them work ok !
Last edited by leevise on Thu Sep 02, 2010 1:12 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
leevise
Joined: 05 Aug 2010 Posts: 89
|
why ? |
Posted: Wed Sep 01, 2010 7:10 pm |
|
|
I don't know if I went wrong in code, or the DEMO board is bad? |
|
![](templates/subSilver/images/spacer.gif) |
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Wed Sep 01, 2010 7:30 pm |
|
|
I/O pins can have multiple uses, so you have to disable those peripherals that are not being used.
Check with the datasheet to which are applicable for the PIC you're using and disable are required. |
|
![](templates/subSilver/images/spacer.gif) |
leevise
Joined: 05 Aug 2010 Posts: 89
|
I only use the I/O |
Posted: Wed Sep 01, 2010 8:06 pm |
|
|
jbmiller wrote: | I/O pins can have multiple uses, so you have to disable those peripherals that are not being used.
Check with the datasheet to which are applicable for the PIC you're using and disable are required. |
I know the PIN has multiple uses, but it works OK ago.
I don't open the multiple use PIN, because the Default State is closed, isn't it?
And I set the FUSES:
Code: |
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT |
I test the voltage of RB, I got the result:
PIN_B7=0V
PIN_B6=0V
PIN_B5=5V
PIN_B4=5V
PIN_B3=0.12V
PIN_B2=4.68V
PIN_B1=4.66V
PIN_B0=1.56V |
|
![](templates/subSilver/images/spacer.gif) |
leevise
Joined: 05 Aug 2010 Posts: 89
|
Very puzzle thing !!!!!i will crazy !!!! |
Posted: Wed Sep 01, 2010 11:33 pm |
|
|
I check the RC and I find these things
in code define PIN ------match--------DEMO BOARD PIC PIN
PIN_C0---------------------------------- NOthing
PIN_C1----------------------------------NOthing
PIN_C2----------------------------------C0
PIN_C3----------------------------------C1
PIN_C4----------------------------------C2
PIN_C5----------------------------------C3
PIN_C6----------------------------------C4
PIN_C7----------------------------------C5
I mean the define PINs can't match actual PINs. When I use the "output_bit()"command, occur above thing.
But I use the "output_c(0xff)", the RC all output signal. I am very puzzled, I will go crazy !!
Pls so everyone tell me why this is ?
My test code as follow:
Code: | #include <16f877a.h>
#device icd=ture
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(CLOCK=20000000)//When use the TMR0 ,not use the delay
#use fast_io(C)
void init_lcd()
{
set_tris_c(0x00);
//output_c(0x00); //output_c(0xff);
output_bit(PIN_C2,1); // C0
output_bit(PIN_C7,1); //C5
output_bit(PIN_C6,1); //C4
output_bit(PIN_C5,1); //C3
output_bit(PIN_C4,1); //C2
output_bit(PIN_C3,1); //C1
output_bit(PIN_C1,1);
output_bit(PIN_C0,1); //
}
void main()
{
init_lcd();
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Sep 02, 2010 3:28 am |
|
|
Quote: | I don't open the multiple use PIN, because the Default State is closed, isn't it? | No. You have to check the datasheet for each pin. Too bad the PIC16F87xA datasheet is not very clear in this, the datasheets for newer processors have the default state listed in a table.
For example, at start up, all analog pins are activated. To use them for digital inputs you have to disable the analog function on these pins.
To play it safe it is best to add code at the startup of your program that disables all the units you don't use.
Does this compile without errors? Please fix the typo as now you have undefined behaviour.
Which demo board are you using? Post the manufacturer and model number. Even better when you can post a link to the website and schematic.
Post your compiler version number. |
|
![](templates/subSilver/images/spacer.gif) |
leevise
Joined: 05 Aug 2010 Posts: 89
|
I use the Microchip demo board |
Posted: Thu Sep 02, 2010 6:56 pm |
|
|
Good morning guys, I use the MICROCHIP demo board "PICDEM 2 PLUS DEMO BOARD "2002 version. The complier I use is the PCWHD 4.088.
I already know the reason about the PIN_B7, PIN_B6, PIN_B3 no output,
I need to disconnect debugger cable from the demo board. They work OK, but the demo RC don't match the define RC, I am not finding the reason. Does RC pin need set the analog ?
ckielstra wrote: | Quote: | I don't open the multiple use PIN, because the Default State is closed, isn't it? | No. You have to check the datasheet for each pin. Too bad the PIC16F87xA datasheet is not very clear in this, the datasheets for newer processors have the default state listed in a table.
For example, at start up, all analog pins are activated. To use them for digital inputs you have to disable the analog function on these pins.
To play it safe it is best to add code at the startup of your program that disables all the units you don't use.
Does this compile without errors? Please fix the typo as now you have undefined behaviour.
Which demo board are you using? Post the manufacturer and model number. Even better when you can post a link to the website and schematic.
Post your compiler version number. |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|