What I use
- Arduino Uno (as a power supplier)
- PicKit 5
- MPLAB X IDE 6.15
- PIC10F200
What I know :
- The OPTIONS on some pins can overwrite the TRIS states (I somewhat read the datasheet but it gets me tired to jump back and forward);
- What 0b00001000 means (somewhat).
The project
I'm trying to program a PIC10F200 for a simple project, basically: GP1 gets power flowing into it or not, based on that information GP0 either turns the LED ON or keeps it OFF.
I have used this code to check that the pins are not shorted :
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <PIC10F200.h>
#define _XTAL_FREQ 4000000
// CONFIG
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config CP = OFF // Code Protect (Code protection off)
#pragma config MCLRE = OFF // Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)
void main(void)
{
OPTION = 0b11011111;
TRISGPIO = 0b00001000;
GPIO = 0b00000111;
}
What I need help with
- Explain some more basic commands for my lack of embedded knowledge;
- Maybe the circuit is built wrong, suggest options.
So after that check, this was the code I created (I don't understand also what is wrong when posting the code so... I'm sorry.):
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
// CONFIG
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config CP = OFF // Code Protect (Code protection off)
#pragma config MCLRE = OFF
#define _XTAL_FREQ 4000000
void main()
{
OPTION = 0b11011111;
TRISGPIO = 0b00000010;
GPIO = 0b00000000;
while(1)
{
if(GP1 == '1')
{
GP0 = '0';
}
else
{
GP0 = '1';
}
}
}

