- Code: Select all
#include <xc.h>
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/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 = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config IOSCFS = 4MHZ // Internal Oscillator Frequency Select (4 MHz)
#pragma config BOREN = OFF // Brown-out Reset Selection bits (BOR disabled)
int main(void) {
ANSEL = 0x00; // All IO pins are configured as digital
GPIO = 0; // Reset all GPIO
TRISIO = 0b00100000; //All GPIO pins to output
CCP1CON = 0x00; //disable PWM pin CCP1
//PWM frequency
PR2 = 58; //Frequency = 17 kHz (with clock 4MHz)
//PWM duty cycle (50%)
CCPR1L = 29; //PR2*0.5
//PWM Enable
CCP1CON = 0x0C ; //PWM enable, P1A output active-high
//Timer2 (Prescaler = 1:1)
TMR2 = 0; //clear TM2 counter
while(1)
{
PIR1 &= ~(0x01 << 1); //clear Timer2 Flag on TMR2IF
TMR2ON |= (0x01 <<2); //Enable Timer2
while(PIR1.TMR2IF == 0); //wait until TM2IF is high
}
return 0;
}
The compilation has no error. However, when I tried to load the code into my PIC, there is an error like this:
- Code: Select all
The following memory area(s) will be programmed:
program memory: start address = 0x0, end address = 0x3ff
configuration memory
program memory
Address: 0 Expected Value: 2bfe Received Value: 280e
Fail to program device
When this program fails, I replace my current PIC with a new one. First, I load the empty program, it could load the program inside. Then, I tried again with my program, the same error happens. After that, I tried again with empty program, it is no longer possible to load the program inside. Thus, I suppose my error doesn't come from the problem of the PIC or the ICD 3, but maybe the software program itself. Did I do something wrong in my program that kills the chip?
Here are the images for the PCB, schematics of the PCB and my hardware connection (The image is large so I cannot upload directly here). The PCB is attached into the Crazyflie and get the voltage supply from the Crazyflie quadcopter (3-4V).
Link: https://drive.google.com/file/d/0B6FAxuaQs3YtQmVmZkRaSGlPdnM/view?usp=sharing
Thank you for your help.