-- =================================================== -- Title: JalV2 device include file for PIC 16F627A -- -- 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 pic16f627a, 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/pic16f627a.dev -- - x:/mplab856/MPASM Suite/LKR/16f627a_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 = 0x1040 const byte PICTYPE[] = "16F627A" const byte DATASHEET[] = "40044" const byte PGMSPEC[] = "41196" -- -- Vdd Range: 2.000-6.000 Nominal: 5.000 -- Vpp Range: 12.750-13.250 Default: 13.000 -- -- --------------------------------------------------- -- include chipdef_jallib -- common constants -- pragma target cpu PIC_14 -- (banks=4) pragma target chip 16f627a pragma target bank 0x0080 pragma target page 0x0800 pragma stack 8 pragma code 1024 -- (words) pragma eeprom 0x2100,128 pragma ID 0x2000,4 pragma data 0x20-0x6F,0xA0-0xEF,0x120-0x14F pragma shared 0x70-0x7E,0x7F-0x7F -- var volatile byte _pic_accum shared at 0x7E -- (compiler) var volatile byte _pic_isr_w shared at 0x7F -- (compiler) -- const word _FUSES_CT = 1 const word _FUSE_BASE = 0x2007 const word _FUSES = 0b_0011_1111_1111_1111 -- -- ------------------------------------------------ var volatile byte INDF at { 0x0,0x80,0x100,0x180 } var volatile byte _ind at { 0x0,0x80,0x100,0x180 } -- (compiler) -- ------------------------------------------------ var volatile byte TMR0 at { 0x1,0x101 } -- ------------------------------------------------ var volatile byte PCL at { 0x2,0x82,0x102,0x182 } var volatile byte _pcl at { 0x2,0x82,0x102,0x182 } -- (compiler) -- ------------------------------------------------ var volatile byte STATUS at { 0x3,0x83,0x103,0x183 } var volatile bit STATUS_IRP at STATUS : 7 var volatile bit*2 STATUS_RP 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,0x83,0x103,0x183 } -- (compiler) const byte _irp = 7 -- (compiler) const byte _rp1 = 6 -- (compiler) const byte _rp0 = 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,0x84,0x104,0x184 } var volatile byte _fsr at { 0x4,0x84,0x104,0x184 } -- (compiler) -- ------------------------------------------------ var volatile byte PORTA at { 0x5 } -- 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 PORTA_RA7 at PORTA : 7 var volatile bit pin_A7 at PORTA : 7 alias pin_OSC1 is pin_A7 alias pin_CLKIN is pin_A7 -- procedure pin_A7'put(bit in x at _PORTA_shadow : 7) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA6 at PORTA : 6 var volatile bit pin_A6 at PORTA : 6 alias pin_OSC2 is pin_A6 alias pin_CLKOUT is pin_A6 -- procedure pin_A6'put(bit in x at _PORTA_shadow : 6) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA5 at PORTA : 5 var volatile bit pin_A5 at PORTA : 5 alias pin_MCLR is pin_A5 alias pin_VPP is pin_A5 -- procedure pin_A5'put(bit in x at _PORTA_shadow : 5) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA4 at PORTA : 4 var volatile bit pin_A4 at PORTA : 4 alias pin_T0CKI is pin_A4 alias pin_CMP2 is pin_A4 -- procedure pin_A4'put(bit in x at _PORTA_shadow : 4) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA3 at PORTA : 3 var volatile bit pin_A3 at PORTA : 3 alias pin_AN3 is pin_A3 alias pin_CMP1 is pin_A3 -- procedure pin_A3'put(bit in x at _PORTA_shadow : 3) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA2 at PORTA : 2 var volatile bit pin_A2 at PORTA : 2 alias pin_AN2 is pin_A2 alias pin_VREF is pin_A2 -- procedure pin_A2'put(bit in x at _PORTA_shadow : 2) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA1 at PORTA : 1 var volatile bit pin_A1 at PORTA : 1 alias pin_AN1 is pin_A1 -- procedure pin_A1'put(bit in x at _PORTA_shadow : 1) is pragma inline _PORTA_flush() end procedure -- var volatile bit PORTA_RA0 at PORTA : 0 var volatile bit pin_A0 at PORTA : 0 alias pin_AN0 is pin_A0 -- procedure pin_A0'put(bit in x at _PORTA_shadow : 0) is pragma inline _PORTA_flush() end procedure -- -- ------------------------------------------------ var volatile byte PORTB at { 0x6,0x106 } -- 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_RB7 at PORTB : 7 var volatile bit pin_B7 at PORTB : 7 alias pin_T1OSI is pin_B7 alias pin_PGD is pin_B7 -- procedure pin_B7'put(bit in x at _PORTB_shadow : 7) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB6 at PORTB : 6 var volatile bit pin_B6 at PORTB : 6 alias pin_T1OSO is pin_B6 alias pin_T1CKI is pin_B6 alias pin_PGC is pin_B6 -- procedure pin_B6'put(bit in x at _PORTB_shadow : 6) is pragma inline _PORTB_flush() end procedure -- var volatile bit PORTB_RB5 at PORTB : 5 var volatile bit pin_B5 at PORTB : 5 -- 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_PGM 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_CCP1 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 alias pin_TX is pin_B2 alias pin_CK is pin_B2 -- 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_RX is pin_B1 alias pin_DT 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_INT is pin_B0 -- procedure pin_B0'put(bit in x at _PORTB_shadow : 0) is pragma inline _PORTB_flush() end procedure -- -- ------------------------------------------------ var volatile byte PCLATH at { 0xA,0x8A,0x10A,0x18A } var volatile bit*5 PCLATH_PCLATH at PCLATH : 0 var volatile byte _pclath at { 0xA,0x8A,0x10A,0x18A } -- (compiler) -- ------------------------------------------------ var volatile byte INTCON at { 0xB,0x8B,0x10B,0x18B } var volatile bit INTCON_GIE at INTCON : 7 var volatile bit INTCON_PEIE at INTCON : 6 var volatile bit INTCON_TMR0IE at INTCON : 5 var volatile bit INTCON_INTE at INTCON : 4 var volatile bit INTCON_RBIE at INTCON : 3 var volatile bit INTCON_TMR0IF at INTCON : 2 var volatile bit INTCON_INTF at INTCON : 1 var volatile bit INTCON_RBIF at INTCON : 0 -- ------------------------------------------------ var volatile byte PIR1 at { 0xC } var volatile bit PIR1_EEIF at PIR1 : 7 var volatile bit PIR1_CMIF at PIR1 : 6 var volatile bit PIR1_RCIF at PIR1 : 5 var volatile bit PIR1_TXIF at PIR1 : 4 var volatile bit PIR1_CCP1IF at PIR1 : 2 var volatile bit PIR1_TMR2IF at PIR1 : 1 var volatile bit PIR1_TMR1IF at PIR1 : 0 -- ------------------------------------------------ var volatile word TMR1 at { 0xE } -- ------------------------------------------------ var volatile byte TMR1L at { 0xE } -- ------------------------------------------------ var volatile byte TMR1H at { 0xF } -- ------------------------------------------------ var volatile byte T1CON at { 0x10 } var volatile bit*2 T1CON_T1CKPS at T1CON : 4 var volatile bit T1CON_T1OSCEN at T1CON : 3 var volatile bit T1CON_NT1SYNC at T1CON : 2 var volatile bit T1CON_TMR1CS at T1CON : 1 var volatile bit T1CON_TMR1ON at T1CON : 0 -- ------------------------------------------------ var volatile byte TMR2 at { 0x11 } -- ------------------------------------------------ var volatile byte T2CON at { 0x12 } var volatile bit*4 T2CON_TOUTPS at T2CON : 3 var volatile bit T2CON_TMR2ON at T2CON : 2 var volatile bit*2 T2CON_T2CKPS at T2CON : 0 -- ------------------------------------------------ var volatile word CCPR1 at { 0x15 } -- ------------------------------------------------ var volatile byte CCPR1L at { 0x15 } -- ------------------------------------------------ var volatile byte CCPR1H at { 0x16 } -- ------------------------------------------------ var volatile byte CCP1CON at { 0x17 } var volatile bit*2 CCP1CON_DC1B at CCP1CON : 4 var volatile bit*4 CCP1CON_CCP1M at CCP1CON : 0 -- ------------------------------------------------ var volatile byte RCSTA at { 0x18 } var volatile bit RCSTA_SPEN at RCSTA : 7 var volatile bit RCSTA_RX9 at RCSTA : 6 var volatile bit RCSTA_SREN at RCSTA : 5 var volatile bit RCSTA_CREN at RCSTA : 4 var volatile bit RCSTA_ADDEN at RCSTA : 3 var volatile bit RCSTA_FERR at RCSTA : 2 var volatile bit RCSTA_OERR at RCSTA : 1 var volatile bit RCSTA_RX9D at RCSTA : 0 -- ------------------------------------------------ var volatile byte TXREG at { 0x19 } -- ------------------------------------------------ var volatile byte RCREG at { 0x1A } -- ------------------------------------------------ var volatile byte CMCON at { 0x1F } var volatile bit CMCON_C2OUT at CMCON : 7 var volatile bit CMCON_C1OUT at CMCON : 6 var volatile bit CMCON_C2INV at CMCON : 5 var volatile bit CMCON_C1INV at CMCON : 4 var volatile bit CMCON_CIS at CMCON : 3 var volatile bit*3 CMCON_CM at CMCON : 0 -- ------------------------------------------------ var volatile byte OPTION_REG at { 0x81,0x181 } var volatile bit OPTION_REG_NRBPU at OPTION_REG : 7 var volatile bit OPTION_REG_INTEDG at OPTION_REG : 6 var volatile bit OPTION_REG_T0CS at OPTION_REG : 5 alias T0CON_T0CS is OPTION_REG_T0CS var volatile bit OPTION_REG_T0SE at OPTION_REG : 4 alias T0CON_T0SE is OPTION_REG_T0SE var volatile bit OPTION_REG_PSA at OPTION_REG : 3 alias T0CON_PSA is OPTION_REG_PSA var volatile bit*3 OPTION_REG_PS at OPTION_REG : 0 alias T0CON_T0PS is OPTION_REG_PS -- ------------------------------------------------ var volatile byte TRISA at { 0x85 } var volatile byte PORTA_direction at TRISA -- procedure PORTA_low_direction'put(byte in x) is pragma inline TRISA = (TRISA & 0xF0) | (x & 0x0F) end procedure function PORTA_low_direction'get() return byte is pragma inline return (TRISA & 0x0F) end function -- procedure PORTA_high_direction'put(byte in x) is pragma inline TRISA = (TRISA & 0x0F) | (x << 4) end procedure function PORTA_high_direction'get() return byte is pragma inline return (TRISA >> 4) end function -- var volatile bit TRISA_TRISA7 at TRISA : 7 var volatile bit pin_A7_direction at TRISA : 7 alias pin_OSC1_direction is pin_A7_direction alias pin_CLKIN_direction is pin_A7_direction -- var volatile bit TRISA_TRISA6 at TRISA : 6 var volatile bit pin_A6_direction at TRISA : 6 alias pin_OSC2_direction is pin_A6_direction alias pin_CLKOUT_direction is pin_A6_direction -- var volatile bit TRISA_TRISA5 at TRISA : 5 var volatile bit pin_A5_direction at TRISA : 5 alias pin_MCLR_direction is pin_A5_direction alias pin_VPP_direction is pin_A5_direction -- var volatile bit TRISA_TRISA4 at TRISA : 4 var volatile bit pin_A4_direction at TRISA : 4 alias pin_T0CKI_direction is pin_A4_direction alias pin_CMP2_direction is pin_A4_direction -- var volatile bit TRISA_TRISA3 at TRISA : 3 var volatile bit pin_A3_direction at TRISA : 3 alias pin_AN3_direction is pin_A3_direction alias pin_CMP1_direction is pin_A3_direction -- var volatile bit TRISA_TRISA2 at TRISA : 2 var volatile bit pin_A2_direction at TRISA : 2 alias pin_AN2_direction is pin_A2_direction alias pin_VREF_direction is pin_A2_direction -- var volatile bit TRISA_TRISA1 at TRISA : 1 var volatile bit pin_A1_direction at TRISA : 1 alias pin_AN1_direction is pin_A1_direction -- var volatile bit TRISA_TRISA0 at TRISA : 0 var volatile bit pin_A0_direction at TRISA : 0 alias pin_AN0_direction is pin_A0_direction -- -- ------------------------------------------------ var volatile byte TRISB at { 0x86,0x186 } var volatile byte PORTB_direction at TRISB -- procedure PORTB_low_direction'put(byte in x) is pragma inline TRISB = (TRISB & 0xF0) | (x & 0x0F) end procedure function PORTB_low_direction'get() return byte is pragma inline return (TRISB & 0x0F) end function -- procedure PORTB_high_direction'put(byte in x) is pragma inline TRISB = (TRISB & 0x0F) | (x << 4) end procedure function PORTB_high_direction'get() return byte is pragma inline return (TRISB >> 4) end function -- var volatile bit TRISB_TRISB7 at TRISB : 7 var volatile bit pin_B7_direction at TRISB : 7 alias pin_T1OSI_direction is pin_B7_direction alias pin_PGD_direction is pin_B7_direction -- var volatile bit TRISB_TRISB6 at TRISB : 6 var volatile bit pin_B6_direction at TRISB : 6 alias pin_T1OSO_direction is pin_B6_direction alias pin_T1CKI_direction is pin_B6_direction alias pin_PGC_direction is pin_B6_direction -- var volatile bit TRISB_TRISB5 at TRISB : 5 var volatile bit pin_B5_direction at TRISB : 5 -- var volatile bit TRISB_TRISB4 at TRISB : 4 var volatile bit pin_B4_direction at TRISB : 4 alias pin_PGM_direction is pin_B4_direction -- var volatile bit TRISB_TRISB3 at TRISB : 3 var volatile bit pin_B3_direction at TRISB : 3 alias pin_CCP1_direction is pin_B3_direction -- var volatile bit TRISB_TRISB2 at TRISB : 2 var volatile bit pin_B2_direction at TRISB : 2 alias pin_TX_direction is pin_B2_direction alias pin_CK_direction is pin_B2_direction -- var volatile bit TRISB_TRISB1 at TRISB : 1 var volatile bit pin_B1_direction at TRISB : 1 alias pin_RX_direction is pin_B1_direction alias pin_DT_direction is pin_B1_direction -- var volatile bit TRISB_TRISB0 at TRISB : 0 var volatile bit pin_B0_direction at TRISB : 0 alias pin_INT_direction is pin_B0_direction -- -- ------------------------------------------------ var volatile byte PIE1 at { 0x8C } var volatile bit PIE1_EEIE at PIE1 : 7 var volatile bit PIE1_CMIE at PIE1 : 6 var volatile bit PIE1_RCIE at PIE1 : 5 var volatile bit PIE1_TXIE at PIE1 : 4 var volatile bit PIE1_CCP1IE at PIE1 : 2 var volatile bit PIE1_TMR2IE at PIE1 : 1 var volatile bit PIE1_TMR1IE at PIE1 : 0 -- ------------------------------------------------ var volatile byte PCON at { 0x8E } var volatile bit PCON_OSCF at PCON : 3 var volatile bit PCON_NPOR at PCON : 1 var volatile bit PCON_NBOR at PCON : 0 -- ------------------------------------------------ var volatile byte PR2 at { 0x92 } -- ------------------------------------------------ var volatile byte TXSTA at { 0x98 } var volatile bit TXSTA_CSRC at TXSTA : 7 var volatile bit TXSTA_TX9 at TXSTA : 6 var volatile bit TXSTA_TXEN at TXSTA : 5 var volatile bit TXSTA_SYNC at TXSTA : 4 var volatile bit TXSTA_BRGH at TXSTA : 2 var volatile bit TXSTA_TRMT at TXSTA : 1 var volatile bit TXSTA_TX9D at TXSTA : 0 -- ------------------------------------------------ var volatile byte SPBRG at { 0x99 } -- ------------------------------------------------ var volatile byte EEDATA at { 0x9A } -- ------------------------------------------------ var volatile byte EEADR at { 0x9B } -- ------------------------------------------------ var volatile byte EECON1 at { 0x9C } var volatile bit EECON1_WRERR at EECON1 : 3 var volatile bit EECON1_WREN at EECON1 : 2 var volatile bit EECON1_WR at EECON1 : 1 var volatile bit EECON1_RD at EECON1 : 0 -- ------------------------------------------------ var volatile byte EECON2 at { 0x9D } -- ------------------------------------------------ var volatile byte VRCON at { 0x9F } var volatile bit VRCON_VREN at VRCON : 7 var volatile bit VRCON_VROE at VRCON : 6 var volatile bit VRCON_VRR at VRCON : 5 var volatile bit*4 VRCON_VR at VRCON : 0 -- -- =================================================== -- -- Special (device specific) constants and procedures -- const ADC_GROUP = 0 -- no ADC module present const byte ADC_NTOTAL_CHANNEL = 0 -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Disable comparator module procedure comparator_off() is pragma inline CMCON = 0b0000_0111 -- disable comparator end procedure -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - -- Switch analog ports to digital mode (if analog module present). procedure enable_digital_io() is pragma inline comparator_off() end procedure -- -- ================================================== -- -- Symbolic Fuse definitions -- ------------------------- -- -- CONFIG (0x2007) -- pragma fuse_def OSC 0x13 { -- oscillator RC_CLKOUT = 0x13 -- rc: clkout on ra6/osc2/clkout, rc on ra7/osc1/clkin RC_NOCLKOUT = 0x12 -- rc: i/o on ra6/osc2/clkout, rc on ra7/osc1/clkin INTOSC_CLKOUT = 0x11 -- intosc: clkout on ra6/osc2/clkout, i/o on ra7/osc1/clkin INTOSC_NOCLKOUT = 0x10 -- intosc: i/o on ra6/osc2/clkout, i/o on ra7/osc1/clkin EC_NOCLKOUT = 0x3 -- ec HS = 0x2 -- hs XT = 0x1 -- xt LP = 0x0 -- lp } pragma fuse_def WDT 0x4 { -- watchdog timer ENABLED = 0x4 -- on DISABLED = 0x0 -- off } pragma fuse_def PWRTE 0x8 { -- power up timer DISABLED = 0x8 -- disabled ENABLED = 0x0 -- enabled } pragma fuse_def MCLR 0x20 { -- master clear enable EXTERNAL = 0x20 -- enabled INTERNAL = 0x0 -- disabled } pragma fuse_def BROWNOUT 0x40 { -- brown out detect ENABLED = 0x40 -- enabled DISABLED = 0x0 -- disabled } pragma fuse_def LVP 0x80 { -- low voltage program ENABLED = 0x80 -- enabled DISABLED = 0x0 -- disabled } pragma fuse_def CPD 0x100 { -- data ee read protect DISABLED = 0x100 -- disabled ENABLED = 0x0 -- enabled } pragma fuse_def CP 0x2000 { -- code protect DISABLED = 0x2000 -- off ENABLED = 0x0 -- on } --