I use a dsPIC33FJ32GP304 with external resonator of 20MHz at pins OSC1 and OSC2.
Code: Select all
'PLLPRE (=N1=4 -> setting 00010)
PLLPRE_4_bit = 0
PLLPRE_3_bit = 0
PLLPRE_2_bit = 0
PLLPRE_1_bit = 1
PLLPRE_0_bit = 0
'PLLPOST (=N2=2 -> setting 00)
PLLPOST_1_bit = 0
PLLPOST_0_bit = 0
'PLLFBD (=M=32 -> setting 30)
PLLFBD = 30
'OSCTUN
OSCTUN = 0
'OSCCON
'NewOsccon = OSCCON 'get current OSCCON value
'NewOsccon = NewOsccon AND $F8FE 'clear NOSC bits and OSWEN bit
'NewOsccon = NewOsccon OR $0300 'new oscillator setting = 3 -> Primary Oscillator with PLL
asm
'const OSCCONH as word = 0x0743 'volatile sfr
';Place the New Oscillator Selection (NOSC=0b011) in W0
MOV #0x13, W0
';OSCCONH (high byte) Unlock Sequence
MOV #0x0743, W1
MOV #0x78, W2
MOV #0x9A, W3
MOV.B W2, [W1] '; Write 0x78
MOV.B W3, [W1] '; Write 0x9A
';Set New Oscillator Selection
MOV.B W0, 0x0743
'; Place 0x01 in W0 for setting clock switch enabled bit
MOV #0x01, W0
';OSCCONL (low byte) Unlock Sequence
MOV #OSCCONL, W1
MOV #0x46, W2
MOV #0x57, W3
MOV.B W2, [W1] '; Write 0x46
MOV.B W3, [W1] '; Write 0x57
'; Enable Clock Switch
MOV.B W0, [W1]
'; Request Clock Switching by Setting OSWEN bit
WaitForOswen:
BTSC OSCCON, #0
BRA WaitForOswen
end asm
while OSCCON.LOCK_bit = 0 'wait for PLL to lock
wend
AD1PCFGL = $FFFF 'In order to use PORTB pins for digital I/O, the corresponding bits in
'the AD1PCFGL register must be set to ‘1’, even if A/D module is turned off.
The compiler generates following errors:
142 313 Invalid ASM instruction: "MOV.B W0, 0x0743" SerialRGBW.mbas
The 0x0743 is the address of the highbyte of OSCCON register
OSCCONL is declared, but OSCCONH is not in the P33FJ32GP304 definition file
OSCCON as word absolute 0x0742 volatile sfr
OSCCONL as word absolute 0x0742 volatile sfr
I would add/change the following for OSCCONH and OSCCONL
OSCCONL as byte absolute 0x0742 volatile sfr
OSCCONH as byte absolute 0x0743 volatile sfr
What is wrong with my assembly code?
regards peter