In the last few days I'm trying to set up simple program (blinking LED) with included configuration bits, in order to check if PIC responds correctly. I have already wired all needed components for this project: added R-C (10k, 22pF) to oscillator pin (OSC2/RA6), 10k pull-up resistor on MCLR, LED with 330R in series to RD0 pin and lastly PICKit3 programmer to all needed pins (wired correctly, I double checked it).
MPLAB tells me that it recognized the device via programmer, and the code is uploaded without errors (see pictures below). However, the problem might lie in me not setting configuration bits correctly. When I open MCC, there is no port A, B, C or D, where I could set them as I/O ports. But PIC18F452 has multiple I/O ports. So, how to I manually set these ports as output or input? Does this need to be defined in configuration bits area or in main.c file? If so, can someone demonstrate, what I should be or shouldn't be doing it this particular situation?
Here is the main.c file:
- Code: Select all
#include <xc.h>
#include <htc.h>
#include <p18cxxx.h>
#include "conifg.h"
void delay (void)
{
int i;
for (i = 0; i < 10000; i++)
;
}
void main( void )
{
TRISD = 0x00;
while (1) {
PORTDbits.RD0 = 1;
delay();
PORTDbits.RD0 = 0;
delay();
}
}
And here is header file (configuration bits) for this project:
- Code: Select all
#ifndef CONFIG_H
#define CONFIG_H
#include <xc.h> // include processor files - each processor file is guarded.
#define _XTAL_FREQ 1000000
// PIC18F452 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1H
#pragma config OSC = RCIO // Oscillator Selection bits (XT oscillator)
#pragma config OSCS = OFF // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = OFF // Brown-out Reset Enable bit (Brown-out Reset disabled)
#pragma config BORV = 20 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128)
// CONFIG3H
#pragma config CCP2MUX = ON // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
// CONFIG4L
#pragma config STVR = OFF // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will not cause RESET)
#pragma config LVP = ON // Low Voltage ICSP Enable bit (Low Voltage ICSP enabled)
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) not code protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) not write protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#endif /* XC_HEADER_TEMPLATE_H */
*P.S. I know some basic stuff about coding in C, but know very little to nothing about coding in C for PIC. I also have PIC16F628A; might have less trouble setting up this one.