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 / How to read switch in XC8 compiler

How to read switch in XC8 compiler

|

Microcontroller › PIC › How to read switch in XC8 compiler

  • This topic has 1 reply, 2 voices, and was last updated 11 years, 7 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 30, 2014 at 5:50 am #2997
    yaseen. d. makandar
    Participant

    Hello .. I’m using pic16f684 microcontroller, pickit3 and XC8 compiler, I written program to flash led for 10 seconds after switch button press but when i burn program on pic it start flashing led continuesly before i pressed button, i used all control instructions such as if, while, switch… even i tryed using pointer which is used in mikroC pro compiler which is also not working, Please can you tell me how to read switch. below is the progam which i burned on pic16f684.

     

    #include<xc.h>            // XC general include file
    #include<pic16f684.h>

    #pragma config FOSC = INTOSCIO   // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/

                                                                     CLKOUT  pin, I/O function on RA7/OSC1/CLKIN)
    #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of

                                                                  the WDTCON register)
    #pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
    #pragma config MCLRE = ON       // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
    #pragma config CP = OFF               // Code Protection bit (Program memory code protection is disabled)
    #pragma config CPD = OFF            // Data Code Protection bit (Data memory code protection is disabled)
    #pragma config BOREN = OFF      // Brown Out Reset Selection bits (BOR disabled)
    #pragma config IESO = OFF           // Internal External Switchover bit (Internal/External Switchover mode is disabled)
    #pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
     
    //#define Switch PORTCbits.RC0

    #define    _XTAL_FREQ 4000000   // Set xtal frequency for time delay

    unsigned int i;

    void main()
    {

        CMCON0 = 0x07;             // turn off comparator      
         ANSEL = 0b00000000;    //All I/O pins are configured as digital
         TRISC = 0b00000111;       // PORTC All Outputs
         TRISA = 0b00001000; // PORTA All Outputs, Except RA3,
        
         while(1)
         {

              if(switch==1)

                     {

                          for(i=0;i<=10;i++)

                          

                              {

                                   
                                 PORTA = 1;

                                 __delay_ms(1000);

                                 PORTA = 0;

                                 __delay_ms(1000);

                                

                             }

                      }

             PORTA =0;

          }
    }

    March 31, 2014 at 4:46 am #11426
    Ashutosh Bhatt
    Participant

    u r reading “switch” but what is switch?

    u hv commented it out in your program. see ur code.

    another thing

    u r not polling pin status in continuous loop the actual loop should be

    loop:while(switch==0);

    for(i=0;i<=10;i++)

                          

                              {

                                   
                                 PORTA = 1;

                                 __delay_ms(1000);

                                 PORTA = 0;

                                 __delay_ms(1000);

                                

                             }

    switch=0;

    goto loop;

          

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

RSS Recent Posts

  • Calculation of A Class amplifier November 9, 2025
  • restarting this Christmas project November 9, 2025
  • strange laptop problem November 9, 2025
  • Have a ultrasonic washer but not knowing what detergent for cleaning soot November 9, 2025
  • JLCPBC are using a different shipping company = less $$$$$$$$ November 9, 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