18F14K50 works with Swordfish, as HID USB device

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
RKP
Registered User
Registered User
Posts: 82
Joined: Mon Oct 22, 2007 3:14 pm
Location: Maryland

18F14K50 works with Swordfish, as HID USB device

Post by RKP » Mon Apr 19, 2010 5:46 pm

Here are the changes that I made to get the PIC18F13K50 and 14K50 family of PIC's to function as HID devices on your PC.

This going to be a rather long post so if anyone would like to make Wiki out of this I would greatly appreciate it as I could not wiki it myself. This is of course, after some users could verify that it also works for them.

The first thing you need to do is update your MPASMWIN.exe as the current version that comes with Swordfish is way out of date and does not support these devices. Download the lateset MPLAB from Microchip and copy the MPASMWIN.exe to the Swordfish\Bin directory. I am currently using V5.34 that came with MPLAB 8.4

Now for the changes to the Swordfish files that will allow it to compile for these family of parts. The changes need to be in the following files.
18F13K50.bas, 18F14K50.bas, P18F13K50.inc and P18F14K50.inc. These files are all located in this directory Swordfish\Includes . Here are the changes:
18F13K50.bas

Code: Select all

{
****************************************************************
*  Name    : 18F13K50                                          *
*  Author  : David John Barker                                 *
*  Notice  : Copyright (c) 2008 Mecanique                      *
*          : All Rights Reserved                               *
*  Date    : 03/03/2008                                        *
*  Version : Modified, alot changes (RKP)                      *                                  
****************************************************************
}

Module SystemTypes

// system header...
#const _core = $0012                   // processor core
#const _ram_banks = $03                // 3 RAM bank(s) used
#variable _maxaccess = $60             // access ram is 96 bytes
#variable _maxram = $0200              // 512 bytes of user RAM
#variable _maxram_contig = $0100       // 256 bytes of contiguous RAM   *** Not sure if this is needed ***
#variable _maxrom = $002000            // 8 KB of program ROM
#const _eeprom = $0100                 // 256 bytes of EEPROM
#const _eeprom_start = $F00000         // EEPROM start address
#const _ports = $03                    // 3 available ports
#const _ccp = $00                      // CCP module NOT supported
#const _eccp = $01                     // 1 ECCP module(s) available
#const _mssp = $01                     // 1 MSSP module(s) available
#const _usart = $01                    // 1 USART(s) available
#const _adc = $09                      // 9 ADC channels available
#const _adres = $0A                    // 10 bit ADC resolution
#const _comparator = $02               // 2 comparator(s) available
#const _psp = $00                      // Parallel Slave Port (PSP) is NOT supported
#const _can = $00                      // onboard CAN is NOT supported
#const _usb = $01                      // USB is NOT supported       *** $00 or $01 Does not matter ***
#const _ethernet = $00                 // onboard Ethernet is NOT supported
#const _flash_write = $01              // FLASH has write capability

// special function registers...
Public System
   UEP0 As Byte Absolute $0F53,
   UEP1 As Byte Absolute $0F54,
   UEP2 As Byte Absolute $0F55,
   UEP3 As Byte Absolute $0F56,
   UEP4 As Byte Absolute $0F57,
   UEP5 As Byte Absolute $0F58,
   UEP6 As Byte Absolute $0F59,
   UEP7 As Byte Absolute $0F5A,
   UEIE As Byte Absolute $0F5B,
   UADDR As Byte Absolute $0F5C,
   UFRML As Byte Absolute $0F5D,
   UFRMH As Byte Absolute $0F5E,
   UEIR As Byte Absolute $0F5F,
   UIE As Byte Absolute $0F60,
   UCFG As Byte Absolute $0F61,        '**** Changed made here ****
   UIR As Byte Absolute $0F62,
   USTAT As Byte Absolute $0F63,
   UCON As Byte Absolute $0F64,        '**** Changed made here ****
   TSTOUT As Byte Absolute $0F65,
   SRCON0 As Byte Absolute $0F68,
   SRCON1 As Byte Absolute $0F69,
   CM2CON0 As Byte Absolute $0F6B,
   CM2CON1 As Byte Absolute $0F6C,
   CM1CON0 As Byte Absolute $0F6D,
   SSPMASK As Byte Absolute $0F6F,
   SLRCON As Byte Absolute $0F76,
   WPUA As Byte Absolute $0F77,
   WPUB As Byte Absolute $0F78,
   IOCA As Byte Absolute $0F79,
   IOCB As Byte Absolute $0F7A,
   ANSEL As Byte Absolute $0F7E,
   ANSELH As Byte Absolute $0F7F,
   LATA As Byte Absolute $0F89,
   LATB As Byte Absolute $0F8A,
   LATC As Byte Absolute $0F8B,
   DDRA As Byte Absolute $0F92,
   TRISA As Byte Absolute $0F92,
   DDRB As Byte Absolute $0F93,
   TRISB As Byte Absolute $0F93,
   DDRC As Byte Absolute $0F94,
   TRISC As Byte Absolute $0F94,
   OSCTUNE As Byte Absolute $0F9B,
   PIE1 As Byte Absolute $0F9D,
   PIR1 As Byte Absolute $0F9E,
   IPR1 As Byte Absolute $0F9F,
   PIE2 As Byte Absolute $0FA0,
   PIR2 As Byte Absolute $0FA1,
   IPR2 As Byte Absolute $0FA2,
   EECON1 As Byte Absolute $0FA6,
   EECON2 As Byte Absolute $0FA7,
   EEDATA As Byte Absolute $0FA8,
   EEADR As Byte Absolute $0FA9,
   RCSTA As Byte Absolute $0FAB,
   TXSTA As Byte Absolute $0FAC,
   TXREG As Byte Absolute $0FAD,
   RCREG As Byte Absolute $0FAE,
   SPBRG As Byte Absolute $0FAF,
   SPBRGH As Byte Absolute $0FB0,
   T3CON As Byte Absolute $0FB1,
   TMR3L As Byte Absolute $0FB2,
   TMR3H As Byte Absolute $0FB3,
   ECCP1AS As Byte Absolute $0FB6,
   PWM1CON As Byte Absolute $0FB7,
   BAUDCTL As Byte Absolute $0FB8,
   PSTRCON As Byte Absolute $0FB9,
   REFCON0 As Byte Absolute $0FBA,
   REFCON1 As Byte Absolute $0FBB,
   REFCON2 As Byte Absolute $0FBC,
   CCP1CON As Byte Absolute $0FBD,
   CCPR1 As Byte Absolute $0FBE,
   CCPR1L As Byte Absolute $0FBE,
   CCPR1H As Byte Absolute $0FBF,
   ADCON2 As Byte Absolute $0FC0,
   ADCON1 As Byte Absolute $0FC1,
   ADCON0 As Byte Absolute $0FC2,
   ADRES As Byte Absolute $0FC3,
   ADRESL As Byte Absolute $0FC3,
   ADRESH As Byte Absolute $0FC4,
   SSPCON2 As Byte Absolute $0FC5,
   SSPCON1 As Byte Absolute $0FC6,
   SSPSTAT As Byte Absolute $0FC7,
   SSPADD As Byte Absolute $0FC8,
   SSPBUF As Byte Absolute $0FC9,
   T2CON As Byte Absolute $0FCA,
   PR2 As Byte Absolute $0FCB,
   TMR2 As Byte Absolute $0FCC,
   T1CON As Byte Absolute $0FCD,
   TMR1L As Byte Absolute $0FCE,
   TMR1H As Byte Absolute $0FCF,
   RCON As Byte Absolute $0FD0,
   WDTCON As Byte Absolute $0FD1,
   OSCCON2 As Byte Absolute $0FD2,
   OSCCON As Byte Absolute $0FD3,
   T0CON As Byte Absolute $0FD5,
   TMR0L As Byte Absolute $0FD6,
   TMR0H As Byte Absolute $0FD7,
   STATUS As Byte Absolute $0FD8,
   FSR2L As Byte Absolute $0FD9,
   FSR2H As Byte Absolute $0FDA,
   PLUSW2 As Byte Absolute $0FDB,
   PREINC2 As Byte Absolute $0FDC,
   POSTDEC2 As Byte Absolute $0FDD,
   POSTINC2 As Byte Absolute $0FDE,
   INDF2 As Byte Absolute $0FDF,
   BSR As Byte Absolute $0FE0,
   FSR1L As Byte Absolute $0FE1,
   FSR1H As Byte Absolute $0FE2,
   PLUSW1 As Byte Absolute $0FE3,
   PREINC1 As Byte Absolute $0FE4,
   POSTDEC1 As Byte Absolute $0FE5,
   POSTINC1 As Byte Absolute $0FE6,
   INDF1 As Byte Absolute $0FE7,
   WREG As Byte Absolute $0FE8,
   FSR0L As Byte Absolute $0FE9,
   FSR0H As Byte Absolute $0FEA,
   PLUSW0 As Byte Absolute $0FEB,
   PREINC0 As Byte Absolute $0FEC,
   POSTDEC0 As Byte Absolute $0FED,
   POSTINC0 As Byte Absolute $0FEE,
   INDF0 As Byte Absolute $0FEF,
   INTCON3 As Byte Absolute $0FF0,
   INTCON2 As Byte Absolute $0FF1,
   INTCON As Byte Absolute $0FF2,
   PROD As Byte Absolute $0FF3,
   PRODL As Byte Absolute $0FF3,
   PRODH As Byte Absolute $0FF4,
   TABLAT As Byte Absolute $0FF5,
   TBLPTR As Byte Absolute $0FF6,
   TBLPTRL As Byte Absolute $0FF6,
   TBLPTRH As Byte Absolute $0FF7,
   TBLPTRU As Byte Absolute $0FF8,
   PC As Byte Absolute $0FF9,
   PCL As Byte Absolute $0FF9,
   PCLATH As Byte Absolute $0FFA,
   PCLATU As Byte Absolute $0FFB,
   STKPTR As Byte Absolute $0FFC,
   TOS As Byte Absolute $0FFD,
   TOSL As Byte Absolute $0FFD,
   TOSH As Byte Absolute $0FFE,
   TOSU As Byte Absolute $0FFF

// system ports...
Public System Port
   PORTC As Byte Absolute $0F82,
   PORTB As Byte Absolute $0F81,
   PORTA As Byte Absolute $0F80

// alias...
Public Dim
   FSR0 As FSR0L.AsWord,
   FSR1 As FSR1L.AsWord,
   FSR2 As FSR2L.AsWord,
   TABLEPTR As TBLPTRL.AsWord


// configuration fuses...   **** Alot of the Config Names are changed to match Microchip newer MPASM ****
Public Config
   CPUDIV(CPUDIV) = [NOCLKDIV, CLKDIV2, CLKDIV3, CLKDIV4],
   USBDIV(USBDIV) = [OFF, ON],
   FOSC(FOSC) = [LP, XT, HS, ERCCLKOUT, ECCLKOUTH, ECH, ERC, IRC, IRCCLKOUT, ECCLKOUTM, ECM, ECCLKOUTL, ECL],
   PLLEN(PLLEN) = [OFF, ON],
   PCLKEN(PCLKEN) = [OFF, ON],
   FCMEN(FCMEN) = [OFF, ON],
   IESO(IESO) = [OFF, ON],
   PWRTEN(PWRTEN) = [ON, OFF],
   BOREN(BOREN) = [OFF, ON, NOSLP, SBORDIS],
   BORV(BORV) = [30, 27, 22, 19],
