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] Problem with pic i/0 port

Status
Not open for further replies.

naveen.kumar

Newbie level 4
Joined
Jul 3, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
37
hello guys,

i am using pic18f4520 and iam making RA4 , RA5 ,RE0 and RE1 as input and i have connected pull up resistor as well but except RA4 all others are going inside the loop even though it is not grounded.

this is my program.....please help me out...

Code:
#include<p18f4520.h>

//#include"sutures_gloves_testing.h"
#pragma config OSC = HS 		//INTOSC_EC
#pragma config PWRT = OFF
#pragma config  BOREN  = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config WDT = OFF		//,DEBUG=OFF


#define LED1  (LATBbits.LATB3)
#define LED2  (LATBbits.LATB2)
#define LED3  (LATCbits.LATC5)
#define LED4  (LATCbits.LATC4)
#define SWITCH_1 (PORTAbits.RA4)
#define SWITCH_2 (PORTAbits.RA5)
#define SWITCH_3 (PORTEbits.RE0)
#define SWITCH_4 (PORTEbits.RE1)

#define Actuator_1 (LATAbits.LATA0) 
#define Actuator_2 (LATAbits.LATA1)
#define Actuator_3 (LATAbits.LATA2)
#define Actuator_4 (LATAbits.LATA3)
#define Solenoid_1 (LATCbits.LATC2)

void All_init(void);

void main()
{
	All_init();
	Actuator_1 = 1;
	Actuator_2 = 1;
	Actuator_3 = 1;
	Actuator_4 = 1;
	while(1)
	{
	        if(SWITCH_1 == 0)
		{
		Actuator_1 = 0;
		}
		if(SWITCH_2 == 0)
		{
		Actuator_2 = 0;
		}
		if(SWITCH_3 == 0)
		{
		Actuator_3 = 0;
		}
		if(SWITCH_4 == 0)
		{
		Actuator_4 = 0;
		}
	//Actuator_2 = 0;
	}
}



void All_init()
{
	TRISBbits.RB3 = 0;
	TRISBbits.RB2 = 0;
	TRISCbits.RC5 = 0;
	TRISCbits.RC4 = 0;
	TRISCbits.RC2 = 0;
    TRISAbits.RA0 = 0;
	TRISAbits.RA1 = 0;
	TRISAbits.RA2 = 0;
	TRISAbits.RA3 = 0;
	TRISAbits.RA4 = 1;
	TRISAbits.TRISA5 = 1;
	TRISEbits.RE0 = 1;
	TRISEbits.RE1 = 1;
}
 
Last edited by a moderator:

You have to use debounce delays for each switch.


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<p18f4520.h>
#include <delays.h>
 
#pragma config OSC    = HS      
#pragma config PWRT   = ON
#pragma config BOREN  = ON
#pragma config MCLRE  = ON
#pragma config PBADEN = OFF
#pragma config LVP    = OFF
#pragma config WDT    = OFF
#pragma config DEBUG  = OFF     
 
 
#define LED1  LATBbits.LATB3
#define LED2  LATBbits.LATB2
#define LED3  LATCbits.LATC5
#define LED4  LATCbits.LATC4
#define SWITCH_1 PORTAbits.RA4
#define SWITCH_2 PORTAbits.RA5
#define SWITCH_3 PORTEbits.RE0
#define SWITCH_4 PORTEbits.RE1
#define Actuator_1 LATAbits.LATA0
#define Actuator_2 LATAbits.LATA1
#define Actuator_3 LATAbits.LATA2
#define Actuator_4 LATAbits.LATA3
#define Solenoid_1 LATCbits.LATC2
 
void All_init(void);
 
 
void All_init()
{
    TRISBbits.TRISB3 = 0;
    TRISBbits.TRISB2 = 0;
    TRISCbits.TRISC5 = 0;
    TRISCbits.TRISC4 = 0;
    TRISCbits.TRISC2 = 0;
 TRISAbits.TRISA0 = 0;
    TRISAbits.TRISA1 = 0;
    TRISAbits.TRISA2 = 0;
    TRISAbits.TRISA3 = 0;
    TRISAbits.TRISA4 = 1;
    TRISAbits.TRISA5 = 1;
    TRISEbits.TRISE0 = 1;
    TRISEbits.TRISE1 = 1;
    ADCON1 = 0x0F;
    CMCON = 0x07;
    CVRCON = 0x00;
 
}
 
void main()
{
 
    All_init();
 
    Actuator_1 = 1;
    Actuator_2 = 1;
    Actuator_3 = 1;
    Actuator_4 = 1;
 
    while(1)
    {
            if(SWITCH_1 == 0)
        {
            Delay1KTCYx(0);
            if(SWITCH_1 == 0)
            {
                Actuator_1 = 0;
 
            }
        }
 
        if(SWITCH_2 == 0)
        {
            Delay1KTCYx(0);
            if(SWITCH_2 == 0)
            {
                Actuator_2 = 0;
 
            }
        }
 
        if(SWITCH_3 == 0)
        {
            Delay1KTCYx(0);
            if(SWITCH_3 == 0)
            {
                Actuator_3 = 0;
 
            }
        }
        
        if(SWITCH_4 == 0)
        {
            Delay1KTCYx(0);
            if(SWITCH_4 == 0)
            {
                Actuator_4 = 0;
 
            }
        }
    
    }
}

 
Last edited:

    V

    Points: 2
    Helpful Answer Positive Rating
so SWITCH_1 is not working your code right ? and why are u using this stuff like
Code:
TRISAbits.RA4 = 1;
	TRISAbits.TRISA5 = 1;
 

thank u for your reply,
ya i ll use it but now i am using debugger to check but still it is entering the loop even though pin is getting 5v.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top