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.

code not working plz help

Status
Not open for further replies.

Kfir Maymon

Member level 1
Joined
Sep 20, 2013
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
Israel
Activity points
315
hey im tring to resolve sothing plz help

this code is working great:
void init() {
ANSEL =0X00;
ADCON0= 0X00;
CMCON = 0X07;
TRISC=0x03 ;
TRISA=0xff;
PORTC=0x00;
}

int newread=0;
void main()
{
init();
while(1)
{
if(PORTA.F5==1)
{
PORTC.F3=1;
}
if(PORTA.F5==0)
{
PORTC.F3=0;
}
if(PORTA.F4==1)
{
PORTC.F4=1;
}
if(PORTA.F4==0)
{
PORTC.F4=0;
}



}

}

this is not way???
void init() {
ANSEL =0X00;
ADCON0= 0X00;
CMCON = 0X07;
TRISC=0x03 ;
TRISA=0xff;
PORTC=0x00;
}

int newread=0;
void main()
{
init();
while(1)
{
if(PORTA.F5==1 && PORTA.F4==1)
{
PORTC.F3=1;
}
if(PORTA.F5==0 && PORTA.F4==0)
{
PORTC.F3=0;
}
}

}

im useing royary encoder as a switch and osilloscope to monitor the two ch so i know they going high and low
 

what is the error message that you are getting ?
try like this sometimes it could solve the issue. if((PORTA.F5==1) && (PORTA.F4==1))
 
Are you trying to reduce your number out output ports? In the first code youa re using F3 and F4 and the second one you are using one. I am just making sure that was the intention. Another problem is that if the stimulus is fast enough, both if statements could execute in one cycle which makes the port the 2nd state. You should do some type of delay function between reads.
 

Im thing to operate a rotary encoder and something want worng, so i try to debug it, and this is what i got.
I don't get any errors code but on the bord it doesn't working.
Wean i get home i will try this if((PORTA.F5==1) && (PORTA.F4==1))
And give you a feedback tnx
 

In mikroC code you have to do like this...


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
if((PORTA.F5 == 1) && (PORTA.F4 == 1))
{
    PORTC.F3 = 1;
}
 
if((PORTA.F5 == 0) && (PORTA.F4 == 0))
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA.F5) && (PORTA.F4))
{
    PORTC.F3 = 1;
}
 
if((!PORTA.F5) && (!PORTA.F4))
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA & 0x30) == 0x30)
{
    PORTC.F3 = 1;
}
 
if((PORTA & 0x30) == 0x00)
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA & 0x30) == 0x30)
{
    PORTC.F3 = 1;
}
 
if(!(PORTA & 0x30))
{
    PORTC.F3 = 0;
}




If RA4 and RA5 are connected to buttons then you need to debounce like this...


Code C - [expand]
1
2
3
4
5
6
7
if((PORTA.F5 == 1) && (PORTA.F4 == 1))
{
    Delay_ms(50);
    if((PORTA.F5 == 1) && (PORTA.F4 == 1)) {
        PORTC.F3 = 1;
    }
}

 
In mikroC code you have to do like this...


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
if((PORTA.F5 == 1) && (PORTA.F4 == 1))
{
    PORTC.F3 = 1;
}
 
if((PORTA.F5 == 0) && (PORTA.F4 == 0))
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA.F5) && (PORTA.F4))
{
    PORTC.F3 = 1;
}
 
if((!PORTA.F5) && (!PORTA.F4))
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA & 0x30) == 0x30)
{
    PORTC.F3 = 1;
}
 
if((PORTA & 0x30) == 0x00)
{
    PORTC.F3 = 0;
}
 
//or
 
if((PORTA & 0x30) == 0x30)
{
    PORTC.F3 = 1;
}
 
if(!(PORTA & 0x30))
{
    PORTC.F3 = 0;
}




If RA4 and RA5 are connected to buttons then you need to debounce like this...


Code C - [expand]
1
2
3
4
5
6
7
if((PORTA.F5 == 1) && (PORTA.F4 == 1))
{
    Delay_ms(50);
    if((PORTA.F5 == 1) && (PORTA.F4 == 1)) {
        PORTC.F3 = 1;
    }
}



tnx its was very helpfall
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top