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.

[PIC] 18F452 ADCON1 PORTAbits.RA0 & PORTAbits.RA1 as input Digital

Status
Not open for further replies.

ppperez

Newbie level 5
Joined
Jul 31, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
84
Hello MASTERS.

Someone can tell me what I am doing wrong....

I am trying to understand the PIC18F452, I did a couple of programs, I am trying to understand the Digital input signal.

I connected a couple of push bottoms on RA0 & RA1 to simulate a digital signal, the output will be the PORTB, I am doing a counter. With RA0 add 1 and RA1 menus 1.

According to the Datasheet in order to get all inputs on PORTA as Digital PCFG3:pCFG0 011X and ADCON0 I understood it's not necessary.

This is my easy code and I don't have any output, I don't know if I need to read more or my PIC is damaged.

Code:
char salida = 0;
void main(int argc, char** argv) {
    TRISB = 0;    //Puerto B output
    TRISA = 1;    //Puerto A input
    ADCON1 = 0x10000111;
    //       0x1-------    Justificacion a la derecha
    //       0x-0------    Fosc/2
    //       0x--00----    No implemented
    //       0x----0110    AN0 -> AN7 = Digitals

    
    while(1)
    {
        if (PORTAbits.RA0 == 1)
        {
            salida = salida + 1;
            while(PORTAbits.RA0 == 1)
            {}
        }
        if (PORTAbits.RA1 == 1)
        {
            salida = salida - 1;
            while(PORTAbits.RA1 == 1)
            {}
        }
        PORTB = salida;
        }
  
            }


I hope that someone can give me some ideas.

Thanks in advance.
 

hi p,
The bit pattern appears to be set for Analog inputs for ADCON1 xxxx0111
E
 

Attachments

  • A004.gif
    A004.gif
    47.2 KB · Views: 123

Hello esp1.

Thank you for your prompt answer. I found my error, the problem was my definition of ADCON1, x means hexadecimal and d decimal, in this case I have to use decimal so

wrong definition:
ADCON1 = 0x10000111;

Correct definition of ADCON1
ADCON1 = 0b10000111;

I am very happy, I am understanding more about microcontrollers.

Thanks again...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top