Author Topic: [SOLVED] PIC on breadboard: why won't it blink?  (Read 2140 times)

0 Members and 1 Guest are viewing this topic.

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
[SOLVED] PIC on breadboard: why won't it blink?
« on: May 04, 2015, 04:06:37 pm »
The PICKit arrived and I started experimenting with a few PIC16F72 on a breadboard, starting with a LED blinker.

Here is the code:

config.h
Code: [Select]
#ifndef CONFIG_H
#define CONFIG_H

#define _XTAL_FREQ 16000000     // 16MHz crystal oscillator used

#include <pic.h>
#include <xc.h>

#ifdef MAIN_FILE

// Configuration bits
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = OFF         // FLASH Program Memory Code Protection bit (Code protection off)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)

#endif

#endif /* CONFIG_H */

main.c
Code: [Select]
#define MAIN_FILE
#include "config.h"

void main(void)
{
    // Make the LED light up.
    TRISA &= ~0x1;
   
    while (1)
    {
        PORTA |= 0x1;
        __delay_ms(500);
        PORTA &= ~0x1;
        __delay_ms(500);
    }
}

I have a 16MHz crystal across pins 9 and 10, power at appropriate pins with a 220nF bypass, and a LED with MOSFET low side switch at pin 2.

The blinking is erratic and I am confused at what is going on. 16F72 does not support debugging with PICKit (D'oh!) so pointers please?

EDIT: Solved. Two culprits: the pin I used was an analog pin which have to be configured into a digital output first, and I left the RESET pin flapping in the wind.
« Last Edit: May 04, 2015, 06:03:20 pm by technix »
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: PIC on breadboard: why won't it blink?
« Reply #1 on: May 04, 2015, 04:22:44 pm »
Mmmm  Check the data sheet page 21 ....  ADCON1   ?

Edit you dont mention any Xtal 22pf caps
« Last Edit: May 04, 2015, 04:29:28 pm by 22swg »
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline Rolo

  • Regular Contributor
  • *
  • Posts: 206
  • Country: nl
Re: PIC on breadboard: why won't it blink?
« Reply #2 on: May 04, 2015, 04:27:27 pm »
Yes, ADCON, pic's pins often default to analog inputs. And after setting that you should make the port an output.
Also when beginning with MCU's disable Brown Out, unless you realy use it.
Hope this helps !
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: PIC on breadboard: why won't it blink?
« Reply #3 on: May 04, 2015, 04:51:01 pm »
Mmmm  Check the data sheet page 21 ....  ADCON1   ?

Edit you dont mention any Xtal 22pf caps

This one worked better, but still erratic:

Code: [Select]
void main(void)
{
    // pinMode(PA0, OUTPUT)
    ADCON1 = 0x6;
    TRISA &= ~0x1;
   
    while (1)
    {
        PORTA |= 0x1;
        __delay_ms(500);
        PORTA &= ~0x1;
        __delay_ms(500);
    }
}
 

Offline os40la

  • Regular Contributor
  • *
  • Posts: 122
  • Country: us
Re: PIC on breadboard: why won't it blink?
« Reply #4 on: May 04, 2015, 04:56:29 pm »
Mmmm  Check the data sheet page 21 ....  ADCON1   ?

Edit you dont mention any Xtal 22pf caps

This one worked better, but still erratic:

Code: [Select]
void main(void)
{
    // pinMode(PA0, OUTPUT)
    ADCON1 = 0x6;
    TRISA &= ~0x1;
   
    while (1)
    {
        PORTA |= 0x1;
        __delay_ms(500);
        PORTA &= ~0x1;
        __delay_ms(500);
    }
}

Do you have a pull-up resistor on the reset pin?
"No, but I did stay at a Holiday Inn Express"
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: PIC on breadboard: why won't it blink?
« Reply #5 on: May 04, 2015, 05:38:56 pm »
Mmmm  Check the data sheet page 21 ....  ADCON1   ?

Edit you dont mention any Xtal 22pf caps

This one worked better, but still erratic:

Code: [Select]
void main(void)
{
    // pinMode(PA0, OUTPUT)
    ADCON1 = 0x6;
    TRISA &= ~0x1;
   
    while (1)
    {
        PORTA |= 0x1;
        __delay_ms(500);
        PORTA &= ~0x1;
        __delay_ms(500);
    }
}

Do you have a pull-up resistor on the reset pin?

Do I need an 1N5819 to protect it against Vpp overloading the power rail?
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: PIC on breadboard: why won't it blink?
« Reply #6 on: May 04, 2015, 06:01:54 pm »
Mmmm  Check the data sheet page 21 ....  ADCON1   ?

Edit you dont mention any Xtal 22pf caps

This one worked better, but still erratic:

Code: [Select]
void main(void)
{
    // pinMode(PA0, OUTPUT)
    ADCON1 = 0x6;
    TRISA &= ~0x1;
   
    while (1)
    {
        PORTA |= 0x1;
        __delay_ms(500);
        PORTA &= ~0x1;
        __delay_ms(500);
    }
}

Do you have a pull-up resistor on the reset pin?

Added a 6.8k pullup and a 1N5819 protection diode, works like a charm now. Thanks.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf