|
|
View previous topic :: View next topic |
Author |
Message |
matcobra
Joined: 14 Feb 2011 Posts: 8
|
problems in LCD 16x2 showing.. |
Posted: Tue Mar 08, 2011 6:20 pm |
|
|
hello, anyone can help my problem where in the simulation part I can show the lcd showing but in real part there are still problems where lcd is blinking not functional well...
Here my code:
Code: |
//////////////////////////////////////////////////////////////////////
//
// File: coding3.c
//
// Description:
//
// Uses the ADC displaying results on the LCD.
//
// Compiler :CCS C complier v.4
//
//
// Note Testing:
//
// Tested on 16F877A
//
// Target : 16F877A
//
// Accuracy : Not very accurate.
//
// Writer:Ahmad Kamil Bin Mat Hussin a.k.a mat cobra (A122459)
//
//////////////////////////////////////////////////////////////////////
#include <16F877A.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8)
#include <lcd.c>
#define x input (pin_b0) // pH output
#define y input (pin_b1)// voltage output
void main()
{
int16 adc_value;
setup_adc_ports(ADC_CLOCK_INTERNAL);
setup_adc(ADC_CLOCK_DIV_8);
while(1)
{
float volt;
lcd_init();
set_adc_channel(0);
adc_value=read_adc();
volt=((float)(adc_value*10)/1023.0);
lcd_putc("\f PHi\n");
if(x==1)
{
if ((volt>5.00) && (volt<=7.50))
printf(lcd_putc,"PH:%3.2fsweet",volt);
else if((volt>3.00) && (volt<=5.00))
printf(lcd_putc,"PH:%3.2fsweetsour",volt);
else if((volt>0.00) && (volt<=3.00))
printf(lcd_putc,"PH:%3.2fsour",volt);
else {printf(lcd_putc,"NULL");}
}
if(y==1)
{
printf(lcd_putc,"voltage=%f\n",volt);
}
}
}
|
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Mar 08, 2011 7:58 pm |
|
|
Hi,
Without studying your code too closely, my guess is that you are encountering a button "bounce" problem. When a physical button is pressed, it has a tendency to "chatter" (open and close repeatedly) for a time before becoming stable. There are numerous hardware and software methods to "debounce" a pushbutton, but I prefer the software method. I use the "button" function that has been posted here on the forum previously.
How are your pushbuttons wired? The most common use of a button input uses a NO (normally open) pushbutton with one side directly wired to an input pin on the PIC, and the other side connected to GND. The input pin of the PIC should have a pull-up resistor to Vcc. The input pin therefore will normally be "high", and go "low" when the button is pressed. Don't forget, you still need to debounce the input!
One other thing. You already had a thread going on this project, so you should use the original, rather than creating a new one!
Good Luck!
John |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|