16F88 ADC problem


Closed Thread
Results 1 to 20 of 20

Hybrid View

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

    Question 16F88 ADC problem

    I'm trying to get a 16f88 to read a voltage and display it on a LCD.

    I have been able to display code on an LCD before, and using a 12f683 I have output serial data to a PC. With this project I am trying to display the analog data directly onto a LCD screen.

    The LCD is connected to the default connections on the 16f88, an LED connected to RB1, and a variable voltage to AN0.

    The code compiles correctly without errors however when I hook everythign up I get no readout on the LCD and the LED does not flash.

    I'm hoping it's just something simple as this is my first time using the pic16f88 although I've been using the 16f84, 16f627a, 16f683 and 16f675 for about a month.

    If anyone has any pointers I've really appreciate hearing them.

    Thanks


    CODE:

    '************************************************* ***************
    '* Name : LCDTest2.pbp *
    '* Author : Greensasquatch *
    '* Notice : Copyright (c) 2008 greensasquatch.ca *
    '* : All Rights Reserved *
    '* Date : 05/09/2008 *
    '* Chip : PIC16F88 *
    '* Version : 1.0.1 *
    '* Notes : Send a message to a LCD on default pins *
    '* : read an analog value and outout on the LCD *
    '************************************************* ***************
    '* PicBasicPro program to demonstrate operation of an LCD *
    '* in 4-bit mode. *
    '* THIS VERSION: To function on a PIC16F88 and output the *
    '* voltage on the second line of the LCD. *
    '************************************************* ***************

    INCLUDE "MODEDEFS.BAS"

    @ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF

    DEFINE OSC 8 ' define ADCIN parameters
    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 uS

    adval VAR WORD ' store adc value
    redLED VAR PORTB.1 ' alias redLED with RB1


    ADCON0.7 = 1 ' right justify result
    ANSEL = %00000001 ' set AN0 analog, rest digital
    CMCON = 7 ' analog comparators off
    Output PORTB.1 ' set RB1 as output
    Pause 1500 ' wait for LCD to startup

    loop: Toggle redLED
    ADCIN 0, adval ' read channel 0 to adval (0-1023)
    adval = (adval */ 500)>>2 ' equal to (adval * 500)/1024

    Lcdout $fe, 1 ' clear LCD screen
    Lcdout "Greensasquatch"' display Greensasquatch on 1st line

    ' move cursor to 2nd line, display voltage
    Lcdout $fe,$c0, "DC Volts= ", DEC (adval/100), ".", DEC2 adval

    Pause 1000 ' wait 1 second

    Goto loop ' loop forever
    -Justin

  2. #2
    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

  3. #3
    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

  4. #4
    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

  5. #5
    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.

  6. #6
    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.

  7. #7
    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.

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