help with pic16f887


Closed Thread
Results 1 to 40 of 61

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default help with pic16f887

    Hello, this is the first I am using the pic16F887. My program is not showing anything on my LCD. I am sure the wiring is good. I would like to know if the initisialixing of the code is good. I took down an example from Melabs, but I saw there was no init strings as I usually do with my pic16F88.

    http://melabs.com/resources/samples/x1/pbp/serbufx.htm

    Ok here is my code. can somebody tell me if there is a problem with the begining ?? thanks
    K


    '/////////////////////////
    '// Define section //
    '/////////////////////////

    '///////////////////////////
    '// Interrupt section //
    '///////////////////////////



    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000


    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////

    DEFINE CCP1_REG PORTB 'Define output port of pulses out
    DEFINE CCP1_BIT 3 'Define output port of pulses out

    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec

    'CMCON = 7 ' Disable analog comparator
    'ANSEL = %11111111 ' set ANx as analog ?????????????????????????????
    ADCON1 = %10000010 ' Right justified results for 10 bits
    ADCON0 = %11000001 ' Internal OSC, AN0, Configure and turn on A/D Module

    TRISB = %00000000 ' Set PORTB to all output
    TRISA = %11111111 ' Set PORTA to all input
    'TRISC = %00000000


    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////


    Battery_Switch var byte
    i var byte
    j var byte
    Battery_Charge_Counter var byte


    SDApin var PORTB.1 ' RTC data
    SCLpin var PORTB.2 ' RTC clock
    DB0 var byte[8]
    bat var byte

    Total_time var byte
    Write_Address var byte

    RTCSec var byte :RTCMin var byte :RTCHour var byte :RTCWDay var byte :RTCDay var byte :RTCMonth var byte :RTCYear var byte :RTCCtrl var byte

    Write_Address = 0

    lcdout $FE,1, "Bienvenue"
    lcdout $FE,$C0, "Welcome"
    pause 4000

    I2CWRITE SDApin,SCLpin,$D0,$00,[$00,$00,$00,$00,$00,$00,$00,$00] ' Write to DS1307 to start counter at ZERO
    PORTC.2 = Battery_Charge_Counter 'always 5v, push button to gnd

    '////////////////////////////////////////////////////
    '////////////////// PROGRAM /////////////////////////
    '////////////////////////////////////////////////////

    Mainloop:

    lcdout $FE,1, " Appuyé sur Start "
    lcdout $FE,$C0, "Press on Start to Begin"
    pause 200

    if PORTC.3 =0 then 'always 5v, push button to gnd

    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl] 'read clock

    I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCSec] ' Write to External EEPROM
    Write_Address= Write_Address + 1
    I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCMin] ' Write to External EEPROM
    Write_Address= Write_Address + 1
    I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCHour] ' Write to External EEPROM
    Write_Address= Write_Address + 1
    I2CWRITE SDApin,SCLpin,$A0,Write_Address,[RTCDay] ' Write to External EEPROM
    Write_Address= Write_Address + 1

    Battery_Charge_Counter = Battery_Charge_Counter + 1
    Endif

    if PORTC.4 =0 then 'always 5v, push button to gnd
    j=1
    bat = 0
    For i=0 to Battery_Charge_Counter
    I2CRead SDApin,SCLpin,$A0,bat,[RTCSec,RTCMin,RTCHour,RTCDay]
    lcdout $FE,1, " Time ", dec j
    lcdout $FE,$C0, dec RTCDay, dec RTCHour, dec RTCMin, dec RTCSec
    pause 3000
    j = j + 1
    i = i + 1
    bat = bat + 4
    next i
    Endif

    goto Mainloop
    End

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The 887 has analog inputs on PORTB.
    So you need to enable Digital Inputs for the LCD to work on those pins ... or the I2C (RB1,RB2).

    Code:
    ANSELH = 0
    DT

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    HI, thanks for the help, I am getting a little bit further I have change my define section:

    '/////////////////////////
    '// Define section //
    '/////////////////////////

    @ device pic16F887, HS_OSC
    Define OSC 8 ' Set clock speed
    ANSELH = 0


    Here is the error:
    Executing: "C:\PBP2.60\PBPMPLAB.BAT" -ampasmwin -k# -p16F887 "C:\PBP2.60\eeprom.bas"
    Executing: "C:\PBP2.60\PBPW.EXE" -ampasmwin -k# -p16F887 "C:\PBP2.60\eeprom.bas"
    PICBASIC PRO(TM) Compiler 2.60A, (c) 1998, 2010 microEngineering Labs, Inc.
    All Rights Reserved.

    ERROR: Unable to execute mpasmwin.Warning[207] C:\PBP2.60\EEPROM.ASM 170 : Found label after column 1. (device)
    Error[122] C:\PBP2.60\EEPROM.ASM 170 : Illegal opcode (pic16F887)
    Warning[202] C:\PBP2.60\EEPROM.MAC 132 : Argument out of range. Least significant bits used.
    Halting build on first failure as requested.
    BUILD FAILED: Tue Nov 30 06:53:30 2010

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I just tested the same code I posted within Windows XP- Dos window. using the command pbp -p16F887 eeprom.bas.. I worked as it did yesterday. At home I have Windows 7, so I had to use Mplab and the same problem free program under windows XP is not compilable under windows 7...
    any thoughts

    .... the code under XP compiles with or without ANSELH = 0


    K

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ device pic16F887, HS_OSC
    Is not correct for MPASAM.
    Try
    Code:
    @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    OSCCON = %01110000 '8 Mhz
    DEFINE OSC 8
    Last edited by mackrackit; - 30th November 2010 at 13:58. Reason: Setup for internal OSC
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Hi,
    thats the same line from the Inc file: 16F887.INC except for the oscillation.
    Why doesn't it work in MPlab ??? does it read the INC files ??? maybe there a configuration that I need to point to that file ??

    K

Members who have read this thread : 0

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