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
Visit site
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:

Hi,

No function description?
No error description?

How can we help?

Klaus
 

No error!! Its debugging properly in MPLAB X IDE V3.10 but, not working with PICKIT3 :-(
 

Hello Mr. Klaus,

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

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
 

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
 

Pull up/down on button? You turn led on once only (not toggling it). Analog pins configuration not done. Ra pin not working.
 

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.
 

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 ?
 

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. :-(
 

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
 

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: 86
Last edited by a moderator:

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: 97

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…