-- =================================================== -- Title: JalV2 device include file for PIC 12F510 -- -- Author: Rob Hamerling, Copyright (c) 2008..2010, all rights reserved. -- -- Adapted-by: -- -- Compiler: 2.4n -- -- This file is part of jallib (http://jallib.googlecode.com) -- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html) -- -- Description: -- Device include file for pic12f510, containing: -- - Declaration of ports and pins of the chip. -- - Procedures for shadowing of ports and pins -- to circumvent the read-modify-write problem. -- - Symbolic definitions for configuration bits (fuses) -- - Some device dependent procedures for common -- operations, like: -- . enable_digital_io() -- -- Sources: -- - x:/mplab856/mplab ide/device/pic12f510.dev -- - x:/mplab856/MPASM Suite/LKR/12f510_g.lkr -- -- Notes: -- - Created with Dev2Jal Rexx script version 0.1.05 -- - File creation date/time: 5 Sep 2010 09:06 -- -- =================================================== -- const word DEVICE_ID = 0x0000 const byte PICTYPE[] = "12F510" const byte DATASHEET[] = "41268" const byte PGMSPEC[] = "41257" -- -- Vdd Range: 2.000-5.500 Nominal: 5.000 -- Vpp Range: 10.000-12.000 Default: 11.000 -- -- --------------------------------------------------- -- include chipdef_jallib -- common constants -- pragma target cpu PIC_12 -- (banks=2) pragma target chip 12f510 pragma target bank 0x0020 pragma target page 0x0200 pragma stack 2 pragma code 1024 -- (words) pragma ID 0x400,4 pragma data 0x10-0x1F,0x30-0x3F pragma shared 0x0A-0x0F -- var volatile byte _pic_accum shared at 0x0E -- (compiler) var volatile byte _pic_isr_w shared at 0x0F -- (compiler) -- const word _FUSES_CT = 1 const word _FUSE_BASE = 0xFFF const word _FUSES = 0b_0000_1111_1111_1111 -- -- ------------------------------------------------ var volatile byte INDF at { 0x0,0x20 } var volatile byte _ind at { 0x0,0x20 } -- (compiler) -- ------------------------------------------------ var volatile byte TMR0 at { 0x1,0x21 } -- ------------------------------------------------ var volatile byte PCL at { 0x2,0x22 } var volatile byte _pcl at { 0x2,0x22 } -- (compiler) -- ------------------------------------------------ var volatile byte STATUS at { 0x3,0x23 } var volatile bit STATUS_GPWUF at STATUS : 7 var volatile bit STATUS_CWUF at STATUS : 6 var volatile bit STATUS_PA0 at STATUS : 5 var volatile bit STATUS_NTO at STATUS : 4 var volatile bit STATUS_NPD at STATUS : 3 var volatile bit STATUS_Z at STATUS : 2 var volatile bit STATUS_DC at STATUS : 1 var volatile bit STATUS_C at STATUS : 0 var volatile byte _status at { 0x3,0x23 } -- (compiler) const byte _gpwuf = 7 -- (compiler) const byte _cwuf = 6 -- (compiler) const byte _pa0 = 5 -- (compiler) const byte _not_to = 4 -- (compiler) const byte _not_pd = 3 -- (compiler) const byte _z = 2 -- (compiler) const byte _dc = 1 -- (compiler) const byte _c = 0 -- (compiler) -- ------------------------------------------------ var volatile byte FSR at { 0x4,0x24 } var volatile byte _fsr at { 0x4,0x24 } -- (compiler) -- ------------------------------------------------ var volatile byte OSCCAL at { 0x5,0x25 } var volatile bit*7 OSCCAL_CAL at OSCCAL : 1 -- ------------------------------------------------ var volatile byte GPIO at { 0x6,0x26 } var volatile byte PORTA at GPIO -- var byte _PORTA_shadow = PORTA -- procedure _PORTA_flush() is pragma inline PORTA = _PORTA_shadow end procedure procedure PORTA'put(byte in x) is pragma inline _PORTA_shadow = x _PORTA_flush() end procedure -- procedure PORTA_low'put(byte in x) is pragma inline _PORTA_shadow = (_PORTA_shadow & 0xF0) | (x & 0x0F) _PORTA_flush() end procedure function PORTA_low'get() return byte is pragma inline return (PORTA & 0x0F) end function -- procedure PORTA_high'put(byte in x) is pragma inline _PORTA_shadow = (_PORTA_shadow & 0x0F) | (x << 4) _PORTA_flush() end procedure function PORTA_high'get() return byte is pragma inline return (PORTA >> 4) end function -- var volatile bit GPIO_GP5 at GPIO : 5 var volatile bit pin_A5 at GPIO : 5 alias pin_GP5 is pin_A5 alias pin_OSC1 is pin_A5 alias pin_CLKIN is pin_A5 -- procedure pin_A5'put(bit in x at _PORTA_shadow : 5) is pragma inline _PORTA_flush() end procedure -- var volatile bit GPIO_GP4 at GPIO : 4 var volatile bit pin_A4 at GPIO : 4 alias pin_GP4 is pin_A4 alias pin_OSC2 is pin_A4 -- procedure pin_A4'put(bit in x at _PORTA_shadow : 4) is pragma inline _PORTA_flush() end procedure -- var volatile bit GPIO_GP3 at GPIO : 3 var volatile bit pin_A3 at GPIO : 3 alias pin_GP3 is pin_A3 alias pin_MCLR is pin_A3 alias pin_VPP is pin_A3 -- procedure pin_A3'put(bit in x at _PORTA_shadow : 3) is pragma inline _PORTA_flush() end procedure -- var volatile bit GPIO_GP2 at GPIO : 2 var volatile bit pin_A2 at GPIO : 2 alias pin_GP2 is pin_A2 alias pin_AN2 is pin_A2 alias pin_T0CKI is pin_A2 alias pin_C1OUT is pin_A2 -- procedure pin_A2'put(bit in x at _PORTA_shadow : 2) is pragma inline _PORTA_flush() end procedure -- var volatile bit GPIO_GP1 at GPIO : 1 var volatile bit pin_A1 at GPIO : 1 alias pin_GP1 is pin_A1 alias pin_AN1 is pin_A1 alias pin_C1IN_NEG is pin_A1 alias pin_ICSPCLK is pin_A1 -- procedure pin_A1'put(bit in x at _PORTA_shadow : 1) is pragma inline _PORTA_flush() end procedure -- var volatile bit GPIO_GP0 at GPIO : 0 var volatile bit pin_A0 at GPIO : 0 alias pin_GP0 is pin_A0 alias pin_AN0 is pin_A0 alias pin_C1IN_POS is pin_A0 alias pin_ICSPDAT is pin_A0 -- procedure pin_A0'put(bit in x at _PORTA_shadow : 0) is pragma inline _PORTA_flush() end procedure -- -- ------------------------------------------------ var volatile byte CM1CON0 at { 0x7,0x27 } var volatile bit CM1CON0_C1OUT at CM1CON0 : 7 var volatile bit CM1CON0_NC1OUTEN at CM1CON0 : 6 var volatile bit CM1CON0_C1POL at CM1CON0 : 5 var volatile bit CM1CON0_NC1T0CS at CM1CON0 : 4 var volatile bit CM1CON0_C1ON at CM1CON0 : 3 var volatile bit CM1CON0_C1NREF at CM1CON0 : 2 var volatile bit CM1CON0_C1PREF at CM1CON0 : 1 var volatile bit CM1CON0_NC1WU at CM1CON0 : 0 -- ------------------------------------------------ var volatile byte ADCON0 at { 0x8,0x28 } var volatile bit JANSEL_ANS1 at ADCON0 : 7 var volatile bit JANSEL_ANS0 at ADCON0 : 6 var volatile bit*2 ADCON0_ADCS at ADCON0 : 4 var volatile bit*2 ADCON0_CHS at ADCON0 : 2 var volatile bit ADCON0_GO at ADCON0 : 1 var volatile bit ADCON0_NDONE at ADCON0 : 1 var volatile bit ADCON0_ADON at ADCON0 : 0 -- ------------------------------------------------ var volatile byte ADRES at { 0x9,0x29 } -- ------------------------------------------------ var byte _TRISA_shadow = 0b1111_1111 -- default all input -- procedure PORTA_direction'put(byte in x) is pragma inline _TRISA_shadow = x asm movf _TRISA_shadow,W asm tris 6 end procedure -- procedure PORTA_low_direction'put(byte in x) is pragma inline _TRISA_shadow = (_TRISA_shadow & 0xF0) | (x & 0x0F) asm movf _TRISA_shadow,W asm tris 6 end procedure -- procedure PORTA_high_direction'put(byte in x) is pragma inline _TRISA_shadow = (_TRISA_shadow & 0x0F) | (x << 4) asm movf _TRISA_shadow,W asm tris 6 end procedure -- procedure pin_A5_direction'put(bit in x at _TRISA_shadow : 5) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP5_direction is pin_A5_direction alias pin_OSC1_direction is pin_A5_direction alias pin_CLKIN_direction is pin_A5_direction -- procedure pin_A4_direction'put(bit in x at _TRISA_shadow : 4) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP4_direction is pin_A4_direction alias pin_OSC2_direction is pin_A4_direction -- procedure pin_A3_direction'put(bit in x at _TRISA_shadow : 3) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP3_direction is pin_A3_direction alias pin_MCLR_direction is pin_A3_direction alias pin_VPP_direction is pin_A3_direction -- procedure pin_A2_direction'put(bit in x at _TRISA_shadow : 2) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP2_direction is pin_A2_direction alias pin_AN2_direction is pin_A2_direction alias pin_T0CKI_direction is pin_A2_direction alias pin_C1OUT_direction is pin_A2_direction -- procedure pin_A1_direction'put(bit in x at _TRISA_shadow : 1) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP1_direction is pin_A1_direction alias pin_AN1_direction is pin_A1_direction alias pin_C1IN_NEG_direction is pin_A1_direction alias pin_ICSPCLK_direction is pin_A1_direction -- procedure pin_A0_direction'put(bit in x at _TRISA_shadow : 0) is pragma inline asm movf _TRISA_shadow,W asm tris 6 end procedure alias pin_GP0_direction is pin_A0_direction alias pin_AN0_direction is pin_A0_direction alias pin_C1IN_POS_direction is pin_A0_direction alias pin_ICSPDAT_direction is pin_A0_direction -- -- ------------------------------------------------ var byte _OPTION_REG_shadow = 0b1111_1111 -- default all set -- procedure OPTION_REG'put(byte in x) is pragma inline _OPTION_REG_shadow = x asm movf _OPTION_REG_shadow,0 asm option end procedure -- procedure OPTION_REG_NGPWU'put(bit in x at _OPTION_REG_shadow : 7) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure -- procedure OPTION_REG_NGPPU'put(bit in x at _OPTION_REG_shadow : 6) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure -- procedure OPTION_REG_T0CS'put(bit in x at _OPTION_REG_shadow : 5) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure alias T0CON_T0CS is OPTION_REG_T0CS -- procedure OPTION_REG_T0SE'put(bit in x at _OPTION_REG_shadow : 4) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure alias T0CON_T0SE is OPTION_REG_T0SE -- procedure OPTION_REG_PSA'put(bit in x at _OPTION_REG_shadow : 3) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure alias T0CON_PSA is OPTION_REG_PSA -- procedure OPTION_REG_PS'put(bit*3 in x at _OPTION_REG_shadow : 0) is pragma inline asm movf _OPTION_REG_shadow,0 asm option end procedure alias T0CON_T0PS is OPTION_REG_PS -- -- =================================================== -- -- Special (device specific) constants and procedures -- const ADC_GROUP = ADC_V0 const byte ADC_NTOTAL_CHANNEL = 3 -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Disable ADC module procedure adc_off() is pragma inline ADCON0 = 0b0000_0000 -- disable ADC end procedure -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Disable comparator module procedure comparator_off() is pragma inline CM1CON0 = 0b0000_0000 -- disable comparator end procedure -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Switch analog ports to digital mode (if analog module present). procedure enable_digital_io() is pragma inline adc_off() comparator_off() OPTION_REG_T0CS = OFF -- T0CKI pin input + output end procedure -- -- ================================================== -- -- Symbolic Fuse definitions -- ------------------------- -- -- CONFIG (0xFFF) -- pragma fuse_def OSC 0x3 { -- oscillator select RC_NOCLKOUT = 0x3 -- extrc with 1.125 ms drt INTOSC_NOCLKOUT = 0x2 -- intosc with 1.125 ms drt XT = 0x1 -- xt oscillator with 18 ms drt LP = 0x0 -- lp oscillator with 18 ms drt } pragma fuse_def WDT 0x4 { -- watchdog timer enable bit ENABLED = 0x4 -- enabled DISABLED = 0x0 -- disabled } pragma fuse_def CP 0x8 { -- code protect DISABLED = 0x8 -- disabled ENABLED = 0x0 -- enabled } pragma fuse_def MCLR 0x10 { -- master clear enable bit EXTERNAL = 0x10 -- enabled INTERNAL = 0x0 -- disabled } pragma fuse_def IOSCFS 0x20 { -- internal oscillator frequency select bit F8MHZ = 0x20 -- 8mhz F4MHZ = 0x0 -- 4mhz } --