Skip to content

MPLAB X "Hello, World !".

1.XC8 - C Language.

// Configuration Registers.
#pragma config FOSC=INTOSC, WDTE=OFF, PWRTE=OFF, MCLRE=ON, CP=OFF
#pragma config CPD=OFF, BOREN=OFF, CLKOUTEN=ON, IESO=OFF, FCMEN=OFF
#pragma config WRT=OFF, PLLEN=OFF, STVREN=ON, BORV=LO, LVP=ON

#include <xc.h>
// PIC12F1822 - Compile with XC8(v2.45).
// PIC12F1822 - @8MHz Internal Oscillator.

// Clock OUT Enable.

// MCU.RA4 -> OSCILLOSCOPE.PROBE.A.

// Main.
void main(void)
{
    // MCU Initialization.
    // Internal Oscillator Settings.
    OSCCON = 0b01110000;
    // Ports Settings.
    // PORT Data Register.
    PORTA = 0b00000000;
    // TRIS Data Direction.
    TRISA = 0b00000000;
    // WPU Disable.
    OPTION_REGbits.nWPUEN = 0b1;
    // LATCH Outputs.
    LATA = 0b00000000;
    // ALTERNATE Pin Function.
    APFCON = 0b00000000;
    // ANSEL Analog.
    ANSELA = 0b00000000;
    // WPU Weak Pull-up.
    WPUA = 0b00000000;

    while(1){
    }
}
Oscilloscope screenshot.

Code.

2.PIC-AS - Assembly Instructions.

; Configuration Registers.
CONFIG FOSC=INTOSC
CONFIG WDTE=OFF
CONFIG PWRTE=OFF
CONFIG MCLRE=ON
CONFIG CP=OFF
CONFIG CPD=OFF
CONFIG BOREN=OFF
CONFIG CLKOUTEN=ON
CONFIG IESO=OFF
CONFIG FCMEN=OFF
CONFIG WRT=OFF
CONFIG PLLEN=OFF
CONFIG STVREN=ON
CONFIG BORV=LO
CONFIG LVP=ON

#include <xc.inc>
; PIC12F1822 - Compile with PIC-AS(v2.45).
; PIC12F1822 - @8MHz Internal Oscillator.
; -preset_vec=0000h, -pcinit=0005h.

; Clock OUT Enable.

; MCU.RA4 -> OSCILLOSCOPE.PROBE.A.

; Reset Vector.
PSECT reset_vec,class=CODE,space=0,delta=2
resetVector:
    GOTO    initialize

; Main.
PSECT cinit,class=CODE,space=0,delta=2
initialize:
    ; MCU Initialization.
    ; Internal Oscillator Settings.
    MOVLB   0x01
    MOVLW   0b01110000
    MOVWF   OSCCON
    ; Ports Settings.
    ; PORT Data Register.
    MOVLB   0x00
    MOVLW   0b00000000
    MOVWF   PORTA
    ; TRIS Data Direction.
    MOVLB   0x01
    MOVLW   0b00000000
    MOVWF   TRISA
    ; WPU Disable.
    BSF     nWPUEN
    ; LATCH Outputs.
    MOVLB   0x02
    MOVLW   0b00000000
    MOVWF   LATA
    ; ALTERNATE Pin Function.
    MOVLW   0b00000000
    MOVWF   APFCON
    ; ANSEL Analog.
    MOVLB   0x03
    MOVLW   0b00000000
    MOVWF   ANSELA
    ; WPU Weak Pull-up.
    MOVLB   0x04
    MOVLW   0b00000000
    MOVWF   WPUA

loop:
    BRA     $

    END resetVector
Oscilloscope screenshot.
  • For display "Data & Program Memory Usage":
    • Project Properties > Loading > Load symbols when programming...

Code.

  • For display "Psect Usage Map":

    • Project Properties > pic-as Global Options
    • Option categories > (Check) Program section (psect)
  • For display "Memory Class Usage":

    • Project Properties > pic-as Global Options
    • Option categories > (Check) Class

Code.

  • Configure Program Sectors, read your MCU Datasheet about Memory organisation.
  • Project Properties > pic-as Global Options > pic-as Linker
    • Reset Vector: -presect_vector=0000h
    • Initialization code: -pcinit=0005h
Code.