'   VREGEN(VREGEN) = [OFF, ON],
   BORPWR(BORPWR) = [OFF, ON],
   WDTEN(WDTEN) = [OFF, ON],
   WDTPS(WDTPS) = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],
   MCLRE(MCLRE) = [OFF, ON],
   HFOFST(HFOFST) = [OFF, ON],
   STVREN(STVREN) = [OFF, ON],
   LVP(LVP) = [OFF, ON],
   BBSIZ(BBSIZ) = [OFF, ON],
   XINST(XINST) = [OFF, ON],
'   BKBUG(BKBUG) = [ON, OFF],
   CP0(CP0) = [ON, OFF],
   CP1(CP1) = [ON, OFF],
   CPB(CPB) = [ON, OFF],
   CPD(CPD) = [ON, OFF],
   WRT0(WRT0) = [ON, OFF],
   WRT1(WRT1) = [ON, OFF],
   WRTB(WRTB) = [ON, OFF],
   WRTC(WRTC) = [ON, OFF],
   WRTD(WRTD) = [ON, OFF],
   EBTR0(EBTR0) = [ON, OFF],
   EBTR1(EBTR1) = [ON, OFF],
   EBTRB(EBTRB) = [ON, OFF]

// default fuses...
Config
   FOSC = HS,
   FCMEN = OFF,
   IESO = OFF,
   PWRTEN = ON,
   BOREN = ON,
   BORV = 27,
   WDTEN = OFF,
   WDTPS = 128,
   STVREN = ON,
   LVP = OFF,
   XINST = OFF
18F14K50.bas

Code: Select all

{
****************************************************************
*  Name    : 18F14K50                                          *
*  Author  : David John Barker                                 *
*  Notice  : Copyright (c) 2008 Mecanique                      *
*          : All Rights Reserved                               *
*  Date    : 03/03/2008                                        *
*  Version : Modified, alot changes (RKP)                      *
****************************************************************
}

Module SystemTypes

// system header...
#const _core = $0012                   // processor core
#const _ram_banks = $03                // 3 RAM bank(s) used
#variable _maxaccess = $60             // access ram is 96 bytes
#variable _maxram = $0300              // 768 bytes of user RAM
#variable _maxram_contig = $0300       // 768 bytes of contiguous RAM   *** Not sure if this is needed ***
#variable _maxrom = $004000            // 16 KB of program ROM
#const _eeprom = $0100                 // 256 bytes of EEPROM
#const _eeprom_start = $F00000         // EEPROM start address
#const _ports = $03                    // 3 available ports
#const _ccp = $00                      // CCP module NOT supported
#const _eccp = $01                     // 1 ECCP module(s) available
#const _mssp = $01                     // 1 MSSP module(s) available
#const _usart = $01                    // 1 USART(s) available
#const _adc = $09                      // 9 ADC channels available
#const _adres = $0A                    // 10 bit ADC resolution
#const _comparator = $02               // 2 comparator(s) available
#const _psp = $00                      // Parallel Slave Port (PSP) is NOT supported
#const _can = $00                      // onboard CAN is NOT supported
#const _usb = $01                      // USB is NOT supported         *** $00 or $01 Does not matter ***
#const _ethernet = $00                 // onboard Ethernet is NOT supported
#const _flash_write = $01              // FLASH has write capability

// special function registers...
Public System
   UEP0 As Byte Absolute $0F53,
   UEP1 As Byte Absolute $0F54,
   UEP2 As Byte Absolute $0F55,
   UEP3 As Byte Absolute $0F56,
   UEP4 As Byte Absolute $0F57,
   UEP5 As Byte Absolute $0F58,
   UEP6 As Byte Absolute $0F59,
   UEP7 As Byte Absolute $0F5A,
   UEIE As Byte Absolute $0F5B,
   UADDR As Byte Absolute $0F5C,
   UFRML As Byte Absolute $0F5D,
   UFRMH As Byte Absolute $0F5E,
   UEIR As Byte Absolute $0F5F,
   UIE As Byte Absolute $0F60,   
   UCFG As Byte Absolute $0F61,        '**** Changed made here ****
   UIR As Byte Absolute $0F62,
   USTAT As Byte Absolute $0F63,   
   UCON As Byte Absolute $0F64,        '**** Changed made here ****
   TSTOUT As Byte Absolute $0F65,
   SRCON0 As Byte Absolute $0F68,
   SRCON1 As Byte Absolute $0F69,
   CM2CON0 As Byte Absolute $0F6B,
   CM2CON1 As Byte Absolute $0F6C,
   CM1CON0 As Byte Absolute $0F6D,
   SSPMASK As Byte Absolute $0F6F,
   SLRCON As Byte Absolute $0F76,
   WPUA As Byte Absolute $0F77,
   WPUB As Byte Absolute $0F78,
   IOCA As Byte Absolute $0F79,
   IOCB As Byte Absolute $0F7A,
   ANSEL As Byte Absolute $0F7E,
   ANSELH As Byte Absolute $0F7F,
   LATA As Byte Absolute $0F89,
   LATB As Byte Absolute $0F8A,
   LATC As Byte Absolute $0F8B,
   DDRA As Byte Absolute $0F92,
   TRISA As Byte Absolute $0F92,
   DDRB As Byte Absolute $0F93,
   TRISB As Byte Absolute $0F93,
   DDRC As Byte Absolute $0F94,
   TRISC As Byte Absolute $0F94,
   OSCTUNE As Byte Absolute $0F9B,
   PIE1 As Byte Absolute $0F9D,
   PIR1 As Byte Absolute $0F9E,
   IPR1 As Byte Absolute $0F9F,
   PIE2 As Byte Absolute $0FA0,
   PIR2 As Byte Absolute $0FA1,
   IPR2 As Byte Absolute $0FA2,
   EECON1 As Byte Absolute $0FA6,
   EECON2 As Byte Absolute $0FA7,
   EEDATA As Byte Absolute $0FA8,
   EEADR As Byte Absolute $0FA9,
   RCSTA As Byte Absolute $0FAB,
   TXSTA As Byte Absolute $0FAC,
   TXREG As Byte Absolute $0FAD,
   RCREG As Byte Absolute $0FAE,
   SPBRG As Byte Absolute $0FAF,
   SPBRGH As Byte Absolute $0FB0,
   T3CON As Byte Absolute $0FB1,
   TMR3L As Byte Absolute $0FB2,
   TMR3H As Byte Absolute $0FB3,
   ECCP1AS As Byte Absolute $0FB6,
   PWM1CON As Byte Absolute $0FB7,
   BAUDCTL As Byte Absolute $0FB8,
   PSTRCON As Byte Absolute $0FB9,
   REFCON0 As Byte Absolute $0FBA,
   REFCON1 As Byte Absolute $0FBB,
   REFCON2 As Byte Absolute $0FBC,
   CCP1CON As Byte Absolute $0FBD,
   CCPR1 As Byte Absolute $0FBE,
   CCPR1L As Byte Absolute $0FBE,
   CCPR1H As Byte Absolute $0FBF,
   ADCON2 As Byte Absolute $0FC0,
   ADCON1 As Byte Absolute $0FC1,
   ADCON0 As Byte Absolute $0FC2,
   ADRES As Byte Absolute $0FC3,
   ADRESL As Byte Absolute $0FC3,
   ADRESH As Byte Absolute $0FC4,
   SSPCON2 As Byte Absolute $0FC5,
   SSPCON1 As Byte Absolute $0FC6,
   SSPSTAT As Byte Absolute $0FC7,
   SSPADD As Byte Absolute $0FC8,
   SSPBUF As Byte Absolute $0FC9,
   T2CON As Byte Absolute $0FCA,
   PR2 As Byte Absolute $0FCB,
   TMR2 As Byte Absolute $0FCC,
   T1CON As Byte Absolute $0FCD,
   TMR1L As Byte Absolute $0FCE,
   TMR1H As Byte Absolute $0FCF,
   RCON As Byte Absolute $0FD0,
   WDTCON As Byte Absolute $0FD1,
   OSCCON2 As Byte Absolute $0FD2,
   OSCCON As Byte Absolute $0FD3,
   T0CON As Byte Absolute $0FD5,
   TMR0L As Byte Absolute $0FD6,
   TMR0H As Byte Absolute $0FD7,
   STATUS As Byte Absolute $0FD8,
   FSR2L As Byte Absolute $0FD9,
   FSR2H As Byte Absolute $0FDA,
   PLUSW2 As Byte Absolute $0FDB,
   PREINC2 As Byte Absolute $0FDC,
   POSTDEC2 As Byte Absolute $0FDD,
   POSTINC2 As Byte Absolute $0FDE,
   INDF2 As Byte Absolute $0FDF,
   BSR As Byte Absolute $0FE0,
   FSR1L As Byte Absolute $0FE1,
   FSR1H As Byte Absolute $0FE2,
   PLUSW1 As Byte Absolute $0FE3,
   PREINC1 As Byte Absolute $0FE4,
   POSTDEC1 As Byte Absolute $0FE5,
   POSTINC1 As Byte Absolute $0FE6,
   INDF1 As Byte Absolute $0FE7,
   WREG As Byte Absolute $0FE8,
   FSR0L As Byte Absolute $0FE9,
   FSR0H As Byte Absolute $0FEA,
   PLUSW0 As Byte Absolute $0FEB,
   PREINC0 As Byte Absolute $0FEC,
   POSTDEC0 As Byte Absolute $0FED,
   POSTINC0 As Byte Absolute $0FEE,
   INDF0 As Byte Absolute $0FEF,
   INTCON3 As Byte Absolute $0FF0,
   INTCON2 As Byte Absolute $0FF1,
   INTCON As Byte Absolute $0FF2,
   PROD As Byte Absolute $0FF3,
   PRODL As Byte Absolute $0FF3,
   PRODH As Byte Absolute $0FF4,
   TABLAT As Byte Absolute $0FF5,
   TBLPTR As Byte Absolute $0FF6,
   TBLPTRL As Byte Absolute $0FF6,
   TBLPTRH As Byte Absolute $0FF7,
   TBLPTRU As Byte Absolute $0FF8,
   PC As Byte Absolute $0FF9,
   PCL As Byte Absolute $0FF9,
   PCLATH As Byte Absolute $0FFA,
   PCLATU As Byte Absolute $0FFB,
   STKPTR As Byte Absolute $0FFC,
   TOS As Byte Absolute $0FFD,
   TOSL As Byte Absolute $0FFD,
   TOSH As Byte Absolute $0FFE,
   TOSU As Byte Absolute $0FFF

// system ports...
Public System Port
   PORTC As Byte Absolute $0F82,
   PORTB As Byte Absolute $0F81,
   PORTA As Byte Absolute $0F80

// alias...
Public Dim
   FSR0 As FSR0L.AsWord,
   FSR1 As FSR1L.AsWord,
   FSR2 As FSR2L.AsWord,
   TABLEPTR As TBLPTRL.AsWord

