This is intended primarily as a reference for the Rochanda Development Team at Morgan State University.
The 12C509 is treated in your Microchip PIC16/17 Microcontroller Data Book.
1 V_DD (+5) 2 GPIO5(I and O)/CLKIN 3 GPIO4(I and O) 4 GPIO3(I only)/ /MCLR 5 GPIO2(I and O) 6 GPIO1(I and O) 7 GPIO0(I and O) 8 V_SS (Ground)
Note that terminal 4 may be used as an input or as /MCLR. Normally we will use it as an input.
This requres that Bit 4 in the CONFIG word be set to a logic 0. This internally ties the master clear function to +5. We will relay on the power-on reset to vector the program to 000H.
We have the emulator, one time programmable (OTP) devices and EEPROM devices. Normally for development, we will use the emulator and the EEPROM devices and reserve the OTP devices for applications which we intend to demo.
Both the emulator and EEPROM devices support an internal clock and this frees terminal 2 for use as GPIO5. No external clock is required. To specify the internal RC clock, CONFIG word bits 1 and 0 should be set to 1 and 0 respectively.
The OTP devices which we have require an external clock. Thus, a 4.0 MHz TTL Clock Oscillator must be connected to terminal 2 and of course the GPIO5 function is not available to us. To specify an exteranl XT oscillator, CONFIG word bits 1 and 0 must be set to 0 and 1 respectively.
Watchdog Timer (WDT).
This is enabled by setting bit 2 of the CONFIG word to a logic one. Normally we will disable WDT by setting this bit to a logic 0. (However, for things we desire to us as demos we will use the WDT. This will require CLRWDT commands throughout your code.)
Set to "off" by setting bit 3 of CONFIG to logic 1.
Summary of CONFIG.
CONFIG BITS 4 3 2 1 0 MCLRE CP WDT FOSC1 FOSC2 FOR EEPROM 0 1 0 1 0 __CONFIG 0AH (dis) (dis) (dis) (internal osc) FOR OTP 0 1 0 0 1 __CONFIG 09H
The stack is limited to two. Thus nested calls must be limited to two. When exceeding this a "call" may be alternately implemented using the user stack which is detailed in another discussion.
Note that calls and returns may be made only from page 0. (We have a workaround on this).
Defining GPIO Directions.
This is a bit different than with the 16C84.
MOVLW B'101000' ; note that Bit 3 must always be an input TRIS
Unlike the 16C84 which has PORTA and PORTB, the 12C509 has only GPIO.
BSF GPIO, 0 ; bring bit 0 to a logic one MOVLW 15H ; 1 0101 MOVWF GPIO ; put it on outputs ; note that although a zero is specified on Bit 3, it will not ; appear as such as GPIO3 is only an input.
There is no ADDLW and SUBLW. Other than that, the instructions appear the same as the 16C84.