Background (If you ask yourself why I'm so unintelligent...)
- Lack of knowledge on electronics;
- Rusty on physics;
- Study univ (electrical engineering - the irony... you may say...);
- Teachers are not very bright neither helpful ("You should worry about failing exams, not this");
- Can't spend extra time to work and earn money (At least I would've done something productive so it helps me live?);
- Can't spend extra time to research or read a lot (I lose 5~6h traveling daily - no, I can't watch youtube or listen to audio logs );
- Most of youtube videos don't help (outdated aka: 3 years ago - assembly / other microcontrollers);
- Didn't get to learn Assembly (also the compiler does not support Assembly language anymore?! - I think).
Try working project, got no working project.
[edit]
#include <stdio.h>
#include <stdlib.h>
#include <PIC10F200.h>
// CONFIG
#pragma config WDTE = OFF
#pragma config CP = OFF
#pragma config MCLRE = 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 4000000
void main() {
OPTION = 0b11011111;
TRISGPIO = 0b00000010;
GPIO = 0b00000000;
while (1) {
if (GP1 == '1') {
GP0 = '0'; // Turn off the LED
} else {
GP0 = '1'; // Turn on the LED
}
}
}
Header file :
// Register: INDF
#define INDF INDF
extern volatile unsigned char INDF __at(0x000);
#ifndef _LIB_BUILD
asm("INDF equ 00h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned INDF :8;
};
} INDFbits_t;
extern volatile INDFbits_t INDFbits __at(0x000);
// bitfield macros
#define _INDF_INDF_POSN 0x0
#define _INDF_INDF_POSITION 0x0
#define _INDF_INDF_SIZE 0x8
#define _INDF_INDF_LENGTH 0x8
#define _INDF_INDF_MASK 0xFF
// Register: TMR0
#define TMR0 TMR0
extern volatile unsigned char TMR0 __at(0x001);
#ifndef _LIB_BUILD
asm("TMR0 equ 01h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned TMR0 :8;
};
} TMR0bits_t;
extern volatile TMR0bits_t TMR0bits __at(0x001);
// bitfield macros
#define _TMR0_TMR0_POSN 0x0
#define _TMR0_TMR0_POSITION 0x0
#define _TMR0_TMR0_SIZE 0x8
#define _TMR0_TMR0_LENGTH 0x8
#define _TMR0_TMR0_MASK 0xFF
// Register: PCL
#define PCL PCL
extern volatile unsigned char PCL __at(0x002);
#ifndef _LIB_BUILD
asm("PCL equ 02h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned PCL :8;
};
} PCLbits_t;
extern volatile PCLbits_t PCLbits __at(0x002);
// bitfield macros
#define _PCL_PCL_POSN 0x0
#define _PCL_PCL_POSITION 0x0
#define _PCL_PCL_SIZE 0x8
#define _PCL_PCL_LENGTH 0x8
#define _PCL_PCL_MASK 0xFF
// Register: STATUS
#define STATUS STATUS
extern volatile unsigned char STATUS __at(0x003);
#ifndef _LIB_BUILD
asm("STATUS equ 03h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned C :1;
unsigned DC :1;
unsigned Z :1;
unsigned nPD :1;
unsigned nTO :1;
unsigned :2;
unsigned GPWUF :1;
};
struct {
unsigned CARRY :1;
unsigned :1;
unsigned ZERO :1;
};
} STATUSbits_t;
extern volatile STATUSbits_t STATUSbits __at(0x003);
// bitfield macros
#define _STATUS_C_POSN 0x0
#define _STATUS_C_POSITION 0x0
#define _STATUS_C_SIZE 0x1
#define _STATUS_C_LENGTH 0x1
#define _STATUS_C_MASK 0x1
#define _STATUS_DC_POSN 0x1
#define _STATUS_DC_POSITION 0x1
#define _STATUS_DC_SIZE 0x1
#define _STATUS_DC_LENGTH 0x1
#define _STATUS_DC_MASK 0x2
#define _STATUS_Z_POSN 0x2
#define _STATUS_Z_POSITION 0x2
#define _STATUS_Z_SIZE 0x1
#define _STATUS_Z_LENGTH 0x1
#define _STATUS_Z_MASK 0x4
#define _STATUS_nPD_POSN 0x3
#define _STATUS_nPD_POSITION 0x3
#define _STATUS_nPD_SIZE 0x1
#define _STATUS_nPD_LENGTH 0x1
#define _STATUS_nPD_MASK 0x8
#define _STATUS_nTO_POSN 0x4
#define _STATUS_nTO_POSITION 0x4
#define _STATUS_nTO_SIZE 0x1
#define _STATUS_nTO_LENGTH 0x1
#define _STATUS_nTO_MASK 0x10
#define _STATUS_GPWUF_POSN 0x7
#define _STATUS_GPWUF_POSITION 0x7
#define _STATUS_GPWUF_SIZE 0x1
#define _STATUS_GPWUF_LENGTH 0x1
#define _STATUS_GPWUF_MASK 0x80
#define _STATUS_CARRY_POSN 0x0
#define _STATUS_CARRY_POSITION 0x0
#define _STATUS_CARRY_SIZE 0x1
#define _STATUS_CARRY_LENGTH 0x1
#define _STATUS_CARRY_MASK 0x1
#define _STATUS_ZERO_POSN 0x2
#define _STATUS_ZERO_POSITION 0x2
#define _STATUS_ZERO_SIZE 0x1
#define _STATUS_ZERO_LENGTH 0x1
#define _STATUS_ZERO_MASK 0x4
// Register: FSR
#define FSR FSR
extern volatile unsigned char FSR __at(0x004);
#ifndef _LIB_BUILD
asm("FSR equ 04h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned FSR :8;
};
} FSRbits_t;
extern volatile FSRbits_t FSRbits __at(0x004);
// bitfield macros
#define _FSR_FSR_POSN 0x0
#define _FSR_FSR_POSITION 0x0
#define _FSR_FSR_SIZE 0x8
#define _FSR_FSR_LENGTH 0x8
#define _FSR_FSR_MASK 0xFF
// Register: OSCCAL
#define OSCCAL OSCCAL
extern volatile unsigned char OSCCAL __at(0x005);
#ifndef _LIB_BUILD
asm("OSCCAL equ 05h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned FOSC4 :1;
unsigned CAL :7;
};
struct {
unsigned :1;
unsigned CAL0 :1;
unsigned CAL1 :1;
unsigned CAL2 :1;
unsigned CAL3 :1;
unsigned CAL4 :1;
unsigned CAL5 :1;
unsigned CAL6 :1;
};
} OSCCALbits_t;
extern volatile OSCCALbits_t OSCCALbits __at(0x005);
// bitfield macros
#define _OSCCAL_FOSC4_POSN 0x0
#define _OSCCAL_FOSC4_POSITION 0x0
#define _OSCCAL_FOSC4_SIZE 0x1
#define _OSCCAL_FOSC4_LENGTH 0x1
#define _OSCCAL_FOSC4_MASK 0x1
#define _OSCCAL_CAL_POSN 0x1
#define _OSCCAL_CAL_POSITION 0x1
#define _OSCCAL_CAL_SIZE 0x7
#define _OSCCAL_CAL_LENGTH 0x7
#define _OSCCAL_CAL_MASK 0xFE
#define _OSCCAL_CAL0_POSN 0x1
#define _OSCCAL_CAL0_POSITION 0x1
#define _OSCCAL_CAL0_SIZE 0x1
#define _OSCCAL_CAL0_LENGTH 0x1
#define _OSCCAL_CAL0_MASK 0x2
#define _OSCCAL_CAL1_POSN 0x2
#define _OSCCAL_CAL1_POSITION 0x2
#define _OSCCAL_CAL1_SIZE 0x1
#define _OSCCAL_CAL1_LENGTH 0x1
#define _OSCCAL_CAL1_MASK 0x4
#define _OSCCAL_CAL2_POSN 0x3
#define _OSCCAL_CAL2_POSITION 0x3
#define _OSCCAL_CAL2_SIZE 0x1
#define _OSCCAL_CAL2_LENGTH 0x1
#define _OSCCAL_CAL2_MASK 0x8
#define _OSCCAL_CAL3_POSN 0x4
#define _OSCCAL_CAL3_POSITION 0x4
#define _OSCCAL_CAL3_SIZE 0x1
#define _OSCCAL_CAL3_LENGTH 0x1
#define _OSCCAL_CAL3_MASK 0x10
#define _OSCCAL_CAL4_POSN 0x5
#define _OSCCAL_CAL4_POSITION 0x5
#define _OSCCAL_CAL4_SIZE 0x1
#define _OSCCAL_CAL4_LENGTH 0x1
#define _OSCCAL_CAL4_MASK 0x20
#define _OSCCAL_CAL5_POSN 0x6
#define _OSCCAL_CAL5_POSITION 0x6
#define _OSCCAL_CAL5_SIZE 0x1
#define _OSCCAL_CAL5_LENGTH 0x1
#define _OSCCAL_CAL5_MASK 0x40
#define _OSCCAL_CAL6_POSN 0x7
#define _OSCCAL_CAL6_POSITION 0x7
#define _OSCCAL_CAL6_SIZE 0x1
#define _OSCCAL_CAL6_LENGTH 0x1
#define _OSCCAL_CAL6_MASK 0x80
// Register: GPIO
#define GPIO GPIO
extern volatile unsigned char GPIO __at(0x006);
#ifndef _LIB_BUILD
asm("GPIO equ 06h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned GP0 :1;
unsigned GP1 :1;
unsigned GP2 :1;
unsigned GP3 :1;
};
} GPIObits_t;
extern volatile GPIObits_t GPIObits __at(0x006);
// bitfield macros
#define _GPIO_GP0_POSN 0x0
#define _GPIO_GP0_POSITION 0x0
#define _GPIO_GP0_SIZE 0x1
#define _GPIO_GP0_LENGTH 0x1
#define _GPIO_GP0_MASK 0x1
#define _GPIO_GP1_POSN 0x1
#define _GPIO_GP1_POSITION 0x1
#define _GPIO_GP1_SIZE 0x1
#define _GPIO_GP1_LENGTH 0x1
#define _GPIO_GP1_MASK 0x2
#define _GPIO_GP2_POSN 0x2
#define _GPIO_GP2_POSITION 0x2
#define _GPIO_GP2_SIZE 0x1
#define _GPIO_GP2_LENGTH 0x1
#define _GPIO_GP2_MASK 0x4
#define _GPIO_GP3_POSN 0x3
#define _GPIO_GP3_POSITION 0x3
#define _GPIO_GP3_SIZE 0x1
#define _GPIO_GP3_LENGTH 0x1
#define _GPIO_GP3_MASK 0x8
// Register: OPTION
#define OPTION OPTION
extern volatile __control unsigned char OPTION __at(0x000);
// Register: TRIS
#define TRIS TRIS
extern volatile __control unsigned char TRIS __at(0x006);
// Register: TRISGPIO
#define TRISGPIO TRISGPIO
extern volatile __control unsigned char TRISGPIO __at(0x006);
/*
* OPTION bits
*/
#define PS 0x7
#define PSA 0x8
#define T0SE 0x10
#define T0CS 0x20
#define nGPPU 0x40
#define nGPWU 0x80
#define PS0 0x1
#define PS1 0x2
#define PS2 0x4
/*
* Bit Definitions
*/
#define _DEPRECATED __attribute__((__deprecated__))
#ifndef BANKMASK
#define BANKMASK(addr) ((addr)&01Fh)
#endif
#define _BIT_ACCESS(r,b) ___mkstr(BANKMASK(r)) "," ___mkstr(b)
#ifndef PAGEMASK
#define PAGEMASK(addr) ((addr)&01FFh)
#endif
// OSCCAL<CAL0>
extern volatile __bit CAL0 __at(0x29); // @ (0x5 * 8 + 1)
#define CAL0_bit _BIT_ACCESS(OSCCAL,1)
// OSCCAL<CAL1>
extern volatile __bit CAL1 __at(0x2A); // @ (0x5 * 8 + 2)
#define CAL1_bit _BIT_ACCESS(OSCCAL,2)
// OSCCAL<CAL2>
extern volatile __bit CAL2 __at(0x2B); // @ (0x5 * 8 + 3)
#define CAL2_bit _BIT_ACCESS(OSCCAL,3)
// OSCCAL<CAL3>
extern volatile __bit CAL3 __at(0x2C); // @ (0x5 * 8 + 4)
#define CAL3_bit _BIT_ACCESS(OSCCAL,4)
// OSCCAL<CAL4>
extern volatile __bit CAL4 __at(0x2D); // @ (0x5 * 8 + 5)
#define CAL4_bit _BIT_ACCESS(OSCCAL,5)
// OSCCAL<CAL5>
extern volatile __bit CAL5 __at(0x2E); // @ (0x5 * 8 + 6)
#define CAL5_bit _BIT_ACCESS(OSCCAL,6)
// OSCCAL<CAL6>
extern volatile __bit CAL6 __at(0x2F); // @ (0x5 * 8 + 7)
#define CAL6_bit _BIT_ACCESS(OSCCAL,7)
// STATUS<CARRY>
extern volatile __bit CARRY __at(0x18); // @ (0x3 * 8 + 0)
#define CARRY_bit _BIT_ACCESS(STATUS,0)
// STATUS<DC>
extern volatile __bit DC __at(0x19); // @ (0x3 * 8 + 1)
#define DC_bit _BIT_ACCESS(STATUS,1)
// OSCCAL<FOSC4>
extern volatile __bit FOSC4 __at(0x28); // @ (0x5 * 8 + 0)
#define FOSC4_bit _BIT_ACCESS(OSCCAL,0)
// GPIO<GP0>
extern volatile __bit GP0 __at(0x30); // @ (0x6 * 8 + 0)
#define GP0_bit _BIT_ACCESS(GPIO,0)
// GPIO<GP1>
extern volatile __bit GP1 __at(0x31); // @ (0x6 * 8 + 1)
#define GP1_bit _BIT_ACCESS(GPIO,1)
// GPIO<GP2>
extern volatile __bit GP2 __at(0x32); // @ (0x6 * 8 + 2)
#define GP2_bit _BIT_ACCESS(GPIO,2)
// GPIO<GP3>
extern volatile __bit GP3 __at(0x33); // @ (0x6 * 8 + 3)
#define GP3_bit _BIT_ACCESS(GPIO,3)
// STATUS<GPWUF>
extern volatile __bit GPWUF __at(0x1F); // @ (0x3 * 8 + 7)
#define GPWUF_bit _BIT_ACCESS(STATUS,7)
// STATUS<ZERO>
extern volatile __bit ZERO __at(0x1A); // @ (0x3 * 8 + 2)
#define ZERO_bit _BIT_ACCESS(STATUS,2)
// STATUS<nPD>
extern volatile __bit nPD __at(0x1B); // @ (0x3 * 8 + 3)
#define nPD_bit _BIT_ACCESS(STATUS,3)
// STATUS<nTO>
extern volatile __bit nTO __at(0x1C); // @ (0x3 * 8 + 4)
#define nTO_bit _BIT_ACCESS(STATUS,4)
#endif // _PIC10F200_H_
GP0 = '0';sets GP0 to the ASCII value of the character0, i.e. 48. Probably not what you want. Likewise comparingGP1 == '1', which is comparing GP1 with 49.