// configuration fuses...   **** Alot of the Config Names are changed to match Microchip newer MPASM ****
Public Config
   CPUDIV(CPUDIV) = [NOCLKDIV, CLKDIV2, CLKDIV3, CLKDIV4],
   USBDIV(USBDIV) = [OFF, ON],
   FOSC(FOSC) = [LP, XT, HS, ERCCLKOUT, ECCLKOUTH, ECH, ERC, IRC, IRCCLKOUT, ECCLKOUTM, ECM, ECCLKOUTL, ECL],
   PLLEN(PLLEN) = [OFF, ON],
   PCLKEN(PCLKEN) = [OFF, ON],
   FCMEN(FCMEN) = [OFF, ON],
   IESO(IESO) = [OFF, ON],
   PWRTEN(PWRTEN) = [ON, OFF],
   BOREN(BOREN) = [OFF, ON, NOSLP, SBORDIS],
   BORV(BORV) = [30, 27, 22, 19],
'   VREGEN(VREGEN) = [OFF, ON],
   BORPWR(BORPWR) = [OFF, ON],
   WDTEN(WDTEN) = [OFF, ON],
   WDTPS(WDTPS) = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],
   MCLRE(MCLRE) = [OFF, ON],
   HFOFST(HFOFST) = [OFF, ON],
   STVREN(STVREN) = [OFF, ON],
   LVP(LVP) = [OFF, ON],
   BBSIZ(BBSIZ) = [OFF, ON],
   XINST(XINST) = [OFF, ON],
'   BKBUG(BKBUG) = [ON, OFF],
   CP0(CP0) = [ON, OFF],
   CP1(CP1) = [ON, OFF],
   CPB(CPB) = [ON, OFF],
   CPD(CPD) = [ON, OFF],
   WRT0(WRT0) = [ON, OFF],
   WRT1(WRT1) = [ON, OFF],
   WRTB(WRTB) = [ON, OFF],
   WRTC(WRTC) = [ON, OFF],
   WRTD(WRTD) = [ON, OFF],
   EBTR0(EBTR0) = [ON, OFF],
   EBTR1(EBTR1) = [ON, OFF],
   EBTRB(EBTRB) = [ON, OFF]

// default fuses...
Config
   FOSC = HS,
   FCMEN = OFF,
   IESO = OFF,
   PWRTEN = ON,
   BOREN = ON,
   BORV = 27,
   WDTEN = OFF,
   WDTPS = 128,
   STVREN = ON,
   LVP = OFF,
   XINST = OFF
