|
|
View previous topic :: View next topic |
Author |
Message |
Ormiga Guest
|
PORT C problem on PIC18F2550 |
Posted: Sun May 25, 2008 10:12 pm |
|
|
Hi all,
I'm having problem to use the pins C4 and C5 as digital inputs on a PIC18F2550. They always being read as "0". I already look the UCON register and the USBEN (bit 3 of UCON) is set to "0" (USB disable).
What i'm doing wrong? I saw in the datasheet that at the power on, these pins are configured as input.
I'm using the function input(PIN_C4), but i already used the input_C() and C4 and C5 always "0". I checked the hardware too, the pin voltage is 5v...
Please, somebody help me.
Thank's
Ormiga |
|
|
sv_shady
Joined: 07 Mar 2008 Posts: 28
|
|
Posted: Sun May 25, 2008 11:29 pm |
|
|
Post your source, otherway we are just having a chat |
|
|
Guest
|
|
Posted: Mon May 26, 2008 4:51 am |
|
|
Shady,
My code is too big to post it all.
The CB's are
///////////////////////////////////////////////////////////////////
#include <18F2550.h>
#device adc=10
#device icd=true
#fuses HS,DEBUG,NOVREGEN
#use delay(clock=20000000)
#use i2c(Master,slow,sda=PIN_C7,scl=PIN_C6)
.
.
.
void main()
{
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_16,255,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
range_gain();
strat0=input(PIN_C5);
strat1=input(PIN_C4);
strat1=strat1<<1;
strat=strat1+strat0;
.
.
.
/////////////////////////////////////////////
input(PIN_C5) and input(PIN_C4) returns always 0.
I know that these pins are multiplexed with USB drive (D+ D-), but USB disble is default at power on. I can't understand what's wrong...
Are these pins mapped in ccs pcwh?
Thank's
Ormiga |
|
|
Ttelmah Guest
|
|
Posted: Mon May 26, 2008 8:47 am |
|
|
Is this with a simulator, or the real chip?.
Using the MPLAB simulator, it doesn't work....
If you don't get involved with CCS at all, but generate literally a couple of line assembler program, to loop, then use the external stimulus ability, to set C0 high, then C4 high, and C5 high, you will see that the F82 register (which should reflect the input), does not respond to these higher pins, but happily responds to C0. It could be a simulator fault, or it may be that something else is involved in the config. However looking through the data, nothing else should be involved, and the sheet says that the pins should be set as logic inputs on boot....
TRIS is not involved (not implemented for these pins, which are meant to be input only), and the register access done by CCS, is 'correct', to access the pins (wouldn't apply to the assembler test outlined, which shows the same behaviour).
Annoyingly, the data sheet, does not give a logic diagram of the input section of this pin, making any guessing what else may be involved impractical.
If you are using the sim, I'd say this may well be a simulator fault.
Best Wishes |
|
|
Guest
|
|
Posted: Mon May 26, 2008 9:10 am |
|
|
Ttelmah,
I'm not using sim, i'm just debugging the real circuit with ICD-U40. I know that there are no TRIS bit associate to the pins C4 and C5. How you said, they should wake up as digital input.
Watching the register at debugging, i can see the portC register changing in C7 and C6 (my hardware provide external level input), but not in C4 and C5. I also watch the UCON register, and as spec, bit 3 is 0.
Can you think any other problem with my code?
Thank'
Ormiga |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 26, 2008 11:36 am |
|
|
Quote: |
Must I also set the bit 3 of UCFG to 1 in order to use the pin as digital inputs ?
|
Read the data sheet.
It says:
Quote: |
Note: On a Power-on Reset, these pins, except
RC4 and RC5, are configured as digital inputs.
To use pins RC4 and RC5 as digital inputs, the
USB module must be disabled (UCON<3> = 0)
and the on-chip USB transceiver must be
disabled (UCFG<3> = 1).
|
|
|
|
Ttelmah Guest
|
|
Posted: Mon May 26, 2008 2:38 pm |
|
|
That isn't the answer PCM.
I had tried in CCS, with the following code, before posting:
Code: |
#bit usbtrans=0xF6F.3
#bit USBON=F6D.3
void main()
{
int8 strat0,strat1;
USBON=0;
usbtrans=1;
strat0=input(PIN_C5);
strat1=input(PIN_C4);
while(true) ;
}
|
In the monitor, it still sits ignoring the external pins.
USBON (USBEN), is 'zero' by default, so you only have to set UTRDIS. I was doing this in the assembler.
I suspect it is a fault in the simulator, since I think I have used the pins in the past OK, on a real chip.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 26, 2008 2:51 pm |
|
|
I'm not sure where I said anything wrong. I made this test program
and it works.
Here's the output when I press a switch on pin C4. The 0's represent
the time when the switch is pressed (connected to ground).
Quote: | 111111111111111110000000111111000001111111111 |
Code: | #include <18F4550.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#byte UCFG = 0xF6F
#bit UTRDIS = UCFG.3
//==========================
void main()
{
UTRDIS = 1;
while(1)
{
if(input(PIN_C4))
putc('1');
else
putc('0');
delay_ms(200);
}
} |
|
|
|
Ttelmah Guest
|
|
Posted: Tue May 27, 2008 3:02 am |
|
|
Ok. You are fractionally missing the point I was making.
There is a separate fault, in at least one version of MPLAB (I have tested 7.50, and 8.10), which stops the inputs working _in the simulator_, even if everything is setup right. This was why I queried the simulator/chip in the original posting. It is a caveat, for anyone wanting to test a setup using these pins.
Have just tested your code, and it too, does not respond to an external pin stimulus on these pins.
Best Wishes |
|
|
taniguti
Joined: 13 Apr 2013 Posts: 1
|
I have this problem too. → I solved this problem. |
Posted: Sat Apr 13, 2013 8:43 pm |
|
|
REQUIRE: PIN_C4, PIN_C5 use digital input.
DO: UPUEN, UTRDIS bits is 0.
UPUEN is 0 at powerON (not describe).
UTRDIS is 0 by this source.
Code: |
#byte UCFG = 0xF6F
#bit UTRDIS = UCFG.3
UTRDIS = 1;
|
RESULT : OK!
thank you for this page. |
|
|
|
|
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
|