Program template for 33EP512MC502

Please note that this toolsuite is not part of the official Firewing release but we will try and help where we can...

Program template for 33EP512MC502

Postby funlw65 » Tue Mar 14, 2023 9:25 am

I'm such a senile... I worked some time ago at a configuration for this micro (see title), running at 140MHz, starting on user configured clock, I think also an 8MHz crystal (which I can't remember if is right and also forgot how to use the spreadsheet to calculate the clock divider and the other parameter - I'll have to scan the forum again). Forgot, mainly because I'm working on my new version of the Nucleo Visual Configurator... like STMCubeMX, but no proprietary code inserted into the generated sources (like your code, my code) and this time, using libopencm3 as driver instead of outdated SPL...

Anyway, back to the template which it looks like this:

Code: Select all
' ======  NO BOOTLOADER APPLICATION SKELETON  =======================
' ______________ Firewing16 PRO R3 - proposal _______________________
' As firewing16 pro device, you use one of these micros:
' 33EP128MC502,33EP256MC502,33EP512MC502,33EP128MC202,33EP256MC202,
' 33EP512MC202
' 24EP128MC202,24EP256MC202,24EP512MC202
device = 33EP512MC502
clock = 140 ' (MHz) = 70MIPS - don't touch this line of code !!!     

' config statements for dsPIC33EP micro without bootloader
' - to edit the pickit2 devices as there is already a
' 33EP32GP202 device...
#if _device in (33EP128MC502,33EP256MC502,33EP512MC502,33EP128MC202,33EP256MC202,33EP512MC202,24EP128MC202, 24EP256MC202, 24EP512MC202)
config  FGS = {GCP_OFF, GWRP_OFF}
config  FOSCSEL = {FNOSC_PRIPLL, IESO_OFF}
config  FOSC = {FCKSM_CSDCMD, IOL1WAY_OFF, OSCIOFNC_OFF, POSCMD_XT}
config  FWDT = {FWDTEN_OFF}
config  FPOR = {ALTI2C2_ON}
config  FICD = {ICS_PGD1, JTAGEN_OFF}
#endif

External sub PPSLock()
External sub PPSUnlock()
public dim LockPPS() as PPSLock
public dim UnlockPPS() as PPSUnlock


macro SetSysClock()
  asm   
    mov   #12288,w0
    mov   w0,_CLKDIV
    clr   _OSCTUN
    clr   _REFOCON
    mov   #68,w0
    mov   w0,_PLLFBD
    clr   _PMD1
    clr   _PMD2
    clr   _PMD3
    clr   _PMD4
    clr   _PMD6
    clr   _PMD7
  end asm       
  while (OSCCON.bits(5) = 0) ' LOCK
  end while
end macro

sub AttachRX2ToRB4()

end sub

sub DetachRX2FromRB4()

end sub

sub AttachTX2ToRA4()

end sub

sub DetachTX2FromRA4()

end sub

sub EnableUart2()

end sub

sub EnableSPI1()

end sub

sub EnableSysTick()

end sub

sub EnableI2C2()

end sub

' this code executes when the PIC first starts up
sub OnStartup() handles PIC.OnStartup
  SetSysClock()
  ' clear pull-ups, pull-downs
  CNPDA = 0
  CNPDB = 0
  CNPUA = 0
  CNPUB = 0
  ' clear open-drain
  ODCA = 0
  ODCB = 0
  ' set all pins digital
  ANSELA = 0
  ANSELB = 0
  UnlockPPS()
 
  'Unlock
  RPINR19 = &H0024 ' map Uart2 RX to RB.4
  RPOR0   = &H0003 ' map Uart2 TX to RA.4
  LockPPS()
end sub

'program entry point...
sub Main()
  ' code your app bellow...
   
end sub



Can anyone throw and eye and see if it is correct? I bet on the C generated code, not on the hex, even if the code compiles on the Firewing16 toolchain, I don't expect to be correct, at least at the initialization code... And unfortunately, not yet a micro to test... hard to find at my place... It will take a while until I get my hands on one...

Thank you very much!
funlw65
 
Posts: 40
Joined: Thu Jan 16, 2014 2:32 pm

Return to Microchip 16

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x