P18F13K50.inc[

Code: Select all

NOLIST
; *******************************************
; * ASM Definition file for Swordfish BASIC *
; * Modified (RKP)                          *
; *******************************************
LIST

; special function registers...
UEP0             EQU 0x0F53
UEP1             EQU 0x0F54
UEP2             EQU 0x0F55
UEP3             EQU 0x0F56
UEP4             EQU 0x0F57
UEP5             EQU 0x0F58
UEP6             EQU 0x0F59
UEP7             EQU 0x0F5A
UEIE             EQU 0x0F5B
UADDR            EQU 0x0F5C
UFRML            EQU 0x0F5D
UFRMLH           EQU 0x0F5E
UFRMH            EQU 0x0F5E
UEIR             EQU 0x0F5F
UIE              EQU 0x0F60
UCFG             EQU 0x0F61
UIR              EQU 0x0F62
USTAT            EQU 0x0F63
UCON             EQU 0x0F64
TSTOUT           EQU 0x0F65
SRCON0           EQU 0x0F68
SRCON1           EQU 0x0F69
CM2CON0          EQU 0x0F6B
CM2CON1          EQU 0x0F6C
CM1CON0          EQU 0x0F6D
SSPMASK          EQU 0x0F6F
SLRCON           EQU 0x0F76
WPUA             EQU 0x0F77
WPUB             EQU 0x0F78
IOCA             EQU 0x0F79
IOCB             EQU 0x0F7A
ANSEL            EQU 0x0F7E
ANSELH           EQU 0x0F7F
LATA             EQU 0x0F89
LATB             EQU 0x0F8A
LATC             EQU 0x0F8B
DDRA             EQU 0x0F92
TRISA            EQU 0x0F92
DDRB             EQU 0x0F93
TRISB            EQU 0x0F93
DDRC             EQU 0x0F94
TRISC            EQU 0x0F94
OSCTUNE          EQU 0x0F9B
PIE1             EQU 0x0F9D
PIR1             EQU 0x0F9E
IPR1             EQU 0x0F9F
PIE2             EQU 0x0FA0
PIR2             EQU 0x0FA1
IPR2             EQU 0x0FA2
EECON1           EQU 0x0FA6
EECON2           EQU 0x0FA7
EEDATA           EQU 0x0FA8
EEADR            EQU 0x0FA9
RCSTA            EQU 0x0FAB
TXSTA            EQU 0x0FAC
TXREG            EQU 0x0FAD
RCREG            EQU 0x0FAE
SPBRG            EQU 0x0FAF
SPBRGH           EQU 0x0FB0
T3CON            EQU 0x0FB1
TMR3L            EQU 0x0FB2
TMR3LH           EQU 0x0FB3
TMR3H            EQU 0x0FB3
ECCP1AS          EQU 0x0FB6
PWM1CON          EQU 0x0FB7
BAUDCTL          EQU 0x0FB8
PSTRCON          EQU 0x0FB9
REFCON0          EQU 0x0FBA
REFCON1          EQU 0x0FBB
REFCON2          EQU 0x0FBC
CCP1CON          EQU 0x0FBD
CCPR1            EQU 0x0FBE
CCPR1L           EQU 0x0FBE
CCPR1LH          EQU 0x0FBF
CCPR1H           EQU 0x0FBF
ADCON2           EQU 0x0FC0
ADCON1           EQU 0x0FC1
ADCON0           EQU 0x0FC2
ADRES            EQU 0x0FC3
ADRESL           EQU 0x0FC3
ADRESLH          EQU 0x0FC4
ADRESH           EQU 0x0FC4
SSPCON2          EQU 0x0FC5
SSPCON1          EQU 0x0FC6
SSPSTAT          EQU 0x0FC7
SSPADD           EQU 0x0FC8
SSPBUF           EQU 0x0FC9
T2CON            EQU 0x0FCA
PR2              EQU 0x0FCB
TMR2             EQU 0x0FCC
T1CON            EQU 0x0FCD
TMR1L            EQU 0x0FCE
TMR1LH           EQU 0x0FCF
TMR1H            EQU 0x0FCF
RCON             EQU 0x0FD0
WDTCON           EQU 0x0FD1
OSCCON2          EQU 0x0FD2
OSCCON           EQU 0x0FD3
T0CON            EQU 0x0FD5
TMR0L            EQU 0x0FD6
TMR0LH           EQU 0x0FD7
TMR0H            EQU 0x0FD7
STATUS           EQU 0x0FD8
FSR2L            EQU 0x0FD9
FSR2LH           EQU 0x0FDA
FSR2H            EQU 0x0FDA
PLUSW2           EQU 0x0FDB
PREINC2          EQU 0x0FDC
POSTDEC2         EQU 0x0FDD
POSTINC2         EQU 0x0FDE
INDF2            EQU 0x0FDF
BSR              EQU 0x0FE0
FSR1L            EQU 0x0FE1
FSR1LH           EQU 0x0FE2
FSR1H            EQU 0x0FE2
PLUSW1           EQU 0x0FE3
PREINC1          EQU 0x0FE4
POSTDEC1         EQU 0x0FE5
POSTINC1         EQU 0x0FE6
INDF1            EQU 0x0FE7
WREG             EQU 0x0FE8
FSR0L            EQU 0x0FE9
FSR0LH           EQU 0x0FEA
FSR0H            EQU 0x0FEA
PLUSW0           EQU 0x0FEB
PREINC0          EQU 0x0FEC
POSTDEC0         EQU 0x0FED
POSTINC0         EQU 0x0FEE
INDF0            EQU 0x0FEF
INTCON3          EQU 0x0FF0
INTCON2          EQU 0x0FF1
INTCON           EQU 0x0FF2
PROD             EQU 0x0FF3
PRODL            EQU 0x0FF3
PRODLH           EQU 0x0FF4
PRODH            EQU 0x0FF4
TABLAT           EQU 0x0FF5
TBLPTR           EQU 0x0FF6
TBLPTRL          EQU 0x0FF6
TBLPTRLH         EQU 0x0FF7
TBLPTRH          EQU 0x0FF7
TBLPTRU          EQU 0x0FF8
PC               EQU 0x0FF9
PCL              EQU 0x0FF9
PCLATH           EQU 0x0FFA
PCLATU           EQU 0x0FFB
STKPTR           EQU 0x0FFC
TOS              EQU 0x0FFD
TOSL             EQU 0x0FFD
TOSLH            EQU 0x0FFE
TOSH             EQU 0x0FFE
TOSU             EQU 0x0FFF

; system ports...
PORTC            EQU 0x0F82
PORTB            EQU 0x0F81
PORTA            EQU 0x0F80

; UEP0
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP1
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP2
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP3
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP4
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP5
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP6
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP7
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEIE
PIDEE = 0
CRC5EE = 1
CRC16EE = 2
DFN8EE = 3
BTOEE = 4
BTSEE = 7

; UADDR
ADDR0 = 0
ADDR1 = 1
ADDR2 = 2
ADDR3 = 3
ADDR4 = 4
ADDR5 = 5
ADDR6 = 6

; UFRML
FRM0 = 0
FRM1 = 1
FRM2 = 2
FRM3 = 3
FRM4 = 4
FRM5 = 5
FRM6 = 6
FRM7 = 7

; UFRMH
FRM8 = 0
FRM9 = 1
FRM10 = 2

; UEIR
PIDEF = 0
CRC5EF = 1
CRC16EF = 2
DFN8EF = 3
BTOEF = 4
BTSEF = 7

; UIE
URSTIE = 0
UERRIE = 1
ACTVIE = 2
TRNIE = 3
IDLEIE = 4
STALLIE = 5
SOFIE = 6

; UCFG
PPB0 = 0
PPB1 = 1
FSEN = 2
UPUEN = 4
UTEYE = 7

; UIR
URSTIF = 0
UERRIF = 1
ACTVIF = 2
TRNIF = 3
IDLEIF = 4
STALLIF = 5
SOFIF = 6

; USTAT
PPBI = 1
DIR = 2
ENDP0 = 3
ENDP1 = 4
ENDP2 = 5

; UCON
SUSPND = 1
RESUME = 2
USBEN = 3
PKTDIS = 4
SE0 = 5
PPBRST = 6

; SRCON0
SRPR = 0
SRPS = 1
SRNQEN = 2
SRQEN = 3
SRCLK0 = 4
SRCLK1 = 5
SRCLK2 = 6
SRLEN = 7

; SRCON1
SRRC1E = 0
SRRC2E = 1
SRRCKE = 2
SRRPE = 3
SRSC1E = 4
SRSC2E = 5
SRSCKE = 6
SRSPE = 7

; CM2CON0
C2CH0 = 0
C2CH1 = 1
C2R = 2
C2SP = 3
C2POL = 4
C2OE = 5
C2OUT = 6
C2ON = 7

; CM2CON1
C2SYNC = 0
C2RSEL = 4
C1RSEL = 5
MC2OUT = 6
MC1OUT = 7

; CM1CON0
C1CH0 = 0
C1CH1 = 1
C1R = 2
C1SP = 3
C1POL = 4
C1OE = 5
C1OUT = 6
C1ON = 7

; SSPMASK
MSK0 = 0
MSK1 = 1
MSK2 = 2
MSK3 = 3
MSK4 = 4
MSK5 = 5
MSK6 = 6
MSK7 = 7

; SLRCON
SLRA = 0
SLRB = 1
SLRC = 2

; WPUA
WPUB3 = 3
WPUB4 = 4
WPUB5 = 5

; WPUB
WPUB4 = 4
WPUB5 = 5
WPUB6 = 6
WPUB7 = 7

; IOCA
IOCA3 = 3
IOCA4 = 4
IOCB5 = 5

; IOCB
IOCB4 = 4
IOCB5 = 5
IOCB6 = 6
IOCB7 = 7

; ANSEL
ANS3 = 3
ANS4 = 4
ANS5 = 5
ANS6 = 6
ANS7 = 7

; ANSELH
ANS8 = 0
ANS9 = 1
ANS10 = 2
ANS11 = 3

; PORTA
RA3 = 3
RA4 = 4
RA5 = 5
AN3 = 4
OSC1 = 4
OSC2 = 5
CLKI = 4
CLKO = 5

; PORTB
RB4 = 4
RB5 = 5
RB6 = 6
RB7 = 7
SDI = 4
RX = 5
SCL = 6
TX = 7
SDA = 4
; DT = 5
SCK = 6
CK = 7
AN10 = 4
AN11 = 5

; PORTC
RC0 = 0
RC1 = 1
RC2 = 2
RC3 = 3
RC4 = 4
RC5 = 5
RC6 = 6
RC7 = 7
AN4 = 0
AN5 = 1
AN6 = 2
AN7 = 3
AN8 = 6
AN9 = 7
C12INP = 0
C12IN1M = 1
C12IN2M = 2
C12IN3M = 3
C12OUT = 4
INT0 = 0
INT1 = 1
INT2 = 2
PGM = 3
T0CKI = 5
T13CKI = 6
T1OSCO = 7
VREFP = 0
VREFM = 1
CVREF = 2
T1OSCI = 6
P1D = 2
P1C = 3
P1B = 4
P1A = 5
SS = 6
SDO = 7
CCP1 = 5
NOT_SS = 6

; LATA
LATA4 = 4
LATA5 = 5

; LATB
LATB4 = 4
LATB5 = 5
LATB6 = 6
LATB7 = 7

; LATC
LATC0 = 0
LATC1 = 1
LATC2 = 2
LATC3 = 3
LATC4 = 4
LATC5 = 5
LATC6 = 6
LATC7 = 7

; DDRA
RA4 = 4
RA5 = 5

; TRISA
TRISA4 = 4
TRISA5 = 5

; DDRB
RB4 = 4
RB5 = 5
RB6 = 6
RB7 = 7

; TRISB
TRISB4 = 4
TRISB5 = 5
TRISB6 = 6
TRISB7 = 7

; DDRC
RC0 = 0
RC1 = 1
RC2 = 2
RC3 = 3
RC4 = 4
RC5 = 5
RC6 = 6
RC7 = 7

; TRISC
TRISC0 = 0
TRISC1 = 1
TRISC2 = 2
TRISC3 = 3
TRISC4 = 4
TRISC5 = 5
TRISC6 = 6
TRISC7 = 7

; OSCTUNE
TUN0 = 0
TUN1 = 1
TUN2 = 2
TUN3 = 3
TUN4 = 4
TUN5 = 5
PLLEN = 6
INTSRC = 7

; PIE1
TMR1IE = 0
TMR2IE = 1
CCP1IE = 2
SSPIE = 3
TXIE = 4
RCIE = 5
ADIE = 6

; PIR1
TMR1IF = 0
TMR2IF = 1
CCP1IF = 2
SSPIF = 3
TXIF = 4
RCIF = 5
ADIF = 6

; IPR1
TMR1IP = 0
TMR2IP = 1
CCP1IP = 2
SSPIP = 3
TXIP = 4
RCIP = 5
ADIP = 6

; PIE2
CCP2IE = 0
TMR3IE = 1
USBIE = 2
BCLIE = 3
EEIE = 4
C2IE = 5
C1IE = 6
OSCFIE = 7

; PIR2
CCP2IF = 0
TMR3IF = 1
USBIF = 2
BCLIF = 3
EEIF = 4
C2IF = 5
C1IF = 6
OSCFIF = 7

; IPR2
CCP2IP = 0
TMR3IP = 1
USBIP = 2
BCLIP = 3
EEIP = 4
C2IP = 5
C1IP = 6
OSCFIP = 7

; EECON1
RD = 0
WR = 1
WREN = 2
WRERR = 3
FREE = 4
CFGS = 6
EEPGD = 7

; RCSTA
RX9D = 0
OERR = 1
FERR = 2
ADDEN = 3
CREN = 4
SREN = 5
RX9 = 6
SPEN = 7
ADEN = 3

; TXSTA
TX9D = 0
TRMT = 1
BRGH = 2
SENDB = 3
SYNC = 4
TXEN = 5
TX9 = 6
CSRC = 7

; T3CON
TMR3ON = 0
TMR3CS = 1
T3SYNC = 2
T3CCP1 = 3
T3CKPS0 = 4
T3CKPS1 = 5
RD16 = 7
NOT_T3SYNC = 2

; ECCP1AS
PSSBD0 = 0
PSSBD1 = 1
PSSAC0 = 2
PSSAC1 = 3
ECCPAS0 = 4
ECCPAS1 = 5
ECCPAS2 = 6
ECCPASE = 7

; PWM1CON
PDC0 = 0
PDC1 = 1
PDC2 = 2
PDC3 = 3
PDC4 = 4
PDC5 = 5
PDC6 = 6
PRSEN = 7

; BAUDCTL
ABDEN = 0
WUE = 1
BRG16 = 3
CKTXP = 4
DTRXP = 5
RCIDL = 6
ABDOVF = 7
SCKP = 4

; PSTRCON
STRA = 0
STRB = 1
STRC = 2
STRD = 3
STRSYNC = 4

; REFCON0
TSRS = 2
TSEN = 3
FVR1S0 = 4
FVR1S1 = 5
FVR1ST = 6
FVR1EN = 7

; REFCON1
D1NSS0 = 0
DAC1OE = 1
D1PSS0 = 2
D1PSS1 = 3
D1LPS = 6
D1EN = 7

; CCP1CON
CCP1M0 = 0
CCP1M1 = 1
CCP1M2 = 2
CCP1M3 = 3
DC1B0 = 4
DC1B1 = 5
P1M0 = 6
P1M1 = 7

; ADCON2
ADCS0 = 0
ADCS1 = 1
ADCS2 = 2
ACQT0 = 3
ACQT1 = 4
ACQT2 = 5
ADFM = 7

; ADCON1
NVCFG0 = 0
NVCFG1 = 1
PVCFG0 = 2
PVCFG1 = 3

; ADCON0
ADON = 0
GO = 1
CHS0 = 2
CHS1 = 3
CHS2 = 4
CHS3 = 5
DONE = 1
NOT_DONE = 1
GO_DONE = 1

; SSPCON2
SEN = 0
RSEN = 1
PEN = 2
RCEN = 3
ACKEN = 4
ACKDT = 5
ACKSTAT = 6
GCEN = 7

; SSPCON1
SSPM0 = 0
SSPM1 = 1
SSPM2 = 2
SSPM3 = 3
CKP = 4
SSPEN = 5
SSPOV = 6
WCOL = 7

; SSPSTAT
BF = 0
UA = 1
R = 2
S = 3
P = 4
D = 5
CKE = 6
SMP = 7
NOT_W = 2
NOT_A = 5
R_W = 2
D_A = 5
NOT_WRITE = 2
NOT_ADDRESS = 5

; T2CON
T2CKPS0 = 0
T2CKPS1 = 1
TMR2ON = 2
TOUTPS0 = 3
TOUTPS1 = 4
TOUTPS2 = 5
TOUTPS3 = 6

; T1CON
TMR1ON = 0
TMR1CS = 1
T1SYNC = 2
T1OSCEN = 3
T1CKPS0 = 4
T1CKPS1 = 5
T1RUN = 6
RD16 = 7
NOT_T1SYNC = 2

; RCON
BOR = 0
POR = 1
PD = 2
TO = 3
RI = 4
SBOREN = 6
IPEN = 7
NOT_BOR = 0
NOT_POR = 1
NOT_PD = 2
NOT_TO = 3
NOT_RI = 4

; WDTCON
SWDTEN = 0
SWDTE = 0

; OSCCON2
LFIOFS = 0
HFIOFL = 1
PRI_SD = 2

; OSCCON
SCS0 = 0
SCS1 = 1
HFIOFS = 2
OSTS = 3
IRCF0 = 4
IRCF1 = 5
IRCF2 = 6
IDLEN = 7

; T0CON
T0PS0 = 0
T0PS1 = 1
T0PS2 = 2
PSA = 3
T0SE = 4
T0CS = 5
T08BIT = 6
TMR0ON = 7

; STATUS
C = 0
DC = 1
Z = 2
OV = 3
N = 4

; INTCON3
INT1F = 0
INT2F = 1
INT1E = 3
INT2E = 4
INT1P = 6
INT2P = 7
INT1IF = 0
INT2IF = 1
INT1IE = 3
INT2IE = 4
INT1IP = 6
INT2IP = 7

; INTCON2
RABIP = 0
TMR0IP = 2
INTEDG2 = 4
INTEDG1 = 5
INTEDG0 = 6
RABPU = 7
NOT_RABPU = 7

; INTCON
RABIF = 0
INT0F = 1
TMR0IF = 2
RBIE = 3
INT0E = 4
TMR0IE = 5
PEIE = 6
GIE = 7
INT0IF = 1
T0IF = 2
INT0IE = 4
T0IE = 5
GIEL = 6
GIEH = 7

; STKPTR
SP0 = 0
SP1 = 1
SP2 = 2
SP3 = 3
SP4 = 4
STKUNF = 6
STKOVF = 7
STKFUL = 7

; LIST
P18F14K50.inc

Code: Select all

NOLIST
; *******************************************
; * ASM Definition file for Swordfish BASIC *
; * Modified (RKP)                          *
; *******************************************
LIST

; special function registers...
UEP0             EQU 0x0F53
UEP1             EQU 0x0F54
UEP2             EQU 0x0F55
UEP3             EQU 0x0F56
UEP4             EQU 0x0F57
UEP5             EQU 0x0F58
UEP6             EQU 0x0F59
UEP7             EQU 0x0F5A
UEIE             EQU 0x0F5B
UADDR            EQU 0x0F5C
UFRML            EQU 0x0F5D
UFRMLH           EQU 0x0F5E
UFRMH            EQU 0x0F5E
UEIR             EQU 0x0F5F
UIE              EQU 0x0F60
UCFG             EQU 0x0F61
UIR              EQU 0x0F62
USTAT            EQU 0x0F63
UCON             EQU 0x0F64
TSTOUT           EQU 0x0F65
SRCON0           EQU 0x0F68
SRCON1           EQU 0x0F69
CM2CON0          EQU 0x0F6B
CM2CON1          EQU 0x0F6C
CM1CON0          EQU 0x0F6D
SSPMASK          EQU 0x0F6F
SLRCON           EQU 0x0F76
WPUA             EQU 0x0F77
WPUB             EQU 0x0F78
IOCA             EQU 0x0F79
IOCB             EQU 0x0F7A
ANSEL            EQU 0x0F7E
ANSELH           EQU 0x0F7F
LATA             EQU 0x0F89
LATB             EQU 0x0F8A
LATC             EQU 0x0F8B
DDRA             EQU 0x0F92
TRISA            EQU 0x0F92
DDRB             EQU 0x0F93
TRISB            EQU 0x0F93
DDRC             EQU 0x0F94
TRISC            EQU 0x0F94
OSCTUNE          EQU 0x0F9B
PIE1             EQU 0x0F9D
PIR1             EQU 0x0F9E
IPR1             EQU 0x0F9F
PIE2             EQU 0x0FA0
PIR2             EQU 0x0FA1
IPR2             EQU 0x0FA2
EECON1           EQU 0x0FA6
EECON2           EQU 0x0FA7
EEDATA           EQU 0x0FA8
EEADR            EQU 0x0FA9
RCSTA            EQU 0x0FAB
TXSTA            EQU 0x0FAC
TXREG            EQU 0x0FAD
RCREG            EQU 0x0FAE
SPBRG            EQU 0x0FAF
SPBRGH           EQU 0x0FB0
T3CON            EQU 0x0FB1
TMR3L            EQU 0x0FB2
TMR3LH           EQU 0x0FB3
TMR3H            EQU 0x0FB3
ECCP1AS          EQU 0x0FB6
PWM1CON          EQU 0x0FB7
BAUDCTL          EQU 0x0FB8
PSTRCON          EQU 0x0FB9
REFCON0          EQU 0x0FBA
REFCON1          EQU 0x0FBB
REFCON2          EQU 0x0FBC
CCP1CON          EQU 0x0FBD
CCPR1            EQU 0x0FBE
CCPR1L           EQU 0x0FBE
CCPR1LH          EQU 0x0FBF
CCPR1H           EQU 0x0FBF
ADCON2           EQU 0x0FC0
ADCON1           EQU 0x0FC1
ADCON0           EQU 0x0FC2
ADRES            EQU 0x0FC3
ADRESL           EQU 0x0FC3
ADRESLH          EQU 0x0FC4
ADRESH           EQU 0x0FC4
SSPCON2          EQU 0x0FC5
SSPCON1          EQU 0x0FC6
SSPSTAT          EQU 0x0FC7
SSPADD           EQU 0x0FC8
SSPBUF           EQU 0x0FC9
T2CON            EQU 0x0FCA
PR2              EQU 0x0FCB
TMR2             EQU 0x0FCC
T1CON            EQU 0x0FCD
TMR1L            EQU 0x0FCE
TMR1LH           EQU 0x0FCF
TMR1H            EQU 0x0FCF
RCON             EQU 0x0FD0
WDTCON           EQU 0x0FD1
OSCCON2          EQU 0x0FD2
OSCCON           EQU 0x0FD3
T0CON            EQU 0x0FD5
TMR0L            EQU 0x0FD6
TMR0LH           EQU 0x0FD7
TMR0H            EQU 0x0FD7
STATUS           EQU 0x0FD8
FSR2L            EQU 0x0FD9
FSR2LH           EQU 0x0FDA
FSR2H            EQU 0x0FDA
PLUSW2           EQU 0x0FDB
PREINC2          EQU 0x0FDC
POSTDEC2         EQU 0x0FDD
POSTINC2         EQU 0x0FDE
INDF2            EQU 0x0FDF
BSR              EQU 0x0FE0
FSR1L            EQU 0x0FE1
FSR1LH           EQU 0x0FE2
FSR1H            EQU 0x0FE2
PLUSW1           EQU 0x0FE3
PREINC1          EQU 0x0FE4
POSTDEC1         EQU 0x0FE5
POSTINC1         EQU 0x0FE6
INDF1            EQU 0x0FE7
WREG             EQU 0x0FE8
FSR0L            EQU 0x0FE9
FSR0LH           EQU 0x0FEA
FSR0H            EQU 0x0FEA
PLUSW0           EQU 0x0FEB
PREINC0          EQU 0x0FEC
POSTDEC0         EQU 0x0FED
POSTINC0         EQU 0x0FEE
INDF0            EQU 0x0FEF
INTCON3          EQU 0x0FF0
INTCON2          EQU 0x0FF1
INTCON           EQU 0x0FF2
PROD             EQU 0x0FF3
PRODL            EQU 0x0FF3
PRODLH           EQU 0x0FF4
PRODH            EQU 0x0FF4
TABLAT           EQU 0x0FF5
TBLPTR           EQU 0x0FF6
TBLPTRL          EQU 0x0FF6
TBLPTRLH         EQU 0x0FF7
TBLPTRH          EQU 0x0FF7
TBLPTRU          EQU 0x0FF8
PC               EQU 0x0FF9
PCL              EQU 0x0FF9
PCLATH           EQU 0x0FFA
PCLATU           EQU 0x0FFB
STKPTR           EQU 0x0FFC
TOS              EQU 0x0FFD
TOSL             EQU 0x0FFD
TOSLH            EQU 0x0FFE
TOSH             EQU 0x0FFE
TOSU             EQU 0x0FFF

; system ports...
PORTC            EQU 0x0F82
PORTB            EQU 0x0F81
PORTA            EQU 0x0F80

; UEP0
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP1
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP2
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP3
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP4
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP5
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP6
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEP7
EPSTALL = 0
EPINEN = 1
EPOUTEN = 2
EPCONDIS = 3
EPHSHK = 4

; UEIE
PIDEE = 0
CRC5EE = 1
CRC16EE = 2
DFN8EE = 3
BTOEE = 4
BTSEE = 7

; UADDR
ADDR0 = 0
ADDR1 = 1
ADDR2 = 2
ADDR3 = 3
ADDR4 = 4
ADDR5 = 5
ADDR6 = 6

; UFRML
FRM0 = 0
FRM1 = 1
FRM2 = 2
FRM3 = 3
FRM4 = 4
FRM5 = 5
FRM6 = 6
FRM7 = 7

; UFRMH
FRM8 = 0
FRM9 = 1
FRM10 = 2

; UEIR
PIDEF = 0
CRC5EF = 1
CRC16EF = 2
DFN8EF = 3
BTOEF = 4
BTSEF = 7

; UIE
URSTIE = 0
UERRIE = 1
ACTVIE = 2
TRNIE = 3
IDLEIE = 4
STALLIE = 5
SOFIE = 6

; UCFG
PPB0 = 0
PPB1 = 1
FSEN = 2
UPUEN = 4
UTEYE = 7

; UIR
URSTIF = 0
UERRIF = 1
ACTVIF = 2
TRNIF = 3
IDLEIF = 4
STALLIF = 5
SOFIF = 6

; USTAT
PPBI = 1
DIR = 2
ENDP0 = 3
ENDP1 = 4
ENDP2 = 5

; UCON
SUSPND = 1
RESUME = 2
USBEN = 3
PKTDIS = 4
SE0 = 5
PPBRST = 6

; SRCON0
SRPR = 0
SRPS = 1
SRNQEN = 2
SRQEN = 3
SRCLK0 = 4
SRCLK1 = 5
SRCLK2 = 6
SRLEN = 7

; SRCON1
SRRC1E = 0
SRRC2E = 1
SRRCKE = 2
SRRPE = 3
SRSC1E = 4
SRSC2E = 5
SRSCKE = 6
SRSPE = 7

; CM2CON0
C2CH0 = 0
C2CH1 = 1
C2R = 2
C2SP = 3
C2POL = 4
C2OE = 5
C2OUT = 6
C2ON = 7

; CM2CON1
C2SYNC = 0
C2RSEL = 4
C1RSEL = 5
MC2OUT = 6
MC1OUT = 7

; CM1CON0
C1CH0 = 0
C1CH1 = 1
C1R = 2
C1SP = 3
C1POL = 4
C1OE = 5
C1OUT = 6
C1ON = 7

; SSPMASK
MSK0 = 0
MSK1 = 1
MSK2 = 2
MSK3 = 3
MSK4 = 4
MSK5 = 5
MSK6 = 6
MSK7 = 7

; SLRCON
SLRA = 0
SLRB = 1
SLRC = 2

; WPUA
WPUB3 = 3
WPUB4 = 4
WPUB5 = 5

; WPUB
WPUB4 = 4
WPUB5 = 5
WPUB6 = 6
WPUB7 = 7

; IOCA
IOCA3 = 3
IOCA4 = 4
IOCB5 = 5

; IOCB
IOCB4 = 4
IOCB5 = 5
IOCB6 = 6
IOCB7 = 7

; ANSEL
ANS3 = 3
ANS4 = 4
ANS5 = 5
ANS6 = 6
ANS7 = 7

; ANSELH
ANS8 = 0
ANS9 = 1
ANS10 = 2
ANS11 = 3

; PORTA
RA3 = 3
RA4 = 4
RA5 = 5
AN3 = 4
OSC1 = 4
OSC2 = 5
CLKI = 4
CLKO = 5

; PORTB
RB4 = 4
RB5 = 5
RB6 = 6
RB7 = 7
SDI = 4
RX = 5
SCL = 6
TX = 7
SDA = 4
; DT = 5
SCK = 6
CK = 7
AN10 = 4
AN11 = 5

; PORTC
RC0 = 0
RC1 = 1
RC2 = 2
RC3 = 3
RC4 = 4
RC5 = 5
RC6 = 6
RC7 = 7
AN4 = 0
AN5 = 1
AN6 = 2
AN7 = 3
AN8 = 6
AN9 = 7
C12INP = 0
C12IN1M = 1
C12IN2M = 2
C12IN3M = 3
C12OUT = 4
INT0 = 0
INT1 = 1
INT2 = 2
PGM = 3
T0CKI = 5
T13CKI = 6
T1OSCO = 7
VREFP = 0
VREFM = 1
CVREF = 2
T1OSCI = 6
P1D = 2
P1C = 3
P1B = 4
P1A = 5
SS = 6
SDO = 7
CCP1 = 5
NOT_SS = 6

; LATA
LATA4 = 4
LATA5 = 5

; LATB
LATB4 = 4
LATB5 = 5
LATB6 = 6
LATB7 = 7

; LATC
LATC0 = 0
LATC1 = 1
LATC2 = 2
LATC3 = 3
LATC4 = 4
LATC5 = 5
LATC6 = 6
LATC7 = 7

; DDRA
RA4 = 4
RA5 = 5

; TRISA
TRISA4 = 4
TRISA5 = 5

; DDRB
RB4 = 4
RB5 = 5
RB6 = 6
RB7 = 7

; TRISB
TRISB4 = 4
TRISB5 = 5
TRISB6 = 6
TRISB7 = 7

; DDRC
RC0 = 0
RC1 = 1
RC2 = 2
RC3 = 3
RC4 = 4
RC5 = 5
RC6 = 6
RC7 = 7

; TRISC
TRISC0 = 0
TRISC1 = 1
TRISC2 = 2
TRISC3 = 3
TRISC4 = 4
TRISC5 = 5
TRISC6 = 6
TRISC7 = 7

; OSCTUNE
TUN0 = 0
TUN1 = 1
TUN2 = 2
TUN3 = 3
TUN4 = 4
TUN5 = 5
PLLEN = 6
INTSRC = 7

; PIE1
TMR1IE = 0
TMR2IE = 1
CCP1IE = 2
SSPIE = 3
TXIE = 4
RCIE = 5
ADIE = 6

; PIR1
TMR1IF = 0
TMR2IF = 1
CCP1IF = 2
SSPIF = 3
TXIF = 4
RCIF = 5
ADIF = 6

; IPR1
TMR1IP = 0
TMR2IP = 1
CCP1IP = 2
SSPIP = 3
TXIP = 4
RCIP = 5
ADIP = 6

; PIE2
CCP2IE = 0
TMR3IE = 1
USBIE = 2
BCLIE = 3
EEIE = 4
C2IE = 5
C1IE = 6
OSCFIE = 7

; PIR2
CCP2IF = 0
TMR3IF = 1
USBIF = 2
BCLIF = 3
EEIF = 4
C2IF = 5
C1IF = 6
OSCFIF = 7

; IPR2
CCP2IP = 0
TMR3IP = 1
USBIP = 2
BCLIP = 3
EEIP = 4
C2IP = 5
C1IP = 6
OSCFIP = 7

; EECON1
RD = 0
WR = 1
WREN = 2
WRERR = 3
FREE = 4
CFGS = 6
EEPGD = 7

; RCSTA
RX9D = 0
OERR = 1
FERR = 2
ADDEN = 3
CREN = 4
SREN = 5
RX9 = 6
SPEN = 7
ADEN = 3

; TXSTA
TX9D = 0
TRMT = 1
BRGH = 2
SENDB = 3
SYNC = 4
TXEN = 5
TX9 = 6
CSRC = 7

; T3CON
TMR3ON = 0
TMR3CS = 1
T3SYNC = 2
T3CCP1 = 3
T3CKPS0 = 4
T3CKPS1 = 5
RD16 = 7
NOT_T3SYNC = 2

; ECCP1AS
PSSBD0 = 0
PSSBD1 = 1
PSSAC0 = 2
PSSAC1 = 3
ECCPAS0 = 4
ECCPAS1 = 5
ECCPAS2 = 6
ECCPASE = 7

; PWM1CON
PDC0 = 0
PDC1 = 1
PDC2 = 2
PDC3 = 3
PDC4 = 4
PDC5 = 5
PDC6 = 6
PRSEN = 7

; BAUDCTL
ABDEN = 0
WUE = 1
BRG16 = 3
CKTXP = 4
DTRXP = 5
RCIDL = 6
ABDOVF = 7
SCKP = 4

; PSTRCON
STRA = 0
STRB = 1
STRC = 2
STRD = 3
STRSYNC = 4

; REFCON0
TSRS = 2
TSEN = 3
FVR1S0 = 4
FVR1S1 = 5
FVR1ST = 6
FVR1EN = 7

; REFCON1
D1NSS0 = 0
DAC1OE = 1
D1PSS0 = 2
D1PSS1 = 3
D1LPS = 6
D1EN = 7

; CCP1CON
CCP1M0 = 0
CCP1M1 = 1
CCP1M2 = 2
CCP1M3 = 3
DC1B0 = 4
DC1B1 = 5
P1M0 = 6
P1M1 = 7

; ADCON2
ADCS0 = 0
ADCS1 = 1
ADCS2 = 2
ACQT0 = 3
ACQT1 = 4
ACQT2 = 5
ADFM = 7

; ADCON1
NVCFG0 = 0
NVCFG1 = 1
PVCFG0 = 2
PVCFG1 = 3

; ADCON0
ADON = 0
GO = 1
CHS0 = 2
CHS1 = 3
CHS2 = 4
CHS3 = 5
DONE = 1
NOT_DONE = 1
GO_DONE = 1

; SSPCON2
SEN = 0
RSEN = 1
PEN = 2
RCEN = 3
ACKEN = 4
ACKDT = 5
ACKSTAT = 6
GCEN = 7

; SSPCON1
SSPM0 = 0
SSPM1 = 1
SSPM2 = 2
SSPM3 = 3
CKP = 4
SSPEN = 5
SSPOV = 6
WCOL = 7

; SSPSTAT
BF = 0
UA = 1
R = 2
S = 3
P = 4
D = 5
CKE = 6
SMP = 7
NOT_W = 2
NOT_A = 5
R_W = 2
D_A = 5
NOT_WRITE = 2
NOT_ADDRESS = 5

; T2CON
T2CKPS0 = 0
T2CKPS1 = 1
TMR2ON = 2
TOUTPS0 = 3
TOUTPS1 = 4
TOUTPS2 = 5
TOUTPS3 = 6

; T1CON
TMR1ON = 0
TMR1CS = 1
T1SYNC = 2
T1OSCEN = 3
T1CKPS0 = 4
T1CKPS1 = 5
T1RUN = 6
RD16 = 7
NOT_T1SYNC = 2

; RCON
BOR = 0
POR = 1
PD = 2
TO = 3
RI = 4
SBOREN = 6
IPEN = 7
NOT_BOR = 0
NOT_POR = 1
NOT_PD = 2
NOT_TO = 3
NOT_RI = 4

; WDTCON
SWDTEN = 0
SWDTE = 0

; OSCCON2
LFIOFS = 0
HFIOFL = 1
PRI_SD = 2

; OSCCON
SCS0 = 0
SCS1 = 1
HFIOFS = 2
OSTS = 3
IRCF0 = 4
IRCF1 = 5
IRCF2 = 6
IDLEN = 7

; T0CON
T0PS0 = 0
T0PS1 = 1
T0PS2 = 2
PSA = 3
T0SE = 4
T0CS = 5
T08BIT = 6
TMR0ON = 7

; STATUS
C = 0
DC = 1
Z = 2
OV = 3
N = 4

; INTCON3
INT1F = 0
INT2F = 1
INT1E = 3
INT2E = 4
INT1P = 6
INT2P = 7
INT1IF = 0
INT2IF = 1
INT1IE = 3
INT2IE = 4
INT1IP = 6
INT2IP = 7

; INTCON2
RABIP = 0
TMR0IP = 2
INTEDG2 = 4
INTEDG1 = 5
INTEDG0 = 6
RABPU = 7
NOT_RABPU = 7

; INTCON
RABIF = 0
INT0F = 1
TMR0IF = 2
RBIE = 3
INT0E = 4
TMR0IE = 5
PEIE = 6
GIE = 7
INT0IF = 1
T0IF = 2
INT0IE = 4
T0IE = 5
GIEL = 6
GIEH = 7

; STKPTR
SP0 = 0
SP1 = 1
SP2 = 2
SP3 = 3
SP4 = 4
STKUNF = 6
STKOVF = 7
STKFUL = 7

; LIST
These are the changes needed just to get Swordfish to compile programs for these parts. To get it to work with the USB modules, those changes will be made in the following post.

:) RKP

