View previous topic :: View next topic |
Author |
Message |
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
Port Configuration (Digital Inputs) |
Posted: Thu Jul 26, 2012 8:16 am |
|
|
Hi there,
I am using a PIC18F4550.
I want configure pins RC4 and RC5 as digital inputs.
page 119 of the datasheet states
Quote: |
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). |
So how do I configure the port for digital?
Thanks
Carl |
|
![](templates/subSilver/images/spacer.gif) |
TMLtech
Joined: 20 Jul 2011 Posts: 21 Location: Finland
|
|
Posted: Thu Jul 26, 2012 11:26 am |
|
|
I use in that way:
#use fast_io(0b00110000); |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 26, 2012 12:58 pm |
|
|
Quote: | I use in that way:
#use fast_io(0b00110000);
|
This answer is incorrect. Please read the CCS manual and verify your
answer before posting.
To answer the question, the USB module is already disabled upon
power-on reset, so you don't need to do it. But the USB transceiver
is enabled by default, so you need to add a line of code at the start
of main() to disable it. See the program shown below:
Code: |
#include <18F4550.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP CPUDIV1
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#byte UCFG = getenv("SFR:UCFG")
#bit UTRDIS = UCFG.3
//=================================
void main()
{
int8 result;
UTRDIS = 1; // Disable USB transceiver
while(1)
{
result = input(PIN_C4);
printf("%u ", result);
delay_ms(500);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
|
Posted: Thu Jul 26, 2012 1:19 pm |
|
|
Thanks PCM,
I will try it tomorrow.
Carl |
|
![](templates/subSilver/images/spacer.gif) |
|