PDA

View Full Version : PIC 18f4680 DIGITAL INPUTS



MegaADY
- 27th June 2006, 23:20
Hello ! I have a problem working with registers of pic18f4680
I want all pins on all ports as digital IO ( except MCLR which I configured as MCLR , not IO ) . I just can't make it, I've read the datasheet a lot, but no success. I make some ports digital configuring ADCON1 and INTCON , fut he others are turning to analog and so on. I need them all digital IO's.
Thank you very much for your support.

mister_e
- 28th June 2006, 03:40
As i remind those line should help


CMCON = 7
ADCON1 = $0F

MegaADY
- 28th June 2006, 08:07
Thanks for reply man, but it's not enough ! I am using theese two lines also

Melanie
- 28th June 2006, 11:08
Datasheet...

Section 10... let's look at this Port by Port...

PortA

Look at Table 10-2... immediately you can see you need to Disable Comparators, Voltage Reference Module and ADC's...

Jump to Comparator Module, see Register 20-1 and Figure 20-1 from those you can determine to knock-out the Comparators you don't need...

CMCON=%00000111

The Comparator has a Voltage Reference Module... jump to Register 21-1 and make sure it's OFF...

CRVCON=%00000000

Next, kill the ADC's...

Section 19 for ADC's, Register 19-1...

ADCON0=%00000000

and Register 19-2 make your selection from the table...

ADCON1=%00001111

All you're left with is configuring TRISA for your I/O application...

Now go back to Section 10 for...

PortB

Table 10-4 tells you ADC's affect this Port, but you've probably killed them with the ADCON statements you did above at PortA.

PortC

Table 10-6 tells us PortC has no issues...

PortD

Table 10-8 tells us that PortD has PWM's and a Parallel Slave Port.

By default, PWM's don't affect us - but if you want to be safe...

ECCP1CON=%00000000

A look at PSPMODE bit 4 of TRISE (OK, I didn't build this chip, so don't moan at me for having to look in TRISE for a PORTD control Bit), at Section 10-5 TRISE Register 10-1 on Page 142 tells us you need this bit to be ZERO for General Purpose I/O...

TRISE.4=0

PortE

Table 10-10 tells us that Comparators and ADC's affect this Port. But, you've probably switched them off back above at PortA stage...

OK... is there a problem?

PS, please keep problems on the forum...

MegaADY
- 28th June 2006, 16:36
Thank you very much Melanie for your support .

MadAl
- 15th March 2008, 19:50
Hi,

just ported a program from 16F877 to this PIC. And Port D refuses to act as an input.
I tried the following program snippet:

ECCP1CON=%00000000
TRISE.4=0
TRISD=%0001111

IF PORTD.2=1 THEN
HIGH beeper
PAUSE 1000
LOW beeper
ENDIF

I put a 1k resistor from Vdd (5V) to port D2. The beeper doesn't sound. When I change the conditional statement to "PORTD.2=0",then the beeper sounds, even with the resistor connected! I checked for shorts, and no there is no short from D2 to GND.
I also tried ports D1 and D3: same result...
For some reason ports D refuse to become input and stay output low.....

Another funny thing is that I use PortA0 as AD converter. If I connect 3V to this port, the PIC heats up like crazy (not so with the same PCB and 16F877)
When I put a 100k in series with this pin, the AD works OK and PIC doesn't heat up.
So also this pin acts as active low, even in AD mode....


Any ideas what more to try?

MadAl
- 15th March 2008, 20:03
The following lines solved the (first) problem:

CMCON7=0
ECCP1CON=%00000000
TRISE.4=0
TRISD=%0001111

Amazing that a simple "INPUT PORTD.2" doesn't do it.

I will study the datasheet on the CMCON stuff.

thanks

MadAl
- 29th July 2008, 19:00
Melanie,

I followed your register tutorial and ran into the following snag:

I use HSEROUT on port C6 (the hardware Tx pin) and all works fine.
However when I issue a SEROUT2 command on that pin, the pin remains silent (no activity on that pin using the oscilloscope). The very same SEROUT2 command on port A1 gives activity on the scope screen.
I assume the same applies to the SERIN2 on port C7.
What am I missing here?

skimask
- 29th July 2008, 21:50
I use HSEROUT on port C6 (the hardware Tx pin) and all works fine.
However when I issue a SEROUT2 command on that pin, the pin remains silent (no activity on that pin using the oscilloscope). The very same SEROUT2 command on port A1 gives activity on the scope screen.
I assume the same applies to the SERIN2 on port C7.
What am I missing here?

If the port is still set up to use the hardware serial port, SERIN/SEROUT won't work. The port has to be set up for normal, general purpose I/O to work with SERIN/SEROUT.

MadAl
- 30th July 2008, 07:09
Hi,

I thought about that. I removed the hardware serial defines at the start of the program, and the problem remains.
Or is there another way to disable HW serial?
Btw I tried the same with a 16F877 and also there the same issue exists.

Bruce
- 30th July 2008, 07:29
Try this;



DEFINE HSER_BAUD 9600

Main:
HSEROUT ["HSER",13,10]
PAUSE 500
SEROUT2 PORTC.6,84,["WITH RCSTA.7=1",13,10]
PAUSE 500
RCSTA.7=0
SEROUT2 PORTC.6,84,["WITH RCSTA.7=0",13,10]
PAUSE 500
RCSTA.7=1

GOTO Main

You should get this;

HSER
WITH RCSTA.7=0
HSER
WITH RCSTA.7=0

With RCSTA.7 set the USART takes over these pins.

MadAl
- 30th July 2008, 07:34
Excellent, will try that.
I'm convinced it'll work.
thanks