RKP
Registered User
Registered User
Posts: 82
Joined: Mon Oct 22, 2007 3:14 pm
Location: Maryland

Post by RKP » Mon Apr 19, 2010 6:22 pm

Here is follow up post to get the USB HID modules to work for these parts.
These are the files that need to be modified. But first copy the files to the user library located here Swordfish\UserLibrary.

The files names are: USBSFR.bas, USBConfig.bas and USBSystem.bas.

I will just post the before and after changes you need to make so this post will not be as long as the previous one.

USBSFR.bas

Code: Select all

// public aliases...
public dim 
   UFRMLBits as TUFRML absolute $0F66,
   UFRMHBits as TUFRMH absolute $0F67,
   UIRBits as TUIR absolute $0F68,
   UIEBits as TUIE absolute $0F69,
   UEIRBits as TUEIR absolute $0F6A,
   UEIEBits as TUEIE absolute $0F6B,
   USTATBits as TUSTAT absolute $0F6C,
   UCONBits as TUCON absolute $0F6D,
   UADDRBits as TUADDR absolute $0F6E,               
   UCFGBits as TUCFG absolute $0F6F,
   UEP0Bits as TUEP absolute $0F70,
   UEP1Bits as TUEP absolute $0F71,
   UEP2Bits as TUEP absolute $0F72,
   UEP3Bits as TUEP absolute $0F73,
   UEP4Bits as TUEP absolute $0F74,
   UEP5Bits as TUEP absolute $0F75,
   UEP6Bits as TUEP absolute $0F76,
   UEP7Bits as TUEP absolute $0F77,
   UEP8Bits as TUEP absolute $0F78,
   UEP9Bits as TUEP absolute $0F79,
   UEP10Bits as TUEP absolute $0F7A,
   UEP11Bits as TUEP absolute $0F7B,
   UEP12Bits as TUEP absolute $0F7C,
   UEP13Bits as TUEP absolute $0F7D,
   UEP14Bits as TUEP absolute $0F7E,
   UEP15Bits as TUEP absolute $0F7F,
   PIE2Bits as TPIE2 absolute $0FA0,
   PIR2Bits as TPIR2 absolute $0FA1, 
   INTCONBits as TINTCON absolute $0FF2
Modify to this

Code: Select all

// public aliases...
                     
#if _device in (18F13K50, 18F14K50)
  Public Dim
   UEP0Bits As TUEP Absolute $0F53,
   UEP1Bits As TUEP Absolute $0F54,
   UEP2Bits As TUEP Absolute $0F55,
   UEP3Bits As TUEP Absolute $0F56,
   UEP4Bits As TUEP Absolute $0F57,
   UEP5Bits As TUEP Absolute $0F58,
   UEP6Bits As TUEP Absolute $0F59,
   UEP7Bits As TUEP Absolute $0F5A,
   UEIEBits As TUEIE Absolute $0F5B,
   UADDRBits As TUADDR Absolute $0F5C, 
   UFRMLBits As TUFRML Absolute $0F5D,
   UFRMHBits As TUFRMH Absolute $0F5E,
   UEIRBits As TUEIR Absolute $0F5F,
   UIEBits As TUIE Absolute $0F60,
   UCFGBits As TUCFG Absolute $0F61,
   UIRBits As TUIR Absolute $0F62,
   USTATBits As TUSTAT Absolute $0F63,
   UCONBits As TUCON Absolute $0F64,
   PIE2Bits As TPIE2 Absolute $0FA0,
   PIR2Bits As TPIR2 Absolute $0FA1, 
   INTCONBits As TINTCON Absolute $0FF2
#else 
Public Dim 
   UFRMLBits As TUFRML Absolute $0F66,
   UFRMHBits As TUFRMH Absolute $0F67,
   UIRBits As TUIR Absolute $0F68,
   UIEBits As TUIE Absolute $0F69,
   UEIRBits As TUEIR Absolute $0F6A,
   UEIEBits As TUEIE Absolute $0F6B,
   USTATBits As TUSTAT Absolute $0F6C,
   UCONBits As TUCON Absolute $0F6D,
   UADDRBits As TUADDR Absolute $0F6E,               
   UCFGBits As TUCFG Absolute $0F6F,
   UEP0Bits As TUEP Absolute $0F70,
   UEP1Bits As TUEP Absolute $0F71,
   UEP2Bits As TUEP Absolute $0F72,
   UEP3Bits As TUEP Absolute $0F73,
   UEP4Bits As TUEP Absolute $0F74,
   UEP5Bits As TUEP Absolute $0F75,
   UEP6Bits As TUEP Absolute $0F76,
   UEP7Bits As TUEP Absolute $0F77,
   UEP8Bits As TUEP Absolute $0F78,
   UEP9Bits As TUEP Absolute $0F79,
   UEP10Bits As TUEP Absolute $0F7A,
   UEP11Bits As TUEP Absolute $0F7B,
   UEP12Bits As TUEP Absolute $0F7C,
   UEP13Bits As TUEP Absolute $0F7D,
   UEP14Bits As TUEP Absolute $0F7E,
   UEP15Bits As TUEP Absolute $0F7F,
   PIE2Bits As TPIE2 Absolute $0FA0,
   PIR2Bits As TPIR2 Absolute $0FA1, 
   INTCONBits As TINTCON Absolute $0FF2
#endif             
There are two changes in the USBConfig.bas file

First one is needed

Code: Select all

// ***************************************************************************
// does device support extended dual port RAM
// ***************************************************************************
#if _device in (18F2455, 18F2550, 18F4455, 18F4550)
   #define USB_EXTENDED_RAM = true
#else
   #define USB_EXTENDED_RAM = false
#endif
Modify to this

Code: Select all

// ***************************************************************************
// does device support extended dual port RAM
// ***************************************************************************
#if _device in (18F2455, 18F2550, 18F4455, 18F4550)
   #define USB_EXTENDED_RAM = true       
#else  
   #define USB_EXTENDED_RAM = false
#endif

// ***************************************************************************
// 18F1xK50 family series support extended dual port RAM
// ***************************************************************************
#if _device in (18F13K50, 18F14K50)
   #define USB_EXTENDED_RAM_K50 = true
#else  
   #define USB_EXTENDED_RAM_K50 = false
#endif                         
The next change is not required to make the USB work but is needed for my example program that will be posted later.

Code: Select all

// ***************************************************************************
// HID buffer size
// ***************************************************************************
#option HID_BUFFER_SIZE = 64                    // HID EP1 can be 8, 16, 32 or 64
#if not (HID_BUFFER_SIZE in (8, 16, 32, 64))
   #error HID_BUFFER_SIZE, "Invalid option. HID_BUFFER_SIZE must be 8, 16, 32 or 64."
#endif

// will equal HID_BUFFER_SIZE unless overridden in main program...
#option HID_REPORT_BYTES_IN = HID_BUFFER_SIZE  // HID Report bytes in
#if not (HID_REPORT_BYTES_IN in (8, 16, 32, 64))
   #error HID_REPORT_BYTES_IN, "Invalid option. HID_REPORT_BYTES_IN must be 8, 16, 32 or 64."
#endif

// will equal HID_BUFFER_SIZE unless overridden in main program...
#option HID_REPORT_BYTES_OUT = HID_BUFFER_SIZE // HID_Report bytes out
#if not (HID_REPORT_BYTES_OUT in (8, 16, 32, 64))
   #error HID_REPORT_BYTES_OUT, "Invalid option. HID_REPORT_BYTES_OUT must be 8, 16, 32 or 64."
#endif
Modify to this (This part is needed for my example code that will be post in the next post)

Code: Select all

// ***************************************************************************
// HID buffer size
// ***************************************************************************
#option HID_BUFFER_SIZE = 64                    // HID EP1 can be 8, 16, 32 or 64
#if Not (HID_BUFFER_SIZE in (2, 4, 8, 16, 32, 40, 64))
   #error HID_BUFFER_SIZE, "Invalid option. HID_BUFFER_SIZE must be 8, 16, 32 or 64."
#endif

// will equal HID_BUFFER_SIZE unless overridden in main program...
#option HID_REPORT_BYTES_IN = HID_BUFFER_SIZE  // HID Report bytes in
#if Not (HID_REPORT_BYTES_IN in (2, 4, 8, 16, 32, 40, 64))
   #error HID_REPORT_BYTES_IN, "Invalid option. HID_REPORT_BYTES_IN must be 8, 16, 32 or 64."
#endif

// will equal HID_BUFFER_SIZE unless overridden in main program...
#option HID_REPORT_BYTES_OUT = HID_BUFFER_SIZE // HID_Report bytes out
#if Not (HID_REPORT_BYTES_OUT in (2, 4, 8, 16, 32, 64))
   #error HID_REPORT_BYTES_OUT, "Invalid option. HID_REPORT_BYTES_OUT must be 8, 16, 32 or 64."
#endif
Finally the USBSystem.bas file, there are two required changes. Here they are:
USBSystem.bas

Code: Select all

// fixed location variables
#if USB_EXTENDED_RAM
   #variable _maxram = $0400     
#else
   #variable _maxram = $0200     
#endif
#define EP_SIZE = 4                   // endpoint size (byte)
#define USB_RAM_EP = $400             // USB RAM start location
Modify to

Code: Select all

// fixed location variables
#if USB_EXTENDED_RAM                   
   #variable _maxram = $0400     
#else
   #variable _maxram = $0200     
#endif 
#define EP_SIZE = 4                   // endpoint size (byte)
#define USB_RAM_EP = $400             // USB RAM start location


#if USB_EXTENDED_RAM_K50                    // Added for PIC18F13K50/14K50 family functionality                                        
      #variable _maxram = $0100             // Only 256 bytes of DP Ram      
      #undefine EP_SIZE
      #undefine USB_RAM_EP         
      #define EP_SIZE = 4                   // endpoint size (byte)
      #define USB_RAM_EP = $200             // USB RAM start location **** starts at 200 hex on these parts         
#else
   #variable _maxram = $0200 

#endif            
Second change

Code: Select all

{
****************************************************************************
* Name    : mDisableEP1to15                                                *
* Purpose : This macro disables all endpoints except EP0. This macro       *
*         : should be called when the host sends a RESET signal or a       *
*         : SET_CONFIGURATION request.                                     *
****************************************************************************
}
Sub mDisableEP1to15()                                                           'usbdrv.h
   UEP1 = $00
   UEP2 = $00
   UEP3 = $00
   UEP4 = $00
   UEP5 = $00
   UEP6 = $00
   UEP7 = $00
   UEP8 = $00
   UEP9 = $00
   UEP10 = $00
   UEP11 = $00
   UEP12 = $00
   UEP13 = $00
   UEP14 = $00
   UEP15 = $00   
End Sub
Modify to

Code: Select all

{
****************************************************************************
* Name    : mDisableEP1to15                                                *
* Purpose : This macro disables all endpoints except EP0. This macro       *
*         : should be called when the host sends a RESET signal or a       *
*         : SET_CONFIGURATION request.                                     *
****************************************************************************
}
Sub mDisableEP1to15()                                                           'usbdrv.h
#if _device in (18F13K50, 18F14K50)                   // Added for PIC18F13K50/14K50 family functionality
   UEP1 = $00
   UEP2 = $00
   UEP3 = $00
   UEP4 = $00
   UEP5 = $00
   UEP6 = $00
   UEP7 = $00
#else   
   UEP1 = $00
   UEP2 = $00
   UEP3 = $00
   UEP4 = $00
   UEP5 = $00
   UEP6 = $00
   UEP7 = $00
   UEP8 = $00
   UEP9 = $00
   UEP10 = $00
   UEP11 = $00
   UEP12 = $00
   UEP13 = $00
   UEP14 = $00
   UEP15 = $00 
#endif           
End Sub
These modified file will now compile the USB module for these part and be recognized by the PC.

In the next post I will post my test program and descriptor file for those interested.

:D RKP

RKP
Registered User
Registered User
Posts: 82
Joined: Mon Oct 22, 2007 3:14 pm
Location: Maryland

Post by RKP » Mon Apr 19, 2010 6:40 pm

Here is my test program and descriptor file I used to verify that the modified files works for these 13K50 and 14K50 family of parts.

Test file

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 4/9/2010                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F14K50
Clock = 16 
Config    
   CPUDIV = CLKDIV3,    ' 12MHz external , 48Mhz for USB_FS, 16MHz internal
   USBDIV = OFF, 
   FOSC = ECH,          ' External 12MHz clock
   PLLEN = ON,
   PWRTEN = ON,
   BOREN = OFF,
   WDTEN = OFF       
   
   
   
#option USB_DESCRIPTOR = "18F14K50_Desc.bas"

// Modules
Include "usbhid.bas" 
   
Dim Buffer(2) As Byte   
Dim x As Byte   
Dim y As Byte
Dim LED As PORTB.5 
Dim cnt As Byte  
   
   
TRISA = %00000011       ' D+ and D- are inputs
TRISB = %00000000       ' All outputs   
TRISC = %00000000       ' All outputs   
ANSEL = %00000000       ' Disable A/D on all pins 
ANSELH = %00000000      ' Disable A/D on all pins
CM1CON0 = %00000000     ' Disable Comparator 1
CM2CON0 = %00000000     ' Disable Comparator 2

LATA = $00              ' Make PORTA outputs Low
LATB = $00              ' Make PORTB outputs Low
LATC = $00              ' Make PORTC outputs Low

 

High (LED)              ' test bit to see if gets to HID.Attached

DelayMS(100)

// connect to USB...
 
Repeat
Service
Until HID.Attached

Low (LED)               ' test bit to see if gets past to HID.Attached

While true
   

   If DataAvailable Then
      ReadArray(Buffer,02)    'Change myBuffer to 02 for Jan's Hid Tester prog. 
         x = Buffer(0)
         y = Buffer(1)       
                       
    // Test just to see if I recieved data and can send it back
         Buffer(0) = Buffer(0) + 1
         Buffer(1) = Buffer(1) + 1
         WriteArray(Buffer,2)
         

         
         Select y
            Case $00               
                Low(LED)
            Case $01                
                High(LED)          
            Else                
                Low(LED)
          EndSelect                 
   
   EndIf
          
// if the USB_SERVICE option has been disabled, you MUST poll the USB
   // connection every 1 ms or so to keep it alive and handle pending
   // transactions on the bus...
   Service       
      
Wend         
The descriptor file

Code: Select all

{
*****************************************************************************
*  Name    : HIDDescriptor                                                  *
*  Author  : David John Barker                                              *
*  Notice  : Copyright (c) 2007 Mecanique                                   *
*          : All Rights Reserved                                            *
*  Date    : 10/01/2007                                                     *
*  Version : 1.0                                                            *
*  Notes   : EasyHID USB HID descriptor module                              *
*****************************************************************************
}
Module HIDDescriptor

// EasyHID options...
#option USB_HAVE_SERIAL_STRING = true
#option USB_VID                = 6017
#option USB_PID                = 2000
#option HID_EP_OUT_POLLING_MS  = $0A
#option HID_EP_IN_POLLING_MS   = $0A
#option USB_BUS_POWER          = $32
#option HID_REPORT_BYTES_IN    = $02
#option HID_REPORT_BYTES_OUT   = $02
#option USB_SERVICE            = false

// import modules...
Include "usbconfig.bas"
Include "usbdefs.bas"
         
// Device Descriptor 
Public Const device_dsc(18) As Byte = (
	SizeOf(USB_DEV_DSC),          // bLength - size of this descriptor IN bytes
	DSC_DEV,	                     // bDescriptorType - device descriptor type
	$00,	                        // bcdUSB (low byte)  - USB Spec Release Number IN BCD format (2.0)
	$02,	                        // bcdUSB (high byte) - USB Spec Release Number IN BCD format (2.0)
	$00,	                        // bDeviceClass - class Code
	$00,	                        // bDeviceSubClass - subclass code
	$00,	                        // bDeviceProtocol - protocol code
	USB_EP0_BUFF_SIZE,	         // bMaxPacketSize - max packet size for EP0
	USB_VID And $00FF,            // idVendor (low byte)
	USB_VID >> 8,                 // idVendor (high byte)
	USB_PID And $00FF,            // idProduct (low byte)
	USB_PID >> 8,                 // idProduct (high byte)
	USB_DEVICE_VERSION And $00FF, // bcdDevice (low byte) - device release number IN BCD format
	USB_DEVICE_VERSION >> 8,      // bcdDevice (high byte) - device release number IN BCD format
	USB_MANUFACTURER_INDEX,       // iManufacturer - manufacturer string index
	USB_PRODUCT_INDEX,            // iProduct - product string index
	USB_SERIAL_INDEX,             // iSerialNumber - device serial number string index
	$01	                        // bNumConfigurations - mumber of possible configurations
)
 
// Configuration 1 Descriptor
Public Const cfg01(41) As Byte = (
    
   // configuration Descriptor (cd01)
   SizeOf(USB_CFG_DSC),    // Size of this descriptor in bytes
   DSC_CFG,                // CONFIGURATION descriptor type
   41,                     // sizeof(cfg01) - Total length of data for this cfg
   0,                      // HIGH BYTE
   1,                      // Number of interfaces in this cfg
   1,                      // Index value of this configuration
   0,                      // Configuration string index
   _DEFAULT Or _RWU,       // Attributes, see usbdefs_std_dsc.h
   USB_BUS_POWER,          // Max power consumption (2X mA)

   // interface descriptor (i00a00)           
   SizeOf(USB_INTF_DSC),   // Size of this descriptor in bytes
   DSC_INTF,               // INTERFACE descriptor type
   0,                      // Interface Number
   0,                      // Alternate Setting Number
   2,                      // Number of endpoints in this intf
   HID_INTF,               // Class code
   0,                      // Subclass code
   0,                      // Protocol code
   0,                      // Interface string index
    
   // HID class-specific descriptor (hid_i00a00)
   SizeOf(USB_HID_DSC),    // Size of this descriptor in bytes
   DSC_HID,                // HID descriptor type
   $10,                    // HID Spec Release Number in BCD format (Low)
   $01,                    // HID Spec Release Number in BCD format (High)   
   $00,                    // Country Code (0x00 for Not supported)
   HID_NUM_OF_DSC,         // Number of class descriptors, see usbcfg.h
   DSC_RPT,                // Report descriptor type
   HID_RPT01_SIZE,         // sizeof(hid_rpt01) - Size of the report descriptor
   0,                      // HIGH BYTE
   
   // endpoint descriptor (IN) (ep01i_i00a00)
   SizeOf(USB_EP_DSC),		 // Size of this descriptor in bytes 
 	DSC_EP,						 // Endpoint descriptor type
	_EP01_IN,					 // Endpoint 1 IN	
	_INT,						    // Interrupt transfers
	HID_INT_IN_EP_SIZE,		 // Maximum packet size
	$00,                     // high byte
	HID_EP_IN_POLLING_MS,    // Polling interval (milliseconds)
	
	// enpoint descriptor (OUT) (ep01o_i00a00)
	SizeOf(USB_EP_DSC),      // Size of this descriptor in bytes 
	DSC_EP,						 // Endpoint descriptor type
	_EP01_OUT,					 // Endpoint 1 OUT	
	_INT,						    // Interrupt transfers
	HID_INT_OUT_EP_SIZE,	    // Maximum packet size
	$00,                     // high byte
	HID_EP_OUT_POLLING_MS    // Polling interval (milliseconds)
)
  
// language string - unicode format...  
Public Const sd000(4) As Byte = (
   4,              // Size of this descriptor in bytes 
   DSC_STR,        // DescriptorType
   $09,            // language ID - low byte   
   $04             // language ID - high byte 
)   

// manufacturer string - unicode format...
Public Const sd001(20) As Byte = (
   20,
   DSC_STR,
   "M", 0, "y", 0, "C", 0, "o", 0, "m", 0, "p", 0, "a", 0, "n", 0, "y", 0
)


// product string - unicode format...
Public Const sd002(26) As Byte = (
   26,
   DSC_STR,
   "H", 0, "I", 0, "D", 0, "_", 0, "1", 0, "8", 0, "F", 0, "1", 0, "4", 0, "K", 0, "5", 0, "0", 0
)


// product serial number...
#if USB_HAVE_SERIAL_STRING
Public Const sd003(10) As Byte = (
   10,
   DSC_STR,
   "2", 0, "0", 0, "1", 0, "0", 0
)

#endif

(*
   This example report descriptor for a "generic HID" defines one
   report of each type. Each report contains two bytes of data with 
   a vendor-defined Usage.

   HID_RPT01_SIZE is defined in usbcfg.h and must equal the number of bytes 
   in the report descriptor.
*)
Public Const hid_rpt01(HID_RPT01_SIZE) As Byte = (                             
   $06, $A0, $FF,	              // Usage page (vendor defined)                                
  	$09, $01,	                 // Usage ID (vendor defined)
  	$A1, $01,	                 // Collection (application)

	// The Input report
   $09, $03,     	              // Usage ID - vendor defined
   $15, $00,     	              // Logical Minimum (0)
   $26, $FF, $00,               // Logical Maximum (255)
   $75, $08,     	              // Report Size (8 bits)
   $95, HID_REPORT_BYTES_IN,    // Report Count (2 fields)
   $81, $02,     	              // Input (Data, Variable, Absolute)  

   // The Output report
   $09, $04,     	              // Usage ID - vendor defined
   $15, $00,     	              // Logical Minimum (0)
   $26, $FF, $00,               // Logical Maximum (255)
   $75, $08,     	              // Report Size (8 bits)
   $95, HID_REPORT_BYTES_OUT,   // Report Count (2 fields)
   $91, $02,                    // Output (Data, Variable, Absolute)  

   // The Feature report
   $09, $05,     	              // Usage ID - vendor defined
   $15, $00,     	              // Logical Minimum (0)
   $26, $FF, $00,               // Logical Maximum (255)
   $75, $08,		              // Report Size (8 bits)
   $95, $02, 		              // Report Count (2 fields)
   $B1, $02,     	              // Feature (Data, Variable, Absolute)  
 	$C0	                       // end collection
)
Please note that these PICs required a 12MHz or 48MHz oscillator to work the Full speed USB module.

My hardware consisted of 12MHz clock not a crystal. That is why FOSC = ECH is in my config settings. Change the config settings to match your hardware design.

The program sends two bytes from the PC to the PIC and the PIC will return two bytes back. The bytes sent back will be the PC sent bytes +1 .
Also if the second byte is a 0x01 it will turn PortB bit 5 high if it 0x00 or any thing else it will turn PortB pin 5 low.

Have fun :) RKP

ta1dr
Registered User
Registered User
Posts: 15
Joined: Tue Aug 18, 2009 8:14 am
Location: istanbul TURKEY

Post by ta1dr » Tue Apr 20, 2010 6:34 am

Hi RKP

Many thanks for share

regards
Ahmet

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Wed Apr 21, 2010 3:13 am

Great post!
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Sep 10, 2010 4:29 pm

Yes, a really great post RKP. I tried this myself and it worked a treat. For the 18F14K50 (which has more RAM) you could add

Code: Select all

#if USB_EXTENDED_RAM_K50                    // Added for PIC18F13K50/14K50 family functionality                                       
   
   // max user RAM
   #if _device in (18F14K50)
   #variable _maxram = $0200             // 512 bytes
   #else
   #variable _maxram = $0100             // 256 bytes
   #endif
   
   #undefine EP_SIZE
   #undefine USB_RAM_EP         
   #define EP_SIZE = 4                   // endpoint size (byte)
   #define USB_RAM_EP = $200             // USB RAM start location **** starts at 200 hex on these parts         
#else
   #variable _maxram = $0200
#endif 
in the USBSystem.bas file which will give you 512 bytes of user RAM

Roshan
Registered User
Registered User
Posts: 42
Joined: Tue Mar 03, 2009 3:08 pm
Location: India

Post by Roshan » Mon Dec 03, 2012 9:21 am

To Use cdc communication what changes should in do ?

I read usbcdc file i did not find it is update with pic18F14K50

Thanks
ROSHAN

Roshan
Registered User
Registered User
Posts: 42
Joined: Tue Mar 03, 2009 3:08 pm
Location: India

Post by Roshan » Mon Dec 03, 2012 11:52 am

Hi !

I have download new files & now cdc communication working fine.

In new usbcdc.bas file command waitforstrtimeout is now obsoleate.

can i add this command again?

currently program is running with 12mhz crystal & clock = 48

i change made 20 mhz crystal & clock = 80 now program doesnot run, what is mistake with clock.

Thanks
ROSHAN

RKP
Registered User
Registered User
Posts: 82
Joined: Mon Oct 22, 2007 3:14 pm
Location: Maryland

Post by RKP » Mon Dec 03, 2012 3:15 pm

Hi Roshan,

Unfortunately you can only use a 12MHz or 48Mhz crystal for use as a High Speed USB device. These smaller USB PIC's do not have the PLL Prescaler that the 18F2455-2550 family does, to allow the 20MHz crystal to be used.

As far as the waitforstrtimeout command not sure why it has been removed. Put it back in and let us know if it works.

Keith

Roshan
Registered User
Registered User
Posts: 42
Joined: Tue Mar 03, 2009 3:08 pm
Location: India

Post by Roshan » Tue Dec 04, 2012 5:42 am

Dear Sir,

Thanks for help.

I want to know one thing more. As i know i have to service usb @ 1ms interval.

I have a sensor where sensor read time is > 1 ms. Then what shoud i do ?

1. Should i disable ISR service, then read sensor & again enable ISR ?

Thanks
ROSHAN

Post Reply