-- =================================================== -- Title: JalV2 device include file for PIC 16F505 -- -- 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 pic16f505, 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/pic16f505.dev -- - x:/mplab856/MPASM Suite/LKR/16f505_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[] = "16F505" const byte DATASHEET[] = "41236" const byte PGMSPEC[] = "41226" -- -- Vdd Range: 2.500-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=4) pragma target chip 16f505 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,0x50-0x5F,0x70-0x7F pragma shared 0x08-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,0x40,0x60 } var volatile byte _ind at { 0x0,0x20,0x40,0x60 } -- (compiler) -- ------------------------------------------------ var volatile byte TMR0 at { 0x1,0x21,0x41,0x61 } -- ------------------------------------------------ var volatile byte PCL at { 0x2,0x22,0x42,0x62 } var volatile byte _pcl at { 0x2,0x22,0x42,0x62 } -- (compiler) -- ------------------------------------------------ var volatile byte STATUS at { 0x3,0x23,0x43,0x63 } var volatile bit STATUS_RBWUF at STATUS : 7 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,0x43,0x63 } -- (compiler) const byte _rbwuf = 7 -- (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,0x44,0x64 } var volatile byte _fsr at { 0x4,0x24,0x44,0x64 } -- (compiler) -- ------------------------------------------------ var volatile byte OSCCAL at { 0x5,0x25,0x45,0x65 } var volatile bit*7 OSCCAL_CAL at OSCCAL : 1 -- ------------------------------------------------ var volatile byte PORTB at { 0x6,0x26,0x46,0x66 } -- var byte _PORTB_shadow = PORTB -- procedure _PORTB_flush() is pragma inline PORTB = _PORTB_shadow end procedure procedure PORTB'put(byte in x) is pragma inline _PORTB_shadow = x _PORTB_flush() end procedure -- procedure PORTB_low'put(byte in x) is pragma inline _PORTB_shadow = (_PORTB_shadow & 0xF0) | (x & 0x0F) _PORTB_flush() end procedure function PORTB_low'get() return byte is pragma inline return (PORTB & 0x0F) end function -- procedure PORTB_high'put(byte in x) is pragma inline _PORTB_shadow = (_PORTB_shadow & 0x0F) | (x << 4) _PORTB_flush() end procedure function PORTB_high'get() return byte is pragma inline return (PORTB >> 4) end function -- var volatile bit PORTB_RB5 at PORTB : 5 var volatile bit pin_B5 at PORTB : 5 alias pin_OSC1 is pin_B5 alias pin_CLKIN is pin_B5 -- procedure pin_B5'put(bit in x at _PORTB_shadow : 5) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB4 at PORTB : 4 var volatile bit pin_B4 at PORTB : 4 alias pin_OSC2 is pin_B4 alias pin_CLKOUT is pin_B4 -- procedure pin_B4'put(bit in x at _PORTB_shadow : 4) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB3 at PORTB : 3 var volatile bit pin_B3 at PORTB : 3 alias pin_MCLR is pin_B3 alias pin_VPP is pin_B3 -- procedure pin_B3'put(bit in x at _PORTB_shadow : 3) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB2 at PORTB : 2 var volatile bit pin_B2 at PORTB : 2 -- procedure pin_B2'put(bit in x at _PORTB_shadow : 2) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB1 at PORTB : 1 var volatile bit pin_B1 at PORTB : 1 alias pin_ICSPCLK is pin_B1 -- procedure pin_B1'put(bit in x at _PORTB_shadow : 1) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB0 at PORTB : 0 var volatile bit pin_B0 at PORTB : 0 alias pin_ICSPDAT is pin_B0 -- procedure pin_B0'put(bit in x at _PORTB_shadow : 0) is pragma inline _PORTB_flush() end procedure -- -- ------------------------------------------------ var volatile byte PORTC at { 0x7,0x27,0x47,0x67 } -- var byte _PORTC_shadow = PORTC -- procedure _PORTC_flush() is pragma inline PORTC = _PORTC_shadow end procedure procedure PORTC'put(byte in x) is pragma inline _PORTC_shadow = x _PORTC_flush() end procedure -- procedure PORTC_low'put(byte in x) is pragma inline _PORTC_shadow = (_PORTC_shadow & 0xF0) | (x & 0x0F) _PORTC_flush() end procedure function PORTC_low'get() return byte is pragma inline return (PORTC & 0x0F) end function -- procedure PORTC_high'put(byte in x) is pragma inline _PORTC_shadow = (_PORTC_shadow & 0x0F) | (x << 4) _PORTC_flush() end procedure function PORTC_high'get() return byte is pragma inline return (PORTC >> 4) end function -- var volatile bit PORTC_RC5 at PORTC : 5 var volatile bit pin_C5 at PORTC : 5 alias pin_T0CKI is pin_C5 -- procedure pin_C5'put(bit in x at _PORTC_shadow : 5) is pragma inline _PORTC_flush() end procedure -- var volatile bit PORTC_RC4 at PORTC : 4 var volatile bit pin_C4 at PORTC : 4 -- procedure pin_C4'put(bit in x at _PORTC_shadow : 4) is pragma inline _PORTC_flush() end procedure -- var volatile bit PORTC_RC3 at PORTC : 3 var volatile bit pin_C3 at PORTC : 3 -- procedure pin_C3'put(bit in x at _PORTC_shadow : 3) is pragma inline _PORTC_flush() end procedure -- var volatile bit PORTC_RC2 at PORTC : 2 var volatile bit pin_C2 at PORTC : 2 -- procedure pin_C2'put(bit in x at _PORTC_shadow : 2) is pragma inline _PORTC_flush() end procedure -- var volatile bit PORTC_RC1 at PORTC : 1 var volatile bit pin_C1 at PORTC : 1 -- procedure pin_C1'put(bit in x at _PORTC_shadow : 1) is pragma inline _PORTC_flush() end procedure -- var volatile bit PORTC_RC0 at PORTC : 0 var volatile bit pin_C0 at PORTC : 0 -- procedure pin_C0'put(bit in x at _PORTC_shadow : 0) is pragma inline _PORTC_flush() end procedure -- -- ------------------------------------------------ var byte _TRISB_shadow = 0b1111_1111 -- default all input -- procedure PORTB_direction'put(byte in x) is pragma inline _TRISB_shadow = x asm movf _TRISB_shadow,W asm tris 6 end procedure -- procedure PORTB_low_direction'put(byte in x) is pragma inline _TRISB_shadow = (_TRISB_shadow & 0xF0) | (x & 0x0F) asm movf _TRISB_shadow,W asm tris 6 end procedure -- procedure PORTB_high_direction'put(byte in x) is pragma inline _TRISB_shadow = (_TRISB_shadow & 0x0F) | (x << 4) asm movf _TRISB_shadow,W asm tris 6 end procedure -- procedure pin_B5_direction'put(bit in x at _TRISB_shadow : 5) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure alias pin_OSC1_direction is pin_B5_direction alias pin_CLKIN_direction is pin_B5_direction -- procedure pin_B4_direction'put(bit in x at _TRISB_shadow : 4) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure alias pin_OSC2_direction is pin_B4_direction alias pin_CLKOUT_direction is pin_B4_direction -- procedure pin_B3_direction'put(bit in x at _TRISB_shadow : 3) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure alias pin_MCLR_direction is pin_B3_direction alias pin_VPP_direction is pin_B3_direction -- procedure pin_B2_direction'put(bit in x at _TRISB_shadow : 2) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure -- procedure pin_B1_direction'put(bit in x at _TRISB_shadow : 1) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure alias pin_ICSPCLK_direction is pin_B1_direction -- procedure pin_B0_direction'put(bit in x at _TRISB_shadow : 0) is pragma inline asm movf _TRISB_shadow,W asm tris 6 end procedure alias pin_ICSPDAT_direction is pin_B0_direction -- -- ------------------------------------------------ var byte _TRISC_shadow = 0b1111_1111 -- default all input -- procedure PORTC_direction'put(byte in x) is pragma inline _TRISC_shadow = x asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure PORTC_low_direction'put(byte in x) is pragma inline _TRISC_shadow = (_TRISC_shadow & 0xF0) | (x & 0x0F) asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure PORTC_high_direction'put(byte in x) is pragma inline _TRISC_shadow = (_TRISC_shadow & 0x0F) | (x << 4) asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure pin_C5_direction'put(bit in x at _TRISC_shadow : 5) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure alias pin_T0CKI_direction is pin_C5_direction -- procedure pin_C4_direction'put(bit in x at _TRISC_shadow : 4) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure pin_C3_direction'put(bit in x at _TRISC_shadow : 3) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure pin_C2_direction'put(bit in x at _TRISC_shadow : 2) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure pin_C1_direction'put(bit in x at _TRISC_shadow : 1) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure -- procedure pin_C0_direction'put(bit in x at _TRISC_shadow : 0) is pragma inline asm movf _TRISC_shadow,W asm tris 7 end procedure -- -- ------------------------------------------------ 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 = 0 -- no ADC module present const byte ADC_NTOTAL_CHANNEL = 0 -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Switch analog ports to digital mode (if analog module present). procedure enable_digital_io() is pragma inline OPTION_REG_T0CS = OFF -- T0CKI pin input + output end procedure -- -- ================================================== -- -- Symbolic Fuse definitions -- ------------------------- -- -- CONFIG (0xFFF) -- pragma fuse_def OSC 0x7 { -- oscillator selection bits RC_CLKOUT = 0x7 -- external rc oscillator/clkout function on rb4/osc2/clkout pin RC_NOCLKOUT = 0x6 -- external rc oscillator/rb4 function on rb4/osc2/clkout pin INTOSC_CLKOUT = 0x5 -- internal rc oscillator/clkout function on rb4/osc2/clkout pin INTOSC_NOCLKOUT = 0x4 -- internal rc oscillator/rb4 function on rb4/osc2/clkout pin EC_NOCLKOUT = 0x3 -- ec oscillator/rb4 function on rb4/osc2/clkout pin HS = 0x2 -- hs oscillator XT = 0x1 -- xt oscillator LP = 0x0 -- lp oscillator } pragma fuse_def WDT 0x8 { -- watchdog timer enable bit ENABLED = 0x8 -- enabled DISABLED = 0x0 -- disabled } pragma fuse_def CP 0x10 { -- code protection bit DISABLED = 0x10 -- disabled ENABLED = 0x0 -- enabled } pragma fuse_def MCLR 0x20 { -- rb3/mclr pin function select bit EXTERNAL = 0x20 -- enabled INTERNAL = 0x0 -- disabled } --