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] how to use PIC18F24K50 RC2 pins as a input (button)

Status
Not open for further replies.

cllunlu

Member level 4
Joined
Nov 21, 2006
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,900
Hi Everyone,

I use pic18f24k50 microcontroller and wanna use RC1 and RC2 pin as input with button. When button1 that is connected RC1 is pressed, led1 that is connected RA1 will be on. And when button2 that is connected RC2 is pressed, led1 that is connected RA2 will be on.

I write code is below. when button1 is pressed, led is on. but when I press button2, dont change any situation led2. it always on.

I check many times hardware and connections and dont any mistake. The first RC2 pin is 5V when I pressed button RC2 is 0V. but pic18f24k50 doesnt detect it.

I think, fuse and settings may be wrong.


void main()
{
TRISA=0x00;
TRISB=0x00;
TRISC=0XFF;
ADCON1 =0x07;
for(;;)
{
if(PORTC.B1==0)
{
PORTA.B0=1;
PORTB.B3=1;
}
else
{
PORTA.B0=0;
PORTB.B3=0;
}
if(PORTC.B2==0)
{
PORTA.B1=1;
PORTB.B3=1;
}
else
{
PORTA.B1=0;
PORTB.B3=0;
}

}
}

my circuit

https://obrazki.elektroda.pl/5347806500_1431118149.png

Anyone can help me about Project settings in mikroC.

Thanks
 

You have to debounce the buttons and also disable Comparators on pins used for LEDs.

Attached mikroC PRO PIC project. Code compiled for 4 MHz XT OSC.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
sbit SW1 at RC1_bit;
sbit SW2 at RC2_bit;
 
sbit SW1_Direction at TRISC1_bit;
sbit SW2_Direction at TRISC2_bit;
 
sbit LED1 at LATA1_bit;
sbit LED2 at LATA2_bit;
 
sbit LED1_Direction at TRISA1_bit;
sbit LED2_Direction at TRISA2_bit;
 
 
#define INPUT 1
#define OUTPUT 0
 
#define LOW 0
#define HIGH 1
 
void main() {
 
     CM1CON0 = 0x00;
     CM2CON0 = 0x00;
     
     ANSELA = 0x00;
     ANSELB = 0x00;
     ANSELC = 0x00;
     
     TRISA = 0xC0;
     TRISB = 0x00;
     TRISC = 0x00;
     
     PORTA = 0x00;
     PORTB = 0x00;
     PORTC = 0x00;
     
     LATA = 0x00;
     LATB = 0x00;
     LATC = 0x00;
     
     SW1_Direction = INPUT;
     SW2_Direction = INPUT;
     
     LED1_Direction = OUTPUT;
     LED2_Direction = OUTPUT;
     
     LED1 = LOW;
     LED2 = LOW;
 
     while(1) {
     
            if(!SW1) {
                Delay_ms(50);
                if(!SW1)
                    LED1 = HIGH;           
            }
            
            if(!SW2) {
                Delay_ms(50);
                if(!SW2)
                    LED2 = HIGH;           
            }
     
     }
}

 

Attachments

  • Buttons and LEDs.rar
    35.6 KB · Views: 57
Last edited:
Can you hwlp mw how to make that?
Thanks

- - - Updated - - -

Thank you so much milan.rajik. Have you any document about mikroC forpic applications.
 

mikroC PRO PIC has help file and a manual.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top