Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [Help] Using PIC to provide 5V

Status
Not open for further replies.

VoltVolt

Junior Member level 1
Junior Member level 1
Joined
Sep 15, 2013
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
124
I'm using PIC18F45K22...

My PIC is just connected to ICSP Header from PICKIT2...
What I want is let all the PIC output pins to provide 5V(except MCLR and Vss).
This is my code:
Code:
#include <htc.h>

/* Start of configuration fuses*/
#pragma config IESO=OFF, FOSC=INTIO67,PRICLKEN=OFF,FCMEN =OFF,PLLCFG=ON,BOREN=ON,BORV=250
#pragma config WDTEN=OFF
#pragma config P2BMX=PORTC0,CCP2MX=PORTC1,PBADEN=OFF,CCP3MX=PORTE0,MCLRE=INTMCLR,HFOFST=OFF,T3CMX=PORTC0
#pragma config DEBUG=OFF,STVREN=ON,XINST=OFF,LVP=OFF
#pragma config CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF
#pragma config CPB=OFF,CPD=OFF
#pragma config WRT0=ON,WRT1=ON,WRT2=ON,WRT3=ON
#pragma config WRTB=ON,WRTC=ON,WRTD=ON
/* end of configuration fuses */

void main()
{
    OSCCON=0b11110011;
    OSCCON2=0b00000000;

    ANSELA = 0x00;      //Configure all ports as I/O digital
    ANSELB = 0x00;
    ANSELC = 0x00;
    ANSELD = 0x00;
    ANSELE = 0x00;

    TRISA=TRISB=TRISC=TRISE=1;      //set all ports as input

    LATA = LATB = LATC = LATD = LATE = 0xFF;
}

Result:
Some giving 5V as I expected, but some didn't...
Below are those pins which unable to provide 5V output...
-RA0 1.3V
-RE0 1.3V
-RE1 0v
-RE2 0v
-RC0 1.3v
-RD0 1.3v
-RD1 1.3v
-RD2 1.3v
-RD3 1.3v
-RD4 1.3v
-RD5 1.3v
-RD6 1.3v

Thank you...
 

TRISA=TRISB=TRISC=TRISE=1; //set all ports as input
Involves a double fault.
- to set all port as inputs, you would write 0xff to the TRISx registers (this is the default state after reset, by the way, so you won't need to set it).
- to apply high level to all GPIO pins, they must be switched to output, TRISx=0

You don't need to write ANSEL for output pins, but there's nothing against it.
 
Aww...
But now at least all the pins giving 5V, EXCEPT PORTD...
PORTD(RD0~RD7) giving 0V
What happen to port D register?
 

Aww...
But now at least all the pins giving 5V, EXCEPT PORTD...
PORTD(RD0~RD7) giving 0V
What happen to port D register?

PIC18F45K22 PortD pins are invert.


Best regards,
Peter
 
PIC18F45K22 PortD pins are invert.

The PIC18F45K22 PORTD pins are NOT inverted.

Reference:pIC18(L)F2X/4XK22 Datasheet, Section: 10.5 PORTD Registers, Page:
10.5 PORTD Registers

Note:
PORTD is only available on 40-pin and
44-pin devices.

PORTD is an 8-bit wide, bidirectional port. The
corresponding data direction register is TRISD. Setting
a TRISD bit (= 1) will make the corresponding PORTD
pin an input (i.e., disable the output driver). Clearing a
TRISD bit (= 0) will make the corresponding PORTD
pin an output (i.e., enable the output driver and put the
contents of the output latch on the selected pin).
The Data Latch register (LATD) is also memory
mapped. Read-modify-write operations on the LATD
register read and write the latched output value for
PORTD.

All pins on PORTD are implemented with Schmitt
Trigger input buffers. Each pin is individually
configurable as an input or output.

All of the PORTD pins are multiplexed with analog and
digital peripheral modules. See Table 10-11.

Note:
On a Power-on Reset, these pins are
configured as analog inputs.

Most likely, as FvM indicated, the TRISD register was not properly cleared (TRISD = 0x00), as in your initial posted code.

BigDog
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top