Blink I/O PIC16F887

(instructions, reset, WDT, specifications...) PIC12F6xx, PIC16Fxxx, PIC16F6x, PIC16F7x

Re: Blink I/O PIC16F887

Postby ric » Fri Sep 04, 2020 4:22 am

Ahh, they didn't use the name in the datasheet
Try "INTRC_NOCLKOUT"

I tried to use a define statement for OSSCON outside of main, but that also doesn't work

You can't use a define to write to a normal register. As I stated, your code must be running before you can write anything to OSCCON. It starts with the "power on default" values mentioned in the datasheet.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Blink I/O PIC16F887

Postby SSAnne_ » Fri Sep 04, 2020 4:37 am

You're both right INTOSCIO, and INTOSC, both work for me to be able to set up OSSCON, although I don't fully understand why because those both sound like external oscillator options when I'm looking at the data sheet. My only problem is "__delay_ms()" does nothing, but I can still delay it with forloops.

Thank you both for your help :)

Code: Select all
/*
 * File:   newmain2.c
 * Author: Eric
 *
 * Created on September 2, 2020, 6:46 PM
 */

// PIC16F887 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FOSC = INTRC_NOCLKOUT// 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 = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
#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)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#define OSSCON (0x75)
#define _XTAL_FREQ (8000000UL)
void main(void) {
    //OSCCON = 0x75;
    TRISD = 0x00;
    int i;
    int j;
    //PORTA = 0xFF;
    //RA7 = 1;
    //*0x05=0xFF
    while(1){
      ///PORTB = 0xFF; 
        PORTD = 0xFF;
        for(j = 0; j<10; j++){
        for(i = 0; i<4000 ; i++);}
        //__delay_ms(1000);
        PORTD = 0x00;
        for(j = 0; j<10; j++){
        for(i = 0; i<4000 ; i++);}
    }
    return;
}
SSAnne_
 
Posts: 6
Joined: Thu Sep 03, 2020 3:24 pm
PIC experience: EE Student

Re: Blink I/O PIC16F887

Postby vloki » Fri Sep 04, 2020 8:33 am

INTernalOSCillator... sounds like external oscillator?

Remove this #define OSCCON nonsense.
OSCCON is a register in the RAM.
It is modified during program execution. (in your main function)

OSCCON has nothing to do with the FOSC settings in the config register Susan told you to have a look at!
Except that frequency selection in OSCCON only makes sense if INTOSC is selected in FOSC ;)

May be you think the __delay() function is not working,
because in the beginning you had only one delay?
The time PORTD was high is only some microseconds and you cant see any blinking!

If you have only one delay then you need to toggle the PORT after each time the delay elapsed.

Code: Select all
...
#define _XTAL_FREQ (4000000UL)

void main(void)
{
    TRISD = 0x00;
   
    while(1){
        __delay_ms(100);
        PORTD ^= 0xFF;         // <<-- toggle the port (^=)
    }
}
´
You possibly want to have a look at how to run a program in debug mode.
It may help you to understand whats going on.
SIMULATOR -> https://microchipdeveloper.com/tls0101:lab2
PICKIT4 -> https://microchipdeveloper.com/tls0101:lab3
You can use your own code. No need to get the example shown in the lessons!
vloki
Verified identity
 
Posts: 186
Joined: Wed May 28, 2014 8:42 am
Location: Germany
PIC experience: Professional 5+ years with MCHP products

Re: Blink I/O PIC16F887

Postby jtemples » Fri Sep 04, 2020 9:38 pm

MPLAB isn't consistent with the data sheet here; use INTRC_NOCLKOUT
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: Blink I/O PIC16F887

Postby AussieSusan » Mon Sep 07, 2020 3:29 am

I was going by the names in the data sheet which are usually the same as those used by the compiler.
In this case you should chose either "INTRC_CLKOUT' or 'INTRC_NOCLKOUT' depending on whether you want to use the pins for IO or not.
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Previous

Return to 14-Bit Core

Who is online

Users browsing this forum: No registered users and 10 guests

cron