element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Pic Microcontrollers Forum Need some help with PIC programing [solved]
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 190 subscribers
  • Views 696 views
  • Users 0 members are here
  • microcontrollers
  • pic16f690
  • pic
Related

Need some help with PIC programing [solved]

Former Member
Former Member over 10 years ago

hi, I am using a PIC16f690. i trying to make a LED on RC0 flash with the help of timers. The problem is that the LED is constantly on. using MPLAB X IDE v2.20 and xc8.

 

#include<PIC16f690.h>

 

#pragma config FOSC = INTRCCLK  // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/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 = OFF      // Power-up Timer Enable bit (PWRT disabled)

#pragma config MCLRE = ON       // MCLR Pin Function Select bit (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 = ON       // Brown-out Reset Selection bits (BOR enabled)

#pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode is enabled)

#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)

 

 

int main(void)

{

    INTCONbits.PEIE = 1;

    INTCONbits.GIE = 1;

 

 

    T1CONbits.T1CKPS0 = 1;

    T1CONbits.T1CKPS1 = 1;

    PIE1bits.TMR1IE = 1;

    T1CONbits.TMR1ON = 1;

 

    TRISC = 0;

    PORTC = 0;

 

 

    while(1);

 

}

 

void interrupt IRS(void)

{

    if(PIR1bits.TMR1IF == 1)

    {

        PORTCbits.RC0 ^= 1;

        PIR1bits.TMR1IF = 0;

    }

  

}

  • Sign in to reply
  • Cancel
  • bbolo1
    bbolo1 over 10 years ago

    Hey Jacob,

     

    I think you forgot to assign the RC0 pin for digital operation. Many of the PIC I/O pins that can work as analog (e.g. ADC or comparator inputs) are assigned for analog operation at power-up.

    Please add the following line before the "while(1)":

    ANSELbits.ANS4 = 0;

     

    Let me know if it works.

     

    Cheers

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • MicrochipRTCfr
    MicrochipRTCfr over 10 years ago in reply to bbolo1

    Hi,

     

    A couple of recommendations :

     

    1/ To make your software portable among all PICs use :

    #include<xc.h>                //  this is valid for any PIC header for all XC compilers ;=)

     

    2/ Interrupts

    To make sure your interrupts will always work in case you use several interrupts simultaneously you should use :

    void interrupt ISR(void)

    if(PIR1bits.TMR1IF && PIE1bits.TMR1IE)

     

    3/ Digital & analog functions

    As mentioned in previous post, analog function are always the default option at reset on PICs. i.e all the ADC analog inputs default to analog mode.

    You must set the ANSEL / ADCON register to declare the pins you want to use in digital mode

     

    Good tutorial about PICs : 8-Bit PICRegistered Microcontrollers - Developer Help

     

    regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Thanks it works now.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • MicrochipRTCfr
    MicrochipRTCfr over 10 years ago in reply to Former Member

    Brilliant,

     

    Good luck with development ;=)

     

    By the way, PIC16F690 is a quite old PIC16 device.

    The new ones can be easily detected as their name has 4 digits after "F" : like PIC16F1xxx. You can easily find them using the parametric selector MAPS : http://www.microchip.com/MAPS

    They are cheaper, they have much more peripherals, and they can run faster from internal oscillator

     

    Regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube