Problem in pin RB2/INT2 - 18F2550

Thread Starter

moahrs

Joined Dec 5, 2011
8
Hi Guys,

I have a problema very intersting. I use the 18F2550, and i am trying read from PIN RB2 anything, but this pin dont response. In my last try, i am using RB2 as INT2, active in the faling of signal, but i can put 0v, 5v, 2v, 10v, 50v, -150v, and nothing, the pin dont accept the interruption. And the same with reading, the RB2 dont return anithing. It seems he's always in "1", or in three-state.

I am set all registers of interruptions, in ADCON1, I had put only RA0 and RA1 as analogic (for A/D), all other pin as digital input/output, i disable all interruptions from peripherics, i put INT2 as High Priority, ans other as Low, and nothing.

Below, my code, make in c++.
Rich (BB code):
void main()
{
    unsigned int cc;
        
    // CONFIGURAR PORTAS
    ADCON1 = 0x0D;    // RA0=AN0, RA1=AN1, TODAS AS DEMAIS ANx = DIGITAIS
    PORTA = 0x30;
    PORTB = 0x00;
    PORTC = 0x00;
    TRISA = 0x0B;    // RA7-X, RA6-X, RA5-INTZ80, RA4-CTRWAIT, RA3-PC6, RA2-X+/Y+, RA1-AN1, RA0-AN0
    TRISB = 0xFC;    // RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
    TRISC = 0x97;    // RC7-RX, RC6-TX, RC5-D+, DC4-D-, RC3-X, RC2 A RC0 - D2 A D0, RE3-PC5

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

    pbyte = 0xD5;
    OUT_TFFT = 1;
    cc = 0;

    while(1)
    {
        if (cc <= 0x06FF)
            OUT_TFFT = 1;
        else
            OUT_TFFT = 0;

        cc++;

        if (cc > 0x0EFF)
            cc = 0;
    }
}

void isr_reset(void) __interrupt 0
{
    main();
}

void isr_int2(void) __interrupt 1
{
    unsigned char vINT;

    vINT = INTCON3 & 0x02;

    if (vINT == 0x02)    // FLAG DE INT2 DISPARADA
    {
        // DESLIGA FLAG DE INT2
        INTCON3 = 0x90;

#ifndef debug
        if (IN_PC6 == 0 && IN_PC5 == 1)                // WR DADOS
            pbyte = RecebeByte();
        else if (IN_PC6 == 1 && IN_PC5 == 0)        // RD DADOS
            EnviaByte(pbyte);
        else if (IN_PC6 == 1 && IN_PC5 == 1)        // RD CTRL
            EnviaByte(pbyte);
#endif
    }
}
Some1 have any idea, PLZ.


Ty a lot
Moacir Jr.
 
Last edited by a moderator:

Thread Starter

moahrs

Joined Dec 5, 2011
8
Sry, i am junt kidding. Its is only one thing that any signal type do nothing in this pin. I am put only 0v or 5v. I never put more than 5v. Sry for this.
 

spinnaker

Joined Oct 29, 2009
7,837
First post your schematic. The circuit for analog inputs is very important.


Also don't do interrupts for now. Just poll the analog pin every few seconds.

And I am not seeing anywhere you are setting ANSEL. Have not yet looked at the 18F2550 datasheet but I would think you would have to set it. When I get some time I will try and take a look at the datasheet.
 

thatoneguy

Joined Feb 19, 2009
6,359
PortB.2 is used by

USB Module
Comparator Module
ADC input Channel
Chip Select for Streaming Parallel Port.

Datasheet has this note:
MOVLW 0Eh ; Set RB<4:0> as
MOVWF ADCON1 ; digital I/O pins
; (required if config bit
; PBADEN is set)
Note: On a Power-on Reset, RB4:RB0 are
configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as
digital inputs.
By programming the configuration bit,
PBADEN (CONFIG3H<1>), RB4:RB0 will
alternatively be configured as digital inputs
on POR.
One or more of the above should get you going. Make sure all listed peripherals are turned off, or at least not using RB2, and PBADEN is set for digital inputs. Power on reset has them as analog inputs from note directly above.
 
Top