PDA

View Full Version : 18F4550 to 18F2550



mpardinho
- 28th September 2007, 14:33
i try this code with 18F4550 and work 1000%
i change code for 18F2550 and not work, not Recognised

Resonator 4Mhz
4k7 in Mclr
470nf in Vusb
0,1nf in Vdd-Vcc

Vusb - 4550 = 3,31
Vusb - 2550 = 3,37




' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
;__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm

DEFINE OSC 48

'
' Hardware configuration
' ======================
'
' I/O and PORTs
' -------------
PORTB = 0
PORTC = 0
' PORTD = 0 ' enable for 18f4550
' PORTE = 0 ' enable for 18f4550
TRISB = 0
TRISC = 0
TRISA = $FF
' TRISD = 0 ' enable for 18f4550
' TRISE = 0 ' enable for 18f4550

' USB modulo
UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(
ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

' Interruptores
INTCON = %10100000 ' Enable global and TMR0 interrupts
T0CON = %10000000 ' TMR0, CLK internal, prescaler 1:2, T0ON

'
' Variables & constants definition
' ================================
I Var Byte

USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output

Usb_Contador Var Byte '
Usb_Dados var byte[8] ' store ADCs & pushButton data to send to USB

' Constantes
TMR0IF VAR INTCON.2 ' TMR0 overflow int flag
TMR0ON VAR T0CON.7 ' TMR0 on/off bit
TMR0IE VAR INTCON.5 ' TMR0 interrupt enable/disable bit

' Macros
goto Configura

asm
Reload_TMR0 macro
BCF _TMR0ON ; stop timer
MOVE?CW d'65000',TMR0L ; reload for timebase ~100uSec
BCF _TMR0IF ; clear overflow flag
BSF _TMR0ON ; start timer
ENDM
endasm

'-------------------------------------------------------------------------------
Configura:
pause 500
usbinit
@ Reload_TMR0
ON INTERRUPT GOTO Usb_Servico

'-------------------------------------------------------------------------------
Inicio:
gosub Usb_Entrada
goto Inicio

'-------------------------------------------------------------------------------
Usb_Entrada:
tmr0ie = 0
Usb_Contador = USBBufferSizeRX

USBService
USBIn 3, Usb_Dados, Usb_Contador, Timeout

GOSUB Usb_Saida
return

Timeout:
@ Reload_TMR0
tmr0ie = 1
return

'-------------------------------------------------------------------------------
Usb_Saida:
TMR0IE = 0

WaitPC:
'Usb_Contador = USBBufferSizeTX

USBService
USBOut 3, Usb_Dados, Usb_Contador, Waitpc
@ Reload_TMR0
tmr0ie = 1
return

'-------------------------------------------------------------------------------
DISABLE
Usb_Servico:
usbservice
@ Reload_TMR0
RESUME
ENABLE

Kamikaze47
- 28th September 2007, 21:22
for 18F2550 I use:

_CONFIG1H, _FOSC_HSPLL_HS_1H

mister_e
- 28th September 2007, 23:13
Somehow strange... i posted examples of the USBDemo that worked on the following link.
http://www.picbasic.co.uk/forum/showpost.php?p=38468&postcount=99

the whole set of config fuses for a 4MHz crystal was


'
' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB

__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48

Unless i need new glasses... can i suspect some wiring or device programmer problem?