Nope, it didn't work. Wondering whether I left out anything else inside. Checked: config words, connections, all OK.
Then I begin to search, and found out that I happened to received these PIC10F320 which are engineering samples (Revision 1) and should not exist in my own hands. I should have Revision 2 instead. The RAM locations in all my PIC10F320 are all wrong.
Luckily I read these links:
http://www.microchip.com/forums/m654174-print.aspx
http://www.microchip.com/forums/m623700.aspx
http://www.microchip.com/forums/m647383.aspx
and most suggested that I should compile the XC8 in a different RAM location, which is at 0x60~0x7f.
So, to (temporarily) fix that, I went to the File->Project Properties->XC8 Global Options->XC8 Linker, and then on the dropdown menu Option Categories, select Memory Model. On the RAM ranges, fill in default,-40-5f. It prevents the compiler from using the wrong memory location. Recompile the code after you change the memory ranges.
Here's the simple code, and these chips are slightly defective with the wrong memory location. I might want to return them to the store and demand for a replacement. The sample code for LED blinking on the PIC10F320 is as follows.
- CODE: SELECT_ALL_CODE
#include <xc.h>
#define _XTAL_FREQ 4000000
__CONFIG(FOSC_INTOSC & BOREN_OFF & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & LVP_OFF & LPBOR_OFF & BORV_LO & WRT_OFF);
void init() {
CLKRCONbits.CLKROE = 0; // Reference clock disabled
OSCCONbits.IRCF2 = 1; // 4mhz internal oscillator
OSCCONbits.IRCF1 = 0;
OSCCONbits.IRCF0 = 1;
ANSELA = 0x00; // all ports are digital for A/D
TRISA = 0x00;
}
void main() {
init();
while(1) {
PORTAbits.RA1 ^= 1;
__delay_ms(500);
}
}