#include <pic.h>#include "delay.c"#include<stdio.h>//configuration fuse__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);static bit LCD_RS @ ((unsigned)&PORTB*8+4); // Register selectstatic bit LCD_EN @ ((unsigned)&PORTB*8+5); // Enable#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))void lcd_write(unsigned char c){ PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}//Clear and home the LCDvoid lcd_clear(void){ LCD_RS = 0; lcd_write(0x01); //0x0C for no blinking cursor DelayMs(2);}//write a string of chars to the LCD void lcd_puts(const char * s){ LCD_RS = 1; // write characters while(*s) lcd_write(*s++);}//write one character to the LCDvoid lcd_putch(char c){ LCD_RS = 1; // write characters PORTB = (PORTB & 0xF0) | (c >> 4); LCD_STROBE; PORTB = (PORTB & 0xF0) | (c & 0x0F); LCD_STROBE; DelayUs(40);}// Go to the specified positionvoid lcd_goto(unsigned char pos){ LCD_RS = 0; lcd_write(0x80+pos);}//initialise the LCD - put into 4 bit modevoid lcd_init(void){ LCD_RS = 0; // write control bytes DelayMs(15); // power on delay PORTB = 0x03; // attention! LCD_STROBE; DelayMs(5); LCD_STROBE; DelayUs(100); LCD_STROBE; DelayMs(5); PORTB = 0x02; // set 4 bit mode LCD_STROBE; DelayUs(40); lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font (0010 1000) lcd_write(0x08); // display off (0000 1000) lcd_write(0x0F); // display on, blink curson on lcd_write(0x06); // entry mode}void init_adc(void){ GIE=0; // disable interrupts ADCS1 = 1; //select 32Fosc ADCS0 = 0; ADCON1=0; // A/D port configuration 0 ADFM = 1; //right justified result ADON=1; // turn on the AD conversion module }unsigned int read_adc(unsigned char channel){ channel&=0x07; // truncate channel to 3 bits ADCON0&=0xC5; // clear current channel select ADCON0|=(channel<<3); // apply the new channel select DelayUs(10); ADGO=1; // initiate conversion on the selected channel while(ADGO)continue; return(((ADRESH&0x03)<<8)+ADRESL); // return the 10-bit result }void main(){ int adc_value; float converted_value; TRISB &= ~0xFF; PORTB &= ~0xFF; lcd_init(); //initialize LCD, set to 4-bit mode lcd_clear(); //clear LCD init_adc(); adc_value = read_adc(0); converted_value = 5 * adc / 1023; lcd_puts("---Volt Meter---"); //display text in first line lcd_goto(0x40); //display text in second line lcd_puts("Voltage: "); while(1); }
printf(lcd_puts,"Voltage: %f",converted_value);
printf("%f", converted_value)
lcd_puts("Voltage: %f",(float)converted_value);
try mo nga to... i'm not sure also, how hitech c cast valueCode: [Select]lcd_puts("Voltage: %f",(float)converted_value);
Error [186] C:\Documents and Settings\Mark\Desktop\PIC16F877A with 16x2 LCD using 1 PORT, ADC\Program1\Main.c; 130.46 too many function arguments
@drx2kparang kaparehas ng problem mo... http://forum.htsoft.com/all/showflat.php/Cat/0/Number/53142/an/page/page//vc/1
void main(){ int adc_value; float converted_value; TRISB &= ~0xFF; PORTB &= ~0xFF; lcd_init(); //initialize LCD, set to 4-bit mode lcd_clear(); //clear LCD init_adc(); adc_value = read_adc(0); converted_value = 5 * adc_value / 1023; // <<<<<<<<<<<<CORRECTION LANG lcd_puts("---Volt Meter---"); //display text in first line lcd_goto(0x40); //display text in second line lcd_puts("Voltage: %f",converted_value); while(1); }
dry2k,use sprintf() to convert the float value to ascii before displaying to LCD. The LCD will only accept character (ascii) data.Also, enable the use of float in the project build configuration
main(){ // < initialize > // while(1) { < read adc > < display adc reading > }}
parang may problem dun sa main loop 'di ba dapat ganito:Code: [Select]main(){ // < initialize > // while(1) { < read adc > < display adc reading > }} * yung read_adc() saka lcd_puts sa 2nd line ng lcd eh dapat nasa loob ng while(1) loop
gumagana po ba ang lcd sample code ng hitech c? nung ginamit ko po kasi yung library di naman gumagana.
so kailangan ko pong palitan yung freq na nakalagay sa delay.h sir? ang usual ko nmn pong ginagamit is 4Mhz sir.
static bit LCD_RS @ ((unsigned)&PORTA*8+2); // Register selectstatic bit LCD_EN @ ((unsigned)&PORTA*8+3); // Enable