+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    16

    Default 18F2550 With Problems

    Hi everyone,

    I'm starting a small program with Pic 18F2550, but it doesn't work well...

    It should start with number 2 at Cnt_Lixo, and increment 1 every 1,5 seconds.

    Sometimes (one in ten...), it starts well and increment correctly, but most of the times, it starts a 0, and never increment any number...

    I'm lost.

    ---------------------------------------------------------------------------------------------------------

    ASM
    __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H & _IESO_OFF_1H
    __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_OFF_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    ENDASM


    Define OSC 8 ' 8 MHz oscillator

    Baud con 84 ' Baud rate = 9600 NonInverted 32 --> 19200 bps / 396 --> 2400 bps

    PortA = $00 '
    PortB = $00 ' --> Turn Off all Port's
    PortC = $00 '

    Tecla_Esq var PortA.4 ' Tecla Esq
    Tecla_Dta var PortA.5 ' Tecla Dta

    cnt_lixo var byte
    cnt_lixo_1 var byte
    cnt_lixo_2 var byte

    cnt_lixo = %00000001
    cnt_lixo_1 = %00000010
    cnt_lixo_2 = %00000011


    ADCON1 = %00001011 ' (5) Vss Referência, (4) Vdd Referência, (3-0) AN0 até AN3 = Analog, restantes ANx Digitais
    ADCON0 = %00000000 ' (5-2) An0 Selected, (0) A/D Module Off
    ADCON2 = %10000000 ' (7) Right Justified, (5-3) A/D Acquisition Time - 0 Tad, (2-0) A/D Clock - FOSC/2

    CMCON = 7 ' (2-0) 111-> Comparator Off
    OSCCON = %01110000 ' (7) Enter Slepp Mode on Sleep Instruction, (6-4) 8 MHz, (1-0) 1x--> Internal Oscilator 00--> Primary Oscilator ???

    TRISA = %00111111
    TRISB = %00000001
    TRISC = %00010010

    ;************************************************* ***************

    DEFINE LCD_DREG PORTB ; LCD data pins port
    DEFINE LCD_DBIT 4 ; LCD low order data bit (0 -> PortX.0 - PortX.3 ou 4 -> PortX.4 - PortX.7)

    DEfine LCD_RSREG PORTB ; LCD register "RS" select pin port
    DEfine LCD_RSBIT 2 ; LCD register "RS" select pin bit

    DEfine LCD_RWREG LCD_RSREG ; LCD Read/Write select pin port
    DEfine LCD_RWBIT LCD_RSBIT ; LCD Read/Write select pin bit

    DEfine LCD_EREG PORTB ; LCD Enable "E" pin port
    DEfine LCD_EBIT 3 ; LCD Enable "E" pin bit

    DEfine LCD_BITS 4 ; Number of LCD data bits (4 or 8)
    DEfine LCD_LINES 2 ; Number of lines in LCD (1, 2, 4)

    DEfine LCD_COMMANDUS 2000 ; LCD command delay in us
    DEfine LCD_DATAUS 50 ; LCD data delay in us (0 - 255)


    cnt_lixo = cnt_lixo + 1

    Lcdout $FE, 1, " Cnt_Lixo_", dec cnt_lixo

    Definicao_Data:
    pause 1500
    Lcdout $FE, 1,"Definicao"

    cnt_lixo = cnt_lixo + 1

    if tecla_dta = 1 then cnt_lixo_1 = cnt_lixo_1 + 1 : lcdout $FE, $C0,"Tcl Dta" : pause 1500
    if tecla_esq = 1 then cnt_lixo_2 = cnt_lixo_2 + 1 : lcdout $FE, $C0,"Tcl Esq" : pause 1500

    lcdout $FE, $C0, dec cnt_lixo_1, "---", dec cnt_lixo_2, "//", dec cnt_lixo

    goto definicao_data


    End

    ---------------------------------------------------------------------------------------------------------

    Thanks,
    Nuno

  2. #2
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    218

    Default Re: 18F2550 With Problems

    Try changing:
    Code:
    if tecla_dta = 1 then cnt_lixo_1 = cnt_lixo_1 + 1 : lcdout $FE, $C0,"Tcl Dta" : pause 1500
    if tecla_esq = 1 then cnt_lixo_2 = cnt_lixo_2 + 1 : lcdout $FE, $C0,"Tcl Esq" : pause 1500
    to this:
    Code:
    if tecla_dta = 1 then
     cnt_lixo_1 = cnt_lixo_1 + 1
     lcdout $FE, $C0,"Tcl Dta" 
     pause 1500
    ELSEIF
     tecla_esq = 1 then
     cnt_lixo_2 = cnt_lixo_2 + 1
     lcdout $FE, $C0,"Tcl Esq"
     pause 1500
    ENDIF

  3. #3
    Join Date
    May 2012
    Posts
    16

    Default Re: 18F2550 With Problems

    Thanks for your answer mpgmike,

    I found the problem:

    For default, the XINST was On, and this change the extended instruction set.

    I change it to --> XINST_OFF, and everything works well.

    Thanks,
    Nuno

  4. #4
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    218

    Default Re: 18F2550 With Problems

    Charles Leo taught me to list every single CONFIG item in the header on every program. There is a document included with the PBP package that lists all the CONFIGs and what the options are for every PIC. On my PC it is found at C:\Program_Files(X86)\PBP3_1\DEVICE_REFERENCE\PIC1 8F2550 for your choice. The PBP package includes several useful resources like this, if you know about them. Glad you found your issue.

Similar Threads

  1. BOLT 18f2550
    By Leightonh in forum General
    Replies: 3
    Last Post: - 13th January 2014, 01:29
  2. Cant program 18F2550
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 4th April 2011, 19:49
  3. 18f2550 oscillator problems
    By rjones2102 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 28th September 2007, 03:57
  4. EasyHid and 18F2550 - why? what? how?
    By Giulio in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th December 2006, 07:57
  5. A/D problem on 18F2550 ?
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th December 2005, 21:40

Members who have read this thread : 19

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts