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.

prob with push button interfacting PIC18F4550

Status
Not open for further replies.

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Code:
#include <p18f4550.h> 
 
 #pragma config FOSC = HS  // to select external osc 
// #pragma config PWRT     = ON    // 62 ms waiting at start 
// #pragma config WDT      = OFF        // watch dog timer off 
 #pragma config LVP      = OFF 
 #pragma config PBADEN   = OFF //PORTB<4:0> pins are configured as digital I/O on Reset 
 #pragma config MCLRE    = ON //MCLR pin enabled; RE3 input pin disabled 
//END CONFIG

 void Delay_ms( int ms ) 
 { 
     int i; 
     for ( i = 0; i < ms; i++ ) 
         Delay100TCYx ( 25 ); 
 } 
 
 void main (void)
{
TRISE= 0b11111111;//sets PORTA as all inputs
TRISA= 0b00000000;//sets PORTB as all outputs


PORTA= 0b11111111;//turns off PORTB outputs so that the LED is initially off

while(1)

{
if (PORTEbits.RE0==0); //if switch goes low PORTBbits.RB4=1;//LED turns on

    else
        PORTAbits.RA0=0;//LED turns off
Delay_ms( 100000 );
}

}
simply one LED is blinking... don't understanding.. what is a problem ??
 
Last edited by a moderator:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,720
Helped
4,343
Reputation
8,695
Reaction score
4,304
Trophy points
1,393
Activity points
130,536
Hi,

No function description?
No error description?

How can we help?

Klaus
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
No error!! Its debugging properly in MPLAB X IDE V3.10 but, not working with PICKIT3 :-(
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Hello Mr. Klaus,

Thanks for your reply.
My program is for LED blinking by push button..
Please tell me where the mistake in program ??
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Hie.. Klaus, Thanks for reply.

My program is about,
If we press switch button, my LED should ON rest tie OFF

Can you please tell... where i am wrong in above program
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,720
Helped
4,343
Reputation
8,695
Reaction score
4,304
Trophy points
1,393
Activity points
130,536
Hi,

Delay_ms( 100000 );
Three problems:
1) the variable is decalred as int. I assume this is a 16 bit value with a range of 0...65535. so 100000 is out of range.
2) 100000ms means 100s. This is one minute and 40 seconds.
3) it is no blink funktion

Klaus

- - - Updated - - -

Hi,

you need to describe the function completey.

Just to blink a LED you don´t need a switch:
Code:
while(1)
{
    PORTAbits.RA0=1;//LED turns on
    Delay_ms( 500 );
    PORTAbits.RA0=0;//LED turns off
    Delay_ms( 500 );
}

Klaus
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
Pull up/down on button? You turn led on once only (not toggling it). Analog pins configuration not done. Ra pin not working.
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Thanks KlausST & xenos for reply..!!

i am working with PIC18F4550 Controller
'MPLAB X IDE v3.10 & PICKIT3

i am making program to display LED by Push button switch
where intially LEDs will be OFF state and after pressing switch LED will be ON.

as if now, nothing as comes as output and swich is not affecting to LED
i checked switch & LEDs are working.

please help me out.
 

pic.programmer

Advanced Member level 3
Joined
Aug 19, 2015
Messages
773
Helped
141
Reputation
284
Reaction score
140
Trophy points
43
Activity points
7,542
Button needs debounce delay of 50 ms. ADCON1 register has to be used an PORTA has to be configured as digital IO by turning off ADC function. LATAbits.LATA0 have to be used for LED. #pragma config are not complete.

#pragma derective should include PLLCFG, CPUDIV, USBDIV etc...

C18 Compiler used ? What is crystal frequency ?
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Hie ...

Thanks for reply.
Ya i am using C18(v3.47) and 20MHZ crystal frequency.

i added #pragma PLLCFG, CPUDIV, USBDIV, but as it is...!!
still no output on LED after pressing switch. :-(
 

pic.programmer

Advanced Member level 3
Joined
Aug 19, 2015
Messages
773
Helped
141
Reputation
284
Reaction score
140
Trophy points
43
Activity points
7,542
Zip and post the complete MPLAB X project files. I will fix it.
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
Adcon register value? Have you set it? It is the 3rd message we ask you to do so. Without this ra0 is not responding for leds
 

KYP

Banned
Joined
Sep 2, 2015
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Bangalore
Activity points
0
Hello...


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
#include<p18f4550.h>                                                // Include Header for PIC18f455          
  
       /* ******COMPILER DIRECTIVES FOR CHIP CONFIGURATION BITS ***   */
#pragma config PLLDIV = 5 , CPUDIV = OSC1_PLL2 , USBDIV = 2    // You can write this way
#pragma config FOSC = INTOSCIO_EC
#pragma config FCMEN = OFF                                 // OR this way
#pragma config BORV = 3
#pragma config WDT = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
 
void main (void)
{
ADCON1= 0x7F;//this makes all I/O pins digital
TRISE= 0b11111111;//sets PORTE as all inputs
TRISA= 0b00000000;//sets PORTA as all outputs
PORTA= 0b00000000;//turns off PORTA outputs so that the LED is initially off
PORTE= 0b11111111;//turns off PORTA outputs so that the LED is initially off
 
while(1)
{
if (PORTEbits.RE1==1) //if switch goes low 
    PORTAbits.RA5=0;//LED turns on
else
PORTAbits.RA5=1;//LED turns off
}
}



Still.... no effect from LED.
I added ADCON also still no output as per required :-(
 

Attachments

  • 1809.X.rar
    17 KB · Views: 3
Last edited by a moderator:

pic.programmer

Advanced Member level 3
Joined
Aug 19, 2015
Messages
773
Helped
141
Reputation
284
Reaction score
140
Trophy points
43
Activity points
7,542
It works. Try attached project. You should use 20 MHz crystal on OSC1 and OSC2 pins with associated 27pf capacitors.
 

Attachments

  • LED and Switch.rar
    34.4 KB · Views: 3

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top