Skip to content

Latest commit

 

History

229 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Various Microchip projects for mid base PIC 12F683 or 12F675 written with pic-as or XC8 compilers.

PIC 12F683:

pic12f683-pins

This PIC has an internal 8MHz oscillor, with software selectable frequency from 125KHz, and support an external oscillator up to 20MHz. It also has 2048 words (14 bits) of program memory space (flash), 128 bytes of general purpose registers (aka data memory space - static RAM) and 256 bytes of eeprom.

PIC 12F675:

pic12F675-pins

This PIC has an internal 4MHz oscillor and support an external oscillator up to 20MHz. It also has 1024 words (14 bits) of program memory space (flash), 64 bytes of general purpose registers (aka data memory space - static RAM) and 128 bytes of eeprom.

CAREFUL: the programming of this pic will overwrite the factory oscillator calibration value (OSCCAL) and the bandgap calibration bit in the config word.
Therefore, always backup these values and restore them, especially the OSCCAL value.
The OSCCAL value is stored in the last FLASH memory address, that is 0x03FF.
The default value of a FLASH address is 0x3FFF = 11 1111 1111 1111 in binary - this will be value stored at each address when erasing a flash memory.
Flash address 0x03FF should instead contain a value in the form 0x34[OSCCAL], 0x34 being the opcode for a RETLW instruction, and OSCCAL being the 6 bits calibration value that must be stored in the OSCCAL register.
For example 0x344C will return 0x4C as the calibration value. Therefore the first instructions of the code should ALWAYS be :

bsf RP0
call 0x03ff ; get oscillator calibration value
movwf OSCCAL

See page 18 and 56 of PIC 12F675 datasheet.

If you don't reprogram correctly the address 0x03FF with 0x34xx, your code will jump to address 0x03FF and perform a addlw 255 (0x3FFF), with no return...PC counter will then wrapup to address 0x00000
I will propose later a simple method to recover the OSCCAL value in case it has been erased and not recovered.

If you program the PIC with a K150 programmer :

  • insert the chip to the correct location
  • click "CALIB" button - a warning message will then pop up telling the return value should be in the "0x34XX" form.
  • Click YES to change this value.
  • Next window, click the "Read" button ; it will retrieve the current band gap (most often 01) and oscillator values stored in the chip.
  • Click then "Yes" button and confirm to insert value in HEX file.

You should then read the correct OSCCAL value at address 0x03FF.

calib-1 calib-2

Note : to debug correctly a assembly program for PIC12F675, you must launch the "Program memory view" window, scroll down to the last address, right click and select "fill address".
Write something like 344C so the PC can return to the program address stacked with the call instruction, and run correctly.

About

Some microchip programming examples and tutorials, based on PIC 12F683

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages