Restrining myself in using only 10 Firewing16 micros

Discuss the Firewing development environment

Restrining myself in using only 10 Firewing16 micros

Postby funlw65 » Fri Dec 29, 2017 10:26 am

I restrain myself in using only 10 PIC24HJ micros, Firewing16 and R2 reference design. All pics are in the same family as the one in the Firewing16 board and there is a single Microchip PDF document for all the micros.

Code: Select all
' 24HJ32GP302, 24HJ32GP304
' 24HJ64GP202, 24HJ64GP204, 24HJ64GP502, 24HJ64GP504
' 24HJ128GP202, 24HJ128GP204, 24HJ128GP502, 24HJ128GP504


I don't use PIC32 and for 8bit pics I use another language. I recently conquered my fear of 3.3V devices and started learning STM32 micros (on a Nucleo board) so because I always wanted to try PIC24, here I am, using Firewing for his unrestricted C compiler.

This is the main skeleton app file:
Code: Select all
' firewing16 device, you can use any of the following:
' 24HJ32GP302, 24HJ32GP304
' 24HJ64GP202, 24HJ64GP204, 24HJ64GP502, 24HJ64GP504
' 24HJ128GP202, 24HJ128GP204, 24HJ128GP502, 24HJ128GP504
device = 24HJ32GP302
' clock speed in MHz, you can use any of the following:
' 80, 64, 32, 16, 8
clock = 80             

' config statements for pic24hj micro without bootloader
' that can be programmed with pickit 2 programmer (pk2cmd)
config  FBS = {BWRP_WRPROTECT_OFF}
#if _device in (24HJ32GP302, 24HJ32GP304)
#else
config  FSS = {SWRP_WRPROTECT_OFF}
#endif
config  FGS = {GWRP_OFF}
config  FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
config  FOSC = {POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_OFF, FCKSM_CSECMD}
config  FWDT = {WDTPOST_PS256, WINDIS_OFF, FWDTEN_OFF}
config  FPOR = {FPWRT_PWR128, ALTI2C_OFF}
config  FICD = {ICS_PGD1, JTAGEN_OFF}

macro SetSysClock()
   #if _device in (24HJ32GP302,24HJ32GP304,24HJ64GP202,24HJ64GP204,24HJ64GP502,24HJ64GP504,24HJ128GP202,24HJ128GP204,24HJ128GP502,24HJ128GP504)
   #else
      checkparam(etError, "unsupported firewing16 micro")
   #endif

   ' Fosc = Fin * (M/N1*N2))
   ' CLKDIVbits.FRCDIV = 0    (CLKDIV[10:8]) FRC/1= 7.3728MHz
   ' CLKDIVbits.PLLPOST = N2  (CLKDIV[7:6])  N2: 00=2, 01=4, 11=8
   ' CLKDIVbits.PLLPRE = 2-N1 (CLKDIV[4:0])  N1 = 2-33
   ' PLLFBDbits.PLLDIV = M-2
   #if (_clock = 80)      ' 40 MIPS
      const FRCDIV = 0
      const PLLPOST = 0
      const PLLPRE = 1
      const PLLDIV = 63   ' 39.94
      WREG4 = (CLKDIV and &HF800) or (FRCDIV<<8) or (PLLPOST<<6) or PLLPRE
      CLKDIV = WREG4
      PLLFBD = PLLDIV             
   #elseif (_clock = 64)  ' 32 MIPS                   
      const FRCDIV = 0
      const PLLPOST = 0
      const PLLPRE = 1
      const PLLDIV = 50   ' 31.95
      WREG4 = (CLKDIV and &HF800) or (FRCDIV<<8) or (PLLPOST<<6) or PLLPRE
      CLKDIV = WREG4
      PLLFBD = PLLDIV             
   #elseif (_clock = 32)  ' 16 MIPS                   
      const FRCDIV = 0
      const PLLPOST = 1
      const PLLPRE = 1
      const PLLDIV = 50   ' 15.97
      WREG4 = (CLKDIV and &HF800) or (FRCDIV<<8) or (PLLPOST<<6) or PLLPRE
      CLKDIV = WREG4
      PLLFBD = PLLDIV                 
   #elseif (_clock = 16)  ' 8 MIPS
      const FRCDIV = 0
      const PLLPOST = 3
      const PLLPRE = 1
      const PLLDIV = 50   ' 7.99
      WREG4 = (CLKDIV and &HF800) or (FRCDIV<<8) or (PLLPOST<<6) or PLLPRE
      CLKDIV = WREG4
      PLLFBD = PLLDIV             
   #elseif (_clock = 8)   ' 4 MIPS
      const FRCDIV = 1    ' note: this is outside the VCO range... should use FNOSC_FRC mode
      const PLLPOST = 3
      const PLLPRE = 1
      const PLLDIV = 50
      WREG4 = (CLKDIV and &HF800) or (FRCDIV<<8) or (PLLPOST<<6) or PLLPRE
      CLKDIV = WREG4
      PLLFBD = PLLDIV               
   #else
      checkparam(etError, "unsupported system clock freq")
   #endif

   ' trim osc for accurate baud (optional)
   'OSCTUN = &H03A

   ' wait until the PLL is locked
   while (OSCCON.bits(5) = 0)    ' check LOCK bit
   end while
end macro

' this code executes when the PIC first starts up
' for a pic24hj micro without bootloader
sub OnStartup() handles PIC.OnStartup
   RPINR18 = RPINR18 and &HFFE0 or &B00100  ' map Uart1 RX to D0 (RB.4)
   RPOR2 = RPOR2 and &HE0FF or &B00011 << 8 ' map Uart1 TX to D1 (RB.5)
   'RPINR18 = RPINR18 or &H001F  ' disable Uart1 RX
   'RPOR2 = RPOR2 and &HE0FF     ' disable Uart1 TX
end sub

'program entry point...
sub Main()
   ' the following line is mandatory! don't erase it!
   SetSysClock()
   ' code your app bellow...
   
end sub
 


I think this is enough, including for the "shrinkify your project" paradigm (at least, in terms of price).
Of course, all the .h, .gld and .bas device files are provided (you should know where to place them).

The entire setup is working under Linnux with Wine but I didn't tried it on a real hardware as I don't have yet a PIC24 micro.
Imageide by Vasile Guta-Ciucur, on Flickr
funlw65
 
Posts: 40
Joined: Thu Jan 16, 2014 2:32 pm

Re: Restrining myself in using only 10 Firewing16 micros

Postby funlw65 » Sat Aug 07, 2021 1:31 am

Download link updated as I added 10 more PICs of dsPIC33F of 40MIPS speed family, similar to the other 10 24HJ PICs, and I updated the skeleton program accordingly.
funlw65
 
Posts: 40
Joined: Thu Jan 16, 2014 2:32 pm


Return to Development Environment

Who is online

Users browsing this forum: No registered users and 2 guests

cron

x