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] LEDs did not turn on when push button is pressed

Status
Not open for further replies.

Lapsapbee

Newbie level 2
Newbie level 2
Joined
Sep 29, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
19
Hi all,

I am new in learning MikcoC. Currently, I wrote a simple coding to turn on the 4 green LEDs for 100ms when the button is being pressed.
I used the microcontroller PIC18F452 and I have configured PORT B as input and PORT D as output.
However, the circuit in my proteus did not function as expected although my coding was built successfully.
I tried it many times already and learnt the tutorial in youtube but the LEDs still cannot light on although I pressed and pressed again.

Here is the coding:

void main()
{
TRISB = 0xFF;
TRISD = 0x00;
ADCON0 = 0x09;
ADCON1 = 0x0E;
PORTD = 0X00;
do {
if (PORTB.F0 == 0) {
{
PORTD = 0xFF;
Delay_ms(100);
PORTD = 0x00;
}
}
}while(1);
}



Please help me to check through whether I have missed out anything. Thank you! :smile:
 

Assuming you have the configuration bits set correctly and the clock and reset working, do you have a pull-up/ pull-down resistor on whatever pin PORTB.F0 is defined as (your input pin) It will only change state if pressing the button moves it from one logic level to the other, you have to set the logic level before the button changes it.

Brian.
 

hi lapsapbee, welcome to forum...BTW you want to control 4 LED of port D with button connected to port B..

Code:
void main()
{
TRISB = 0xFF;
TRISD = 0x00;
ADCON0 = 0x09;
ADCON1 = 0x0E;
PORTD = 0X00

while(1)
{

if (PORTB.F0 == 0) /// check this statement PORTB.F0 is it write ???
 {
PORTD = 0xFF;      // PORT D High you are turning all pins of port D high
Delay_ms(100);     // delay 
PORTD = 0x00;     // PORTD is low
Delay_ms(100);     // delay

   }

}

}
 
Hi Brian,

The clock frequency, I set it to 20Mhz.. I don't know whether the resistor that I picked correct or not.. I use the RES so I can change the value of resistance.
There is the component that I used.

one.png

- - - Updated - - -

Hi peeyushsigma,

Thank you! :) Btw, I changed the coding as below (PORTA bit 3 as input):


void main()
{
TRISA = 0xFF;
TRISD = 0x00;
ADCON0 = 0x09;
ADCON1 = 0x0E;
PORTD = 0X00;
do {
if (Button(&PORTA,3,1,0)) {
{
PORTD = 0xFF;
Delay_ms(100);
PORTD = 0x00;
Delay_ms(100);
}
}
}while(1);
}

one.pngTWO.png
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top