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

Status
Not open for further replies.

VoltVolt

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.

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

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

Cookies are required to use this site. You must accept them to continue using the site. Learn more…