18F87K22 Port B Digital


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Posts
    53

    Default 18F87K22 Port B Digital

    Hi,

    I am using a PIC18F87K22 and want to write a simple message to the LCD but something is not right, perhaps the set up of Port B is not correct?, any help would be greatly appreciated, I have the following code below:


    DEFINE OSC 16
    Define LCD_DREG PORTB ' Define LCD connections
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 4
    Define LCD_EREG PORTB
    Define LCD_EBIT 5
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8
    DEFINE LCD_LINES 2 'Number lines on LCD
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us
    DEFINE LCD_DATAUS 50 'Data delay time in us

    ANCON0 = 0
    ANCON1 = 0
    ANCON2 = 0
    Pause 10 ' Wait for LCD to startup



    STARTUP:


    Lcdout $fe, 1,"HELLO "
    Lcdout $fe,$C0,"WORLD "
    PAUSE 4000

    goto startup



    END

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: 18F87K22 Port B Digital

    There is no fuse, and OSCCON isnt set.
    Here is config for internal osc and 16MHz:
    Code:
    #CONFIG
        CONFIG RETEN = OFF
        CONFIG INTOSCSEL = LOW
        CONFIG SOSCSEL = LOW
        CONFIG XINST = OFF
        CONFIG FOSC = INTIO2
        CONFIG PLLCFG = OFF
        CONFIG FCMEN = OFF
        CONFIG IESO = OFF
        CONFIG PWRTEN = ON
        CONFIG BOREN = OFF
        CONFIG BORV = 3
        CONFIG BORPWR = ZPBORMV
        CONFIG WDTEN = OFF
        CONFIG WDTPS = 1048576
        CONFIG RTCOSC = SOSCREF
        CONFIG CCP2MX = PORTC
        CONFIG MSSPMSK = MSK7
        CONFIG MCLRE = OFF
        CONFIG STVREN = ON
        CONFIG BBSIZ = BB2K
        CONFIG CP0 = OFF
        CONFIG CP1 = OFF
        CONFIG CP2 = OFF
        CONFIG CP3 = OFF
        CONFIG CP4 = OFF
        CONFIG CP5 = OFF
        CONFIG CP6 = OFF
        CONFIG CP7 = OFF
        CONFIG CPB = OFF
        CONFIG CPD = OFF
        CONFIG WRT0 = OFF
        CONFIG WRT1 = OFF
        CONFIG WRT2 = OFF
        CONFIG WRT3 = OFF
        CONFIG WRT4 = OFF
        CONFIG WRT5 = OFF
        CONFIG WRT6 = OFF
        CONFIG WRT7 = OFF
        CONFIG WRTC = OFF
        CONFIG WRTB = OFF
        CONFIG WRTD = OFF
        CONFIG EBRT0 = OFF
        CONFIG EBRT1 = OFF
        CONFIG EBRT2 = OFF
        CONFIG EBRT3 = OFF
        CONFIG EBRT4 = OFF
        CONFIG EBRT5 = OFF
        CONFIG EBRT6 = OFF
        CONFIG EBRT7 = OFF
        CONFIG EBRTB = OFF
    #ENDCONFIG
    
        DEFINE OSC 16
        DEFINE NO_CLRWDT 1
        OSCCON = %01110010

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: 18F87K22 Port B Digital

    here is commented config for 18f67k22 , 64mhz internal

    Code:
    ' config for 18F67K22
    
        #CONFIG
    
    ;----- CONFIG1L Options --------------------------------------------------
        CONFIG XINST     = OFF 
        CONFIG SOSCSEL   = DIG        ; Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
        CONFIG INTOSCSEL = HIGH       ; LF-INTOSC in High-power mode during Sleep
        CONFIG RETEN     = ON
    
    ;----- CONFIG1H Options --------------------------------------------------
        CONFIG IESO      = OFF 
        CONFIG FCMEN     = OFF
        CONFIG PLLCFG    = ON 
        CONFIG FOSC      = INTIO2     ; Internal RC oscillator
     
    ;----- CONFIG2L Options --------------------------------------------------
        CONFIG BORPWR    = ZPBORMV    ; ZPBORMV instead of BORMV is selected
        CONFIG BORV      = 2          ; 2V
        CONFIG BOREN     = SBORDIS    ; Enabled in hardware, SBOREN disabled
        CONFIG PWRTEN    = ON         ; Power up timer on 
    
    ;----- CONFIG2H Options --------------------------------------------------
        CONFIG WDTPS     = 512        ; 1:512
        CONFIG WDTEN     = ON        ; WDT ON
      
    ;----- CONFIG3L Options --------------------------------------------------
        CONFIG RTCOSC    = INTOSCREF       ; RTCC uses internal osc
    
    ;----- CONFIG3H Options --------------------------------------------------
        CONFIG MCLRE     = ON              ; MCLR Enabled, RG5 disabled
        CONFIG MSSPMSK   = MSK7            ; 7 Bit address masking mode
        CONFIG CCP2MX    = PORTC           ; RC1
    
    ;----- CONFIG4L Options --------------------------------------------------
        CONFIG DEBUG     = OFF
        CONFIG BBSIZ     = BB1K            ; 1K word Boot Block size
        CONFIG STVREN    = ON 
    
    ;----- CONFIG5L Options --------------------------------------------------  
        
        CONFIG CP0       = OFF
        CONFIG CP1       = OFF
        CONFIG CP2       = OFF
        CONFIG CP3       = OFF
        CONFIG CP4       = OFF
        CONFIG CP5       = OFF
        CONFIG CP6       = OFF
        CONFIG CP7       = OFF 
       
    ;----- CONFIG5H Options --------------------------------------------------  
       CONFIG  CPD       = OFF
       CONFIG  CPB       = OFF
    
    ;----- CONFIG6L Options --------------------------------------------------  
        CONFIG WRT0      = OFF
        CONFIG WRT1      = OFF
        CONFIG WRT2      = OFF 
        CONFIG WRT3      = OFF
        CONFIG WRT4      = OFF
        CONFIG WRT5      = OFF
        CONFIG WRT6      = OFF
        CONFIG WRT7      = OFF
      
    ;----- CONFIG6H Options --------------------------------------------------  
        CONFIG WRTD      = OFF
        CONFIG WRTB      = OFF
        CONFIG WRTC      = OFF
     
    ;----- CONFIG7L Options --------------------------------------------------  
         CONFIG EBRT0     = OFF
         CONFIG EBRT1     = OFF
         CONFIG EBRT2     = OFF
         CONFIG EBRT3     = OFF
         CONFIG EBRT4     = OFF 
         CONFIG EBRT5     = OFF
         CONFIG EBRT6     = OFF
         CONFIG EBRT7     = OFF
       
    ;----- CONFIG7H Options --------------------------------------------------  
        CONFIG EBRTB     = OFF 
     
       #ENDCONFIG
    usually the problems are with C port or D port as config affects use of those ports

    Code:
     
       ' -------   Setup port B Variables  & directions  ----------                       
        INTCON2.7 = 0              ' Weak Pullups Globle PortB -  1= globel PortB disable, 0 = PortB Globle enable 
        INTCON2.0 = 1              ' RBIP    - RB PortB Change Interupt Priority - 1 = High Priorty , 0 = Low Priority 
        
        TRISB =  %11011111         ' setup Port B input=1,output=0 for I/O pins 
        PORTB  = %00000000         ' Clear Outputs

  4. #4
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: 18F87K22 Port B Digital

    You should also note that the PBP manual states ""a program should wait for up to half a second before sending the first command to an LCD. It can take quite a while for an LCD to start up."

    I recently wasted an entire evening learning (the hard way) just how long it can take for an LCD to start up!

    Change your line
    Pause 10 ' Wait for LCD to startup

    to

    Pause 500 ' Wait for LCD to startup

    and see how it goes.

    Cheers
    Barry
    VK2XBP

  5. #5
    Join Date
    Sep 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: 18F87K22 Port B Digital

    Thanks All - Worked like a charm!, I now know to set Config Bits..;-)

Similar Threads

  1. 18F87K22 & extended memory in PBP3
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th November 2013, 06:45
  2. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 11:41
  3. Replies: 5
    Last Post: - 16th October 2009, 18:29
  4. LCD R/S works on Port A but not Port B
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th February 2009, 12:41
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43

Members who have read this thread : 1

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