EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / hi i need some help in implementing LED and push button

hi i need some help in implementing LED and push button

|

Microcontroller › PIC › hi i need some help in implementing LED and push button

  • This topic has 4 replies, 4 voices, and was last updated 10 years, 10 months ago by Hashwanth.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • August 21, 2014 at 6:50 am #3166
    Hashwanth
    Participant
    hi i’m very new to controller and i’m trying myself with pic16f877A. here is my doubt, when i deal with push button and LED, i have some trouble in switching my LED’s off, i need to on and off the LED by using same button,here is my code.
     
    can anyone please help me solve this issue,,
     
    void lcd_cmd(char a);
    void lcd_disp(char b);
     
    void main()
    {
    char a[]={“LED1 ON led2off”};
    char a1[]={“LED3 OFF”};
    char b[]=”LED1OFF LED2ON”;
    char c[]=”LED1OFF LED2OFF”;
    char d[]=”LED3 ON”;
    int i;
    char x;
     
       setup_adc_ports(NO_ANALOGS);
       setup_adc(ADC_OFF);
       setup_psp(PSP_DISABLED);
       setup_spi(FALSE);
       setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
       setup_timer_1(T1_DISABLED);
       setup_timer_2(T2_DISABLED,0,1);
       setup_comparator(NC_NC_NC_NC);
       setup_vref(FALSE);
     
       // TODO: USER CODE!!
     lcd_cmd(0x01);
     lcd_cmd(0x06);
     lcd_cmd(0x0e);
     lcd_cmd(0x38);
     
    while(1)
    {
    lcd_cmd(0x80);
    switch(1)
    {
     
    case 1:  if(input(pin_c0)==0)
    {
    output_low(pin_d7);
    delay_ms(10);
    lcd_cmd(0x01);
    delay_ms(10);
    for(i=0;a!=’’;i++)
    {
    x=a;
    lcd_disp(x);
    delay_ms(10);
    }
    lcd_cmd(0xc0);
    for(i=0;a1!=’’;i++)
    {
    x=a1;
    lcd_disp(x);
    delay_ms(10);
    }
    while(input(pin_c0)==0);
     
    }
     
     
     
     
    case 2: if(input(pin_c1)==0)
    {
    output_low(pin_d6);
    delay_ms(10);
    lcd_cmd(0x01);
    delay_ms(10);
    for(i=0;b!=’’;i++)
    {
    x=b;
    lcd_disp(x);
    delay_ms(10);
    }
    lcd_cmd(0xc0);
    for(i=0;a1!=’’;i++)
    {
    x=a1;
    lcd_disp(x);
    delay_ms(10);
    }
    while(input(pin_c1)==0);
    }
     
    case 3: if(input(pin_c2)==0)
    {
    output_low(pin_d5);
    delay_ms(10);
    lcd_cmd(0x01);
    delay_ms(10);
    for(i=0;c!=’’;i++)
    {
    x=c;
    lcd_disp(x);
    delay_ms(10);
    }
    lcd_cmd(0xc0);
    for(i=0;d!=’’;i++)
    {
    x=d;
    lcd_disp(x);
    delay_ms(10);
    }
    while(input(pin_c2)==0);
    }
     
     
    }
    }
    }
     
     void lcd_cmd(char a)
    {
    output_low(pin_d1);
    output_low(pin_d0);
    output_b(a);
    output_high(pin_d1);
    delay_ms(10);
    output_low(pin_d1);
    }
     
    void lcd_disp(char b)
    {
    output_low(pin_d1);
    output_high(pin_d0);
    output_b(b);
    output_high(pin_d1);
    delay_ms(10);
    output_low(pin_d1);
    }
    August 21, 2014 at 9:06 am #12048
    SAAD ABDULLAH
    Participant

    As mentioned in your code 

    *

    switch(1)

    {
    *
     
    which variable are u using in switch case? it only mentions a constant  integer.
    August 21, 2014 at 1:24 pm #12051
    AJISH ALFRED
    Participant

    Hi Hashwanth,

     

    I read that “hi i’m very new to controller“

     So i would suggest you not to make the code this much complex. Write a seperate small code for interfacing the switch and led only and test it.

    August 22, 2014 at 9:49 am #12055
    Ashutosh Bhatt
    Participant

    you said you want just a switch and LED

    and in your program I see LCD, ADC

    why do you need these?

    i suggest you start with the tutorials given on this site

    EG labs / micro controller / PIC

    August 22, 2014 at 11:57 am #12060
    Hashwanth
    Participant

    Hi all,

     

      Thanks for your reply, i have completed that coding without using switch case and this looks much complex than the one which i posted earlier. And i have to go with some tutorials first so that i can handle this like situations. 

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Adhesive Defibrillator Pad Cable June 25, 2025
  • Epson crystal oscillators June 25, 2025
  • Simple LED Analog Clock Idea June 24, 2025
  • Fun with AI and swordfish basic June 24, 2025
  • Microinverters and storeage batteries? June 23, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise