16F88 ADC problem


Closed Thread
Results 1 to 20 of 20

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by greensasquatch View Post
    I'm trying to get a 16f88 to read a voltage and display it on a LCD. ...

    The LCD is connected to the default connections on the 16f88, an LED connected to RB1, and a variable voltage to AN0.
    The "Default" LCD pins have the data bus on PORTA<3:0>.

    It will be difficult to also read an analog voltage on AN0 (PORTA.0)
    <br>
    DT

  2. #2
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thank you for pointing out what should have been very painfully obvious. I'll redo the code tonight and post the results.
    -Justin

  3. #3
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    So one thing at a time, I want to get the LCD working again but on PortB. I've gone back to my code for the 16f627A and I want to get it working there before going back to the 16F88 and trying the ADC again.

    I have used defines for LCDout so that I only use port B.

    It compiles alright but when I run it on the PIC the LCD does not initialize. The light comes on, boxes are displayed (as the code used to do before initializing), the LED begins to toggle, but no change on the LCD.

    The Code:

    '************************************************* ***************
    '* Name : LCDTest1.pbp *
    '* Author : Greensasquatch *
    '* Notice : Copyright (c) 2008 greensasquatch.ca *
    '* : All Rights Reserved *
    '* Date : 05/09/2008 *
    '* Chip : PIC16F627A *
    '* Version : 1.1 *
    '* Notes : Send Hello World to a LCD on PORTB pins *
    '* : blink a LED connected to RB6 as a status light *
    '************************************************* ***************
    '* PicBasicPro program to demonstrate *
    '* operation of an LCD in 4-bit mode. *
    '************************************************* ***************
    '*
    '* Connections are as follows:
    '*
    '* N/C -01-|####|-18- N/C
    '* N/C -02-|####|-17- N/C
    '* N/C -03-|####|-16- N/C
    '* N/C -04-|####|-15- N/C
    '* Gnd -05-|####|-14- V+
    '* LCD Pin DB4 on RB0 -06-|####|-13- RB7, N/C
    '* LCD Pin DB5 on RB1 -07-|####|-12- RB6, to red LED
    '* LCD Pin DB6 on RB2 -08-|####|-11- RB5, E on LCD
    '* LCD Pin DB7 on RB3 -09-|####|-10- RB4, RS on LCD
    '*
    '************************************************* ***************

    INCLUDE "MODEDEFS.BAS"

    @ DEVICE pic16F627A, INTRC_OSC_NOCLKOUT, MCLR_OFF

    DEFINE LCD_DREG PORTB ' LCD data port
    DEFINE LCD_DBIT 0 ' LCD data starting pin, RB0-RB3
    DEFINE LCD_RSREG PORTB ' LCD register select port
    DEFINE LCD_RSBIT 4 ' LCD "RS" register select pin
    DEFINE LCD_EREG PORTB ' LCD enable port
    DEFINE LCD_EBIT 5 ' LCD "E" enable pin
    DEFINE LCD_BITS 4 ' LCD data bus size
    DEFINE LCD_LINES 2 ' number of lines on the LCD
    DEFINE LCD_COMMANDUS 1500 ' command delay in us
    DEFINE LCD_DATAUS 44 ' data delay in us


    'LED Connected to PortB.0 to circuit is doing something
    LED var PORTB.6

    CMCON = 7 'Turn off comparators
    Pause 2000 ' Wait for LCD to startup

    loop: toggle LED
    Lcdout $fe, 1 ' Clear LCD screen
    Pause 500 ' Wait .5 second
    Lcdout "Greensasquatch" ' Display Greensasquatch on 1st line
    Pause 500 ' Wait .5 second
    toggle LED
    Lcdout $fe,$c0,"Hello" ' move cursor to 2nd line, display Hello
    Pause 1000 ' Wait 1 second
    toggle LED
    Lcdout $fe,$c0,"World" ' move cursor to 2nd line, display World
    Pause 1000 ' Wait 1 second
    toggle LED
    Goto loop ' Do it forever
    -Justin

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


    Did you find this post helpful? Yes | No

    Default

    LCD4 TO RB4
    LCD6 TO RB5
    LCD11 TO RB0
    LCD12 TO RB1
    LCD13 TO RB2
    LCD14 TO RB3

    I think it is wierd wrong
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    In no particular order...

    1. Turn down the Contrast...

    2. Double-Check your LCD wiring

    3. Some LCD's need DB0-DB3 grounded to work in 4-Bit Mode.

    4. Some LCD's need their R/W pin Grounded

    5. Increase LCD_COMMANDUS to 2000 and LCD_DATAUS to 50 (values which seem to work with most LCD's).

    6. Check your code is the same as that which you have posted... if you have a typo in the LCD DEFINEs it will not throw up an Error at compile time.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Everything Melanie said, and bypass the LCD's power leads with an .01 &micro;F cap between them. I ran into a Display which wouldn't work otherwise, and it was attached to a 16F628A.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help first of all.

    I've rewritten the code and connections as per the example in the picbasic pro manual.

    Works great on the 16F627A, now to port it over to the 16F88.

    I'll post the results when it's done.

    '************************************************* ***************
    '* Name : LCDTest1.pbp *
    '* Author : Greensasquatch *
    '* Notice : Copyright (c) 2008 greensasquatch.ca *
    '* : All Rights Reserved *
    '* Date : 05/09/2008 *
    '* Chip : PIC16F627A *
    '* Version : 1.1 *
    '* Notes : Send Hello World to a LCD on PORTB pins *
    '* : blink a LED connected to RB6 as a status light *
    '************************************************* ***************
    '* PicBasicPro program to demonstrate *
    '* operation of an LCD in 4-bit mode. *
    '************************************************* ***************
    '*
    '* Connections are as follows:
    '*
    '* N/C -01-|####|-18- N/C
    '* N/C -02-|####|-17- N/C
    '* N/C -03-|####|-16- N/C
    '* N/C -04-|####|-15- N/C
    '* Gnd -05-|####|-14- V+
    '* E on LCD on RB0 -06-|####|-13- RB7, LCD Pin DB7
    '* RS on LCD on RB1 -07-|####|-12- RB6, LCD Pin DB6
    '* N/C -08-|####|-11- RB5, LCD Pin DB5
    '* red LED on RB3 -09-|####|-10- RB4, LCD Pin DB4
    '*
    '************************************************* ***************

    INCLUDE "MODEDEFS.BAS"

    @ DEVICE pic16F627A, INTRC_OSC_NOCLKOUT, MCLR_OFF

    ' Set LCD Data port
    DEFINE LCD_DREG PORTB
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTB
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 1
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTB
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 0
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50


    'LED Connected to PortB.3 to circuit is doing something
    LED var PORTB.3
    output PORTB.3

    CMCON = 7 'Turn off comparators
    Pause 2000 ' Wait for LCD to startup

    loop: toggle LED
    Lcdout $fe, 1 ' Clear LCD screen
    Pause 500 ' Wait .5 second
    Lcdout "Greensasquatch" ' Display Greensasquatch on 1st line
    Pause 500 ' Wait .5 second
    toggle LED
    Lcdout $fe,$c0,"Hello" ' move cursor to 2nd line, display Hello
    Pause 1000 ' Wait 1 second
    toggle LED
    Lcdout $fe,$c0,"World" ' move cursor to 2nd line, display World
    Pause 1000 ' Wait 1 second
    toggle LED
    Goto loop ' Do it forever
    -Justin

  8. #8
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Progrss report...

    So I've now got a new problem, can you tell I'm a noob yet?

    I've created a program now to make sure the 16F88 is working ok.

    I load the program in to the pic, compile, burn and it works. LED flashes away merrily.

    My problem now is that I can no longer reprogram the chip.

    If I connect my JDM programmer to the serial port I can detect the programmer with PICPgm and if i then insert the chip I can detect it. BUT when I try to burn the new hex file it immediately says No chip found, and then no programmer found.

    I'm wondering if it has something to do with using the RA6 and RA7 pins that are normally OSC pins. It almost seems like the programmer is fine until the PIC gets power and starts doing it's blink code. (just guessing, I'm really new at this and grasping at straws).

    Any suggestions?

    the code in case that helps:

    '************************************************* ***************
    '* Name : 88Blinker.pbp *
    '* Author : Greensasquatch *
    '* Notice : Copyright (c) 2008 *
    '* : All Rights Reserved *
    '* Chip : PIC16F88 *
    '* Date : 06/09/2008 *
    '* Version : 1.0 *
    '* Notes : To set up the most basic settings to flash *
    '* : an LED on a PORTB pin using only the internal *
    '* : oscillator and MCLR turned off. *
    '* : *
    '************************************************* ***************
    '*
    '* Connections are as follows:
    '*
    '* RA2 -01-|######|-18- RA1
    '* RA3 -02-|######|-17- RA0
    '* RA4 -03-|######|-16- RA7 to LED
    '* RA5 -04-|######|-15- RA6 to LED
    '* Gnd -05-|######|-14- V++
    '* RB0 -06-|######|-13- RB7
    '* RB1 -07-|######|-12- RB6
    '* RB2 -08-|######|-11- RB5
    '* RB3 -09-|######|-10- RB4
    '*
    '************************************************* ***************

    OSCCON = $60 'set int osc to 4mhz
    ANSEL = 0 'ALL DIGITAL
    CMCON = 7 'COMPARATORS OFF

    TRISA = %00000000 'all output
    TRISB = %00000000 'all output
    PORTA = 0 'all porta low

    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
    Pause 100 'wait to start

    START:
    High PORTA.6 'LED's on
    High PORTA.7
    Pause 1000
    Low PORTA.6 'LED's off
    Low PORTA.7
    Pause 1000
    GoTo START 'repeat
    -Justin

Similar Threads

  1. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  2. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  3. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  4. Problem with 16F88 controlling h-bridges
    By silentwol in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th March 2007, 04:16
  5. 16F88 using comparators AND the adc
    By jpeakall in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th May 2005, 01:08

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