I am new, and need help

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

I am new, and need help

Postby elZero » Sat Aug 04, 2018 2:10 pm

I am new to microcontrollers and programming for embedded systems. Just got a gift of a PICKit3 and decided to test it out. The ode compiles, but the microcontroller doesn't do what I expected it to do(count from 1-31, in binary and output it to connected LEDs. There is an external 6MHz Crystal Oscillator, and the MCLR pin is pulled high through a 10K resistor.

Here's the code:
Code: Select all
 
#include <xc.h>
 
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config BOREN = OFF
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config CP = OFF
 
#define _XTAL_FREQ 6000000
 
void main(void)
{
    TRISA = 0xE0;

    unsigned char i;

    i = 0;
    for(i = 0; i <= 31; i++)
    {
        PORTA = i;
        __delay_ms(100);
        if(i=31)i=0;
    }
}
Last edited by ric on Sun Aug 05, 2018 9:59 am, edited 1 time in total.
Reason: Added "code" tags around the code.
elZero
 
Posts: 3
Joined: Sat Aug 04, 2018 5:00 am

Re: I am new, and need help

Postby Jorgef » Sun Aug 05, 2018 5:03 am

Hi

I just saw that you are already receving replies in the MCHP forum.
if I can add something, just ask.
Best regards
Jorge
Jorgef
Verified identity
 
Posts: 19
Joined: Wed May 30, 2018 8:46 pm
PIC experience: Professional 5+ years with MCHP products

Re: I am new, and need help

Postby ric » Sun Aug 05, 2018 10:23 am

Appears to be cross posted from: https://www.microchip.com/forums/m1063072.aspx
Over there it has been revealed that the PIC is a PIC16F628A

Also the bug in " if(i=31)i=0;" which should be "==" has been noted.
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: I am new, and need help

Postby ric » Sun Aug 05, 2018 12:52 pm

Here it is with the config bits taken from the MPLABX config editor, and the main loop done in a more standard way
Code: Select all
// PIC16F628A Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ 6000000
 
void main(void)
{
    unsigned char i;
    TRISA = 0b11100000;    // RA0-4 all output
    while (1)
    {
        for(i = 0; i <= 31; i++)
        {
            PORTA = i;
            __delay_ms(100);
        }
    }
}
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


Return to 14-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest

cron