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] Pin RA2 dont works as digital

Status
Not open for further replies.

moahrs

Junior Member level 2
Joined
Dec 29, 2011
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,459
Hi all.

I have a big problem. I am a projet school using 18F2550, but a few days, I can't do works the pin RA2 how input digital.

I always read "0" in pin RA2. I put "1" in pin RA2, and still reading "0"....

All other pin was working fine, no trobles, but this pin dont works. I need to believe that the pin was working, but I am doing any worng in program.

Below, the initial configuration in my program.

Ty if any1 can helpme. I am using mplab and c18 compiler. I am brazilian, then some comments in program still in portuguese.


Code:
#define MINOR_VERSION   0x00
#define MAJOR_VERSION   0x01

#define OUT_CTRLWAIT LATAbits.LATA4
#define OUT_INTZ80 LATAbits.LATA5

#define OUT_SDA LATBbits.LATB0
#define OUT_SDL LATBbits.LATB1

#define OUT_TSTR LATAbits.LATA0
#define OUT_TSTY LATAbits.LATA1

#define OUT_CPU0 LATCbits.LATC0
#define OUT_CPU1 LATCbits.LATC1
#define OUT_CPU2 LATCbits.LATC2
#define OUT_CPU3 LATBbits.LATB3
#define OUT_CPU4 LATBbits.LATB4
#define OUT_CPU5 LATBbits.LATB5
#define OUT_CPU6 LATBbits.LATB6
#define OUT_CPU7 LATBbits.LATB7

#define IN_CPU0 PORTCbits.RC0
#define IN_CPU1 PORTCbits.RC1
#define IN_CPU2 PORTCbits.RC2
#define IN_CPU3 PORTBbits.RB3
#define IN_CPU4 PORTBbits.RB4
#define IN_CPU5 PORTBbits.RB5
#define IN_CPU6 PORTBbits.RB6
#define IN_CPU7 PORTBbits.RB7

#define IN_WR PORTAbits.RA3	
#define IN_STATUS_CS2 PORTAbits.RA2	
// WR  | Result
//  0  | WR Data : Z80 -> PIC
//  1  | RD Data : PIC -> Z80

// Private function prototypes
void isr_int2(void);
void isr_lowpri(void);
void EnviaByte(void);
void RecebeByte(void);

// ADC
void LerADC(int vporta);

// USB
void ComunicarUSB(void);

// SERIAL
void ComunicarSerial(void);

//------------------------------------------------------------
// PROGRAMA PRINCIPAL
//------------------------------------------------------------
void main()
{
	// CONFIGURAR PORTAS
	OSCCON = 0xFF;	// Seta Oscilador Interno para 8 MHz
	ADCON1 = 0x0F;	// 0x0D => RA0=AN0, RA1=AN1, TODAS AS DEMAIS ANx = DIGITAIS; 0x0F para testes
	PORTA = 0x30;
	PORTB = 0x00;
	PORTC = 0x00;
	TRISA = 0x0C;   // 0x0F => RA7-X, RA6-X, RA5-INTZ80, RA4-CTRWAIT, RA3-WR, RA2-CS2, RA1-AN1, RA0-AN0; 0x0C para testes
	TRISB = 0xFC;	// RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
	TRISC = 0x97;	// RC7-RX, RC6-TX, RC5-D+, RC4-D-, RC3-X, RC2 A RC0 - D2 A D0

	RCON = RCON | 0x80;
	PIR1 = 0x00;
	PIR2 = 0x00;
	PIE1 = 0x00;
	PIE2 = 0x00;
	IPR1 = 0x00;
	IPR2 = 0x00;
	INTCON = 0xC0;    // 0xC0
	INTCON2 = 0xE0;   // 0xE0
	INTCON3 = 0x90;   // 0x90

	INTCON3bits.INT2IE = 0x00;
	INTCON3bits.INT2IF = 0x00;
	PIE1bits.RCIE = 0x00;
	PIR1bits.RCIF = 0x00;
	PIE2bits.USBIE = 0x00;
	PIR2bits.USBIF = 0x00;

	pbyte = 0x00;
	pfunc = 0x00;
	plerverif = 0x00;
	pbytectrl = 0x00;

	OUT_SDA = 0x00;
	OUT_SDL = 0x00;

	OUT_TSTR = 0x01;
	OUT_TSTY = 0x00;

	INTCON3bits.INT2IE = 0x01;
	
...
}
 
Last edited by a moderator:

Hi horace1,

In my code, have this settings:

ADCON1 = 0x0F; // 0x0D => RA0=AN0, RA1=AN1, ALL OTHER ANx = DIGITAL's; 0x0F for test

And from datasheet, 0b00001111 is all ports digital.


Ty
Moacir Jr.
 

Could it have something to do with the comparator settings?
RA2 is also an analog input to the comparator.

Reg CMCOM
 
  • Like
Reactions: moahrs

    moahrs

    Points: 2
    Helpful Answer Positive Rating
