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.

PortE problem?? PIC18F458

Status
Not open for further replies.

ABOELLEEL

Junior Member level 3
Junior Member level 3
Joined
Apr 6, 2011
Messages
31
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Egypt
Activity points
1,483
Hi all,
My project is very simple that is keypad UP,DN & OK, LED
When i press ok LED is ON and OFF if i pressed UP or DN
UP----> porte.f1
DN----> porte.f0
OK----> portc.f3
LED---> porte.f2
and this is the code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void main()
 {
 TRISE = 0X03;
 PORTE.F2 = 0;
 TRISC.F3 = 1;
 
  while(1)
  {
   if(PORTE.F1 == 1) PORTE.F2 = 0;   //UP
   
   if(PORTE.F0 == 1) PORTE.F2 = 0;     //dn
   
   if(PORTC.F3 == 1) PORTE.F2 = 1;      //ok
 
   }
   }



The problem that i can turn LED on and cant off it
I am using mikroC V8.2.0.0
:?::?::?::?::?::?::?::?::?:
 
Last edited by a moderator:

Try this code

Code:
void main()
{
TRISE = 0X03;
PORTE.F2 = 0;
TRISC = 0x08;

while(1)
{
if(PORTE.F1 == 1)
	Delay_ms(150);
		if(PORTE.F1 == 1)
 			PORTE.F2 = 0; //UP

if(PORTE.F0 == 1)
	Delay_ms(150);
		if(PORTE.F0 == 1)
		 	PORTE.F2 = 0; //dn

if(PORTC.F3 == 1)
	Delay_ms(150);
		if(PORTC.F3 == 1) 
			PORTE.F2 = 1; //ok

}
}

You need to give debounce for buttons.

When OK is pressed led will turn ON. pressing up or down will turn off the led.
 

I tried with 5 ms and 500 ms delay but the same problem
 

Thank you for replay
still not working :(

- - - Updated - - -

Try this code

Code:
void main()
{
TRISE = 0X03;
PORTE.F2 = 0;
TRISC = 0x08;

while(1)
{
if(PORTE.F1 == 1)
	Delay_ms(150);
		if(PORTE.F1 == 1)
 			PORTE.F2 = 0; //UP

if(PORTE.F0 == 1)
	Delay_ms(150);
		if(PORTE.F0 == 1)
		 	PORTE.F2 = 0; //dn

if(PORTC.F3 == 1)
	Delay_ms(150);
		if(PORTC.F3 == 1) 
			PORTE.F2 = 1; //ok

}
}

You need to give debounce for buttons.

When OK is pressed led will turn ON. pressing up or down will turn off the led.
i tried but still not working

- - - Updated - - -

did you press another button & post it.
?????????????

- - - Updated - - -

I am confused because it very simple and i created many programs using this function
 

please press up/down button & check it.

- - - Updated - - -

have you try it.
 

try this code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void main()
{
TRISE = 0X03;
PORTE.F2 = 0;
TRISC.F3 = 1;
 
while(1)
{
if(PORTE.F1 == 1) PORTE.F2 = 0; //UP
 
if(PORTE.F0 == 1) PORTE.F2 = 0; //dn
 
if(PORTC.F3 == 1) PORTE.F2 = 1; //ok
delay ms(100);
}
}

 
Last edited by a moderator:

try this code.

void main()
{
TRISE = 0X03;
PORTE.F2 = 0;
TRISC.F3 = 1;

while(1)
{
if(PORTE.F1 == 1) PORTE.F2 = 0; //UP

if(PORTE.F0 == 1) PORTE.F2 = 0; //dn

if(PORTC.F3 == 1) PORTE.F2 = 1; //ok
delay ms(100);
}
}
There is (_) missing in(delay ms(100); and i completed it but still not working??
 

sorry its delay_ms(100);

- - - Updated - - -

its on on when its power up itself.
 

Hi all,
My project is very simple that is keypad UP,DN & OK, LED
When i press ok LED is ON and OFF if i pressed UP or DN
UP----> porte.f1
DN----> porte.f0
OK----> portc.f3
LED---> porte.f2
and this is the code
void main()
{
TRISE = 0X03;
PORTE.F2 = 0;
TRISC.F3 = 1;

while(1)
{
if(PORTE.F1 == 1) PORTE.F2 = 0; //UP

if(PORTE.F0 == 1) PORTE.F2 = 0; //dn

if(PORTC.F3 == 1) PORTE.F2 = 1; //ok

}
}
The problem that i can turn LED on and cant off it
I am using mikroC V8.2.0.0
:?::?::?::?::?::?::?::?::?:

You are right... this should be simple. And when even a simple thing doesn't work it can be very frustating. I'm sure we can fix it ....

But first, can you tell me what is the purpose of the following lines --

TRISE = 0x03

and
TRISC.F3 = 1

Second -- How have you connected your switchs ? Are they switch-to-GND with pullup-to-Vcc ? Or something different ? If its switch-to-GND then when the switch is ON, your input level will be 0 and not 1. So you will have to check for PORTE.Fx == 0 etc

I believe focusing on these 2 questions will give you the answer to fix it.

cheers!
 

in port E 1st & 2nd bit are set as input & others are o/p.

switch is connected to pull down to gnd. the other terminal of the switch is connected to vcc.
 
in port E 1st & 2nd bit are set as input & others are o/p.

switch is connected to pull down to gnd. the other terminal of the switch is connected to vcc.

Hmmmm.... so then the error seems obvious ? Or am I missing something ?

1) You need to do TRISE = 0x0B ; otherwise how will bit f3 ever be input ?!?

and
2) Still not sure exactly HOW the switch is connected. But I think you mean - switch has a pull-down resistor to GND. In which case make sure it is not a very large value
 

TRISE = 0x03
That make pin 0 & 1 are I/P for DN & UP switches and pin 2 O/P for the LED
and
TRISC.F3 = 1
To make pin 3 I/P for OK switch
Second -- How have you connected your switchs ? Are they switch-to-GND with pullup-to-Vcc ? Or something different ? If its switch-to-GND then when the switch is ON, your input level will be 0 and not 1. So you will have to check for PORTE.Fx == 0 etc
Micro pin is pulled down with resistor and switch get 5V to the pin
I believe focusing on these 2 questions will give you the answer to fix it.

cheers!
thank you for your interest :)
 

That make pin 0 & 1 are I/P for DN & UP switches and pin 2 O/P for the LED
and

To make pin 3 I/P for OK switch

Ok.... i see. But why is the method different for making 0 &1 as input and different for making 3 input ?
I'm a PIC and microCv8 virgin, so pardon my ignorance. Oh i see now... f3 is on C and not E

Finally read a bit of the PIC user manual, and noticed that PORTC.F3 is ALSO the SCK/SCL bit.
Maybe you should try disconnecting your programmer before you try the buttons/ etc. Sometimes the programmer might be holding the pin low.
 
Last edited:

I cant run micro before disconnecting the programmer (it may be lower MCLR pin)
This part are from already running program ???!!! :cry:
I will try tomorrow get it in interrupt subroutine then use flags
 

I cant run micro before disconnecting the programmer (it may be lower MCLR pin)
This part are from already running program ???!!! :cry:
I will try tomorrow get it in interrupt subroutine then use flags

What ???? You have a very strange circuit dude. So you feel a more complicated method might work better ? Good thought... :)
Sorry, can't help anymore... did the best i could. Hope it works out.

cheers!
:)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top