you set TRISA
Code:
	TRISA = 0x0C;
which sets RA0 and RA1 as output and RA2 and RA3 as input, which should work
 
  • Like
Reactions: moahrs

    moahrs

    Points: 2
    Helpful Answer Positive Rating
Could it have something to do with the comparator settings?
RA2 is also an analog input to the comparator.

Reg CMCOM

Hum. I understandod. I thinked that when I put ADCON1 in 0x0F, putting RA1 to RA3 to digital, the CMCOM was assigned to all digital and not comparator.

I was put CMCOM = 0x07, and testing and put here the results.

Ty for help
Moacir Jr
 

Guys,

Nothing. I put the code below. I dont understand whats happen. I setup adcon1, cmcon, trisa and other, but nothing. But one curiosity: How digital output, all pins works very fine. My problem is only in port "A".

Have any possibility that how my port "A" don't works how digital input, my 18f2550 is broken ?

The unique port "A" that works how input or output digital is RA4. RA0, RA1, RA2, RA3 and RA5 only works how output digital.

I need at least one porta "A" how digital input. All others can be how output digital.

PS: I use the USB to program my 18f2550, and have worked very well, I think, rsssss...

CODE BELOW:
// Configurações do PIC
#pragma config CPUDIV = OSC1_PLL2, USBDIV = 2, PLLDIV = 5 // CONFIG1L
#pragma config FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, VREGEN = ON // CONFIG2L
#pragma config WDT = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = ON // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF // CONFIG5L
#pragma config CPB = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF // CONFIG7L
#pragma config EBTRB = OFF // CONFIG7H

// INTERRUPÇÕES
#define REMAPPED_RESET_VECTOR_ADDRESS 0x0800
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x0808
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x0818

#pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS
void _reset (void)
{
_asm goto 0x0838 _endasm
}

#pragma code high_vector = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS
void high_interrupt (void)
{
_asm GOTO isr_int2 _endasm
}
#pragma code

#pragma code low_vector = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS
void low_interrupt (void)
{
_asm GOTO isr_lowpri _endasm
}
#pragma code

//------------------------------------------------------------
// PROGRAMA PRINCIPAL
//------------------------------------------------------------
void main()
{
// CONFIGURAR PORTAS
ADCON1 = 0x0F;
CMCON = 0x07;
TRISA = 0x14; // RA7-X, RA6-X, RA5-CTRWAIT, RA4-WR, RA3-INTZ80, RA2-CS2, RA1-LEDR, RA0-LEDY
TRISB = 0xFC; // RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
TRISC = 0x97; // RC7-RX, RC6-TX, RC5-D+, RC4-D-, RC3-X, RC2 A RC0 - D2 A D0
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;

RCON = RCON | 0x80;
PIR1 = 0x00;
PIR2 = 0x00;
PIE1 = 0x00;
PIE2 = 0x00;
IPR1 = 0x00;
IPR2 = 0x00;
INTCON = 0xC0; // 0xC0
INTCON2 = 0xE0; // 0xE0
INTCON3 = 0x90; // 0x90

INTCON3bits.INT2IE = 0x00;
INTCON3bits.INT2IF = 0x00;
PIE1bits.RCIE = 0x00;
PIR1bits.RCIF = 0x00;
PIE2bits.USBIE = 0x00;
PIR2bits.USBIF = 0x00;

OSCCON = 0xFF; // Seta Oscilador Interno para 8 MHz
INTCON3bits.INT2IE = 0x01;



Thanks a lot.
Moacir Jr.
 
Last edited:

Any1 have any idea how i can solve this ?
 

May be your PIC RA0 is damaged. Have you checked your code with proteus. Can you zip and upload the proteus .dsn file or .jpg schematic file.
 

hello


if you want RA2 as input
the correct init of TRISA is 0b00000100 so 0x04 not 0x10
 

Its ok.... my fault....

I just put wrong code..... I just changed... Same with 0x04, the RA2 dint works how input digital.


Ty for reply.
Moacir Jr.
 

did you try a very short program, just to only test RA2 behavior ?
 

Can you zip and upload your schematic?

Add the code
Code:
 CVRCON.CVROE = 0;
or
Code:
 CVRCONbits.CVROE = 0;
and try.
 
Last edited:

Hi internetuser2k12,

I dont have any circuit here, but in home. I will go home later, and send.

But I will try this setting, CVRCON.CVROE = 0;... I see in datasheet, and can be him. I will test and will put result here


thanks a lot
Moacir Jr.
 

Which compiler are you using?

I get the output. RA2 is working.
 

Attachments

  • ss26.jpg
    ss26.jpg
    106.9 KB · Views: 105
Last edited:

Hi all,

I thanks all for helpme, but I solved the problem. I desist to use this pins (RA0, RA1, RA2, RA3 e RA5) how input digital. I put this pins how output digital, that works greate, and put others pins how input digital. My problem was solved. My circuit works greate.



Thanks a lot,
Moacir Jr.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top