Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me solve library error in Proteus

Status
Not open for further replies.

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Hello, I'm new here and need help. In the simulator Proteus to simulate the LM35 temperature sensor gave the following message and I had never seen before and do not know how to solve, if anyone has a hint will be welcome, ok.

"Can not find model 'LM35.MDF.'
Pin ' VS + 'is not modeled.
Pin 'VOUT' nor is modeled.
Pin 'VS-' is not modeled.
Simulation FAILED due to netlist linker error (s). "
 

h.sharma

Junior Member level 3
Joined
Jun 16, 2012
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,455
Re: Error msg in Proteus

in device window insert the device with model
 

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Re: Error msg in Proteus

i already place my device at device window, but still not working. Here, my circuitry.

 

Jigar 4 Electronics

Full Member level 5
Joined
Apr 28, 2011
Messages
313
Helped
40
Reputation
82
Reaction score
38
Trophy points
1,318
Location
Hamilton, ON, Canada
Activity points
3,390
Re: Error msg in Proteus

The error is mentioning Library problem.
Might be you don't have the library in a same folder where your simulator is.
or you should go for reinstall the software.

to confirm the error of library, try to simulate the circuit without LM35, Is it running or not?
If yes then try to found related library in your files or reinstall the program.
 

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Re: Error msg in Proteus

Thanks for the reply .

but I still don't get it how to check wheather the model is inside the library or not.

thank you in advance.
 

Jigar 4 Electronics

Full Member level 5
Joined
Apr 28, 2011
Messages
313
Helped
40
Reputation
82
Reaction score
38
Trophy points
1,318
Location
Hamilton, ON, Canada
Activity points
3,390
Re: Error msg in Proteus

@ nyeda, I've already mentioned how to check it :

to confirm the error of library, try to simulate the circuit without LM35, Is it running or not?

If it's running without error then the problem is of component library, & If you're still facing the error then reinstall the program or find the library files.
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,032
Trophy points
1,393
Location
Greece
Activity points
64,375
Re: Error msg in Proteus

open the component selector and check the show only components with models option.
Then search if LM35 exists and use that
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Re: Error msg in Proteus

Put this file in MODELS directory and check the simulation. If it doesn't work try renaming the file from LM35DZ.MDF to LM35.MDF.

You are using a very old version (7.07) of proteus download and install Proteus 7.10 SP 0 and try. If you need any help mail to internetuser2k11@gmail.com

Just an Update...

OK. I found the LM35 files.

Download LM35.rar and extract LM32.IDX and LM35.LIB ti LIBRARY folder and LM35.MDF to MODELS folder.
 

Attachments

  • LM35DZ.rar
    520 bytes · Views: 23
  • LM35.rar
    1.4 KB · Views: 26
Last edited:

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Re: Error msg in Proteus

ok thank you for the reply alexan_e and internetuser2k12

i will try to place the file first . thank you
 

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Re: Error msg in Proteus

My LM35 already didnt display that error when play , but the prob is the LCD doesnt display the analog reading. and when i stop the simulation the error come out again .

LM35Play.pngLM35Play.pngLM35stop.png
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Re: Error msg in Proteus

You have used .cof file for simulation instead use hex file for similation. Have you put the LM35.IDX, LM35.LIB, and LM35.MDF files into the proper folders? If you still get errors after using .hex file for simulation upload your .dsn file zipped. Also try to post your code. For ADC you have to configure ACCON0, ADCON1, ANSEL, ANSELH, and CMCON registers.
 
  • Like
Reactions: nyeda

    nyeda

    Points: 2
    Helpful Answer Positive Rating

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
Re: Error msg in Proteus

I already put the LM35.IDX, LM35.LIB to LIBRARY folder and lm35.mdf to model folder. I also have simulate it using both .cof and.hex file. when I try it at hardware, it can display the value,

adc code :

Code:
#define _XTAL_FREQ 	20000000

int read_adc(unsigned char channel);

int read_adc(unsigned char channel)
{
ADCON0=0b00000001;					//Turn on A/D module
ADCON1=0b10000000;					//Right Justify
if(channel<=7) ANSEL=ANSEL|(0b00000001<<channel);
else ANSELH=ANSELH|(0b00000001<<(channel-8));
ADCON0=(ADCON0&0xC3)|(channel<<2);			//select analog input channel
__delay_ms(2);
ADON=1;							//initiate conversion on the selected channel
while(ADON==1) continue;					//wait until conversion done
return(256*ADRESH+ADRESL);
}

LM35 code:

Code:
#include <htc.h>
#include <stdio.h>
 	
#include "lcd16f887.c"
#include "adc16f887.c"
/*******************************************************************************
* DEVICE CONFIGURATION WORDS FOR PIC16F887                                     *
*******************************************************************************/

// If PIC16F887 is being selected as device

//******************************************************************************/
#define	_XTAL_FREQ	20000000

main()
{
TRISD=0;
RD7=1;
TRISA=0B11111111;
unsigned char i;
unsigned int an1; //read analog voltage at RA0;
	lcd_init();
	printf("Temperature");
    	here:
			lcd_2ndline();
			an1=(int)(4.888*read_adc(1)); //10 mV per celcius. Convert 4.88V to 5Volt( 4.888x 1023=5000mV)	
		//	an1=(an1/10);		
            printf("%d",an1);		
			printf(".");
			printf("%d",an1%10);
			printf("Celcius   ");
			__delay_ms(1000);
goto here;
    	
}
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Re: Error msg in Proteus

That is not the full code. Where is channel defined? Why do you need RD7 = 1? Check this about adc. you will get some idea.
https://www.edaboard.com/threads/253183/ Check only the Hi-Tech C code. mikroC doesn't apply to you. Why have you connected 4K7 to RA1, when you are giving o/p V from LM35 to RA1? Your ADCON1 should be 10001101. with that RA0 and RA1 will be analog.

Where is the code of the include files?
lcd16f887.c
adc16f887.c

If possible send me your .hex file and also proteus .dsn file. zip and upload the files.
 
Last edited:

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
please send lcd16f877.c and adc16f887.c files.

Does the code work in real hardware?
 
Last edited:

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
the code is working in the real harware , and the value is shown in the display . just i dont get it why the value doesnt display at proteus

Code:
adc16f887
#define _XTAL_FREQ 	20000000

int read_adc(unsigned char channel);

int read_adc(unsigned char channel)
{
ADCON0=0b00000001;					//Turn on A/D module
ADCON1=0b10000000;					//Right Justify
if(channel<=7) ANSEL=ANSEL|(0b00000001<<channel);
else ANSELH=ANSELH|(0b00000001<<(channel-8));
ADCON0=(ADCON0&0xC3)|(channel<<2);			//select analog input channel
__delay_ms(2);
ADON=1;							//initiate conversion on the selected channel
while(ADON==1) continue;					//wait until conversion done
return(256*ADRESH+ADRESL);
}

Code:
lcd16f887
#include <htc.h>
#include "pic16f887_config.h"
#define _XTAL_FREQ 20000000

// 16x2 LCD controller
// (max characters is 40)
// Initialization: lcd_init();
// To print a string: printf("Hello World");
// A few more formatting subroutines are available. 
// See towards the end of this page. 

// macros to isolate interface dependencies
// LCD is connected to PORTD
#define LCDPort		PORTD
#define LCDTris		TRISD
#define Epin		6
#define RWpin		5
#define RSpin		4
#define BUSYpin		3
#define DATA0pin	0
#define DATA1pin	1
#define DATA2pin	2
#define DATA3pin	3

#define EHIGH          bitset(LCDPort, Epin)
#define ELOW           bitclr(LCDPort, Epin)
#define E_OUTPUT       bitclr(LCDTris, Epin)
#define RSHIGH         bitset(LCDPort, RSpin)
#define RSLOW          bitclr(LCDPort, RSpin)
#define RS_OUTPUT      bitclr(LCDTris, RSpin)
#define RWHIGH         bitset(LCDPort, RWpin)
#define RWLOW          bitclr(LCDPort, RWpin)
#define RW_OUTPUT      bitclr(LCDTris, RWpin)
#define BUSY_FLAG      bittst(LCDPort, BUSYpin)
#define DATA_DIR_RD    {bitset(LCDTris,DATA3pin);bitset(LCDTris,DATA2pin);bitset(LCDTris,DATA1pin);bitset(LCDTris,DATA0pin);}
#define DATA_DIR_WR    {bitclr(LCDTris,DATA3pin);bitclr(LCDTris,DATA2pin);bitclr(LCDTris,DATA1pin);bitclr(LCDTris,DATA0pin);}
#define OUTPUT_DATA(x) {int aval=LCDPort&0xF0; x = x & 0x0F; LCDPort=aval+x;}

	
void epulse(void){
	__delay_us(1);
	EHIGH;
	__delay_us(1); 
	ELOW; 
	__delay_us(1);
}

void lcd_write(
     unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag){
	char bflag,c;
	if (chk_busy) {
		RSLOW;       //RS = 0 to check busy
		// check busy
		DATA_DIR_RD;  //set data pins all inputs
		RWHIGH;       // R/W = 1, for read
		do {
			EHIGH; 
			__delay_us(1);  // upper 4 bits
			bflag = BUSY_FLAG;  
			ELOW; 
			__delay_us(1);
			epulse();
		} while(bflag);
	} else {
		__delay_ms(10); // don't use busy, just delay
	}
	DATA_DIR_WR;
	if (data_flag)  RSHIGH;   // RS=1, data byte
	else    RSLOW;   // RS=0, command byte
	// device is not busy
	RWLOW;       // R/W = 0, for write
	c = cmd >> 4;  // send upper 4 bits
	OUTPUT_DATA(c);
	epulse();
	if (dflag) {
		c = cmd & 0x0F;  //send lower 4 bits
		OUTPUT_DATA(c);
		epulse();
	}
}
    

void lcd_init(void) {
	// configure, see control pins as outputs
	// initialize as low
	E_OUTPUT;  RS_OUTPUT;  RW_OUTPUT;
	ELOW; RSLOW;  RWLOW; 
	
	__delay_ms(25);  //wait for device to settle
	__delay_ms(25);
	lcd_write(0x20,0,0,0);  // 4 bit interface
	lcd_write(0x28,0,0,1);  // 2 line display, 5x7 font
	lcd_write(0x28,0,0,1);  // repeat
	lcd_write(0x06,0,0,1);  // enable display
	lcd_write(0x0C,0,0,1);  // turn display on; cursor, blink is off
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
	__delay_ms(3);   // wait for busy flag to be ready
}

// send 8 bit char to LCD
void putch (char c) {
    lcd_write(c,1,1,1);
}

void lcd_clear(void){
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
}

void lcd_2ndline(void){
	lcd_write(0xC0,0,1,1);  // cursor to 2nd line
}

void lcd_shiftleft(void){
	lcd_write(0x18,0,1,1);  // shift left
}
 
void lcd_shiftright(void){
	lcd_write(0x1C,0,1,1);  // shift right
}   

void lcd_blinkcursor(void){
	lcd_write(0x0F,0,1,1);  // displays and blink a cursor
}

void lcd_printbar(int bar){
	for(int i=0; i<bar; i++){
		lcd_write(0xFF,1,1,1);	// print bars on the LCD
	}
}

void lcd_printstring(const char *s)			//send a string to display in the lcd
{          
	unsigned char i=0;
  	while (s && *s)lcd_write(*s++,1,1,1);

}
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Sorry, I get the error message pic16f887_config.h not found. You have to send that file. I can't compile without that file.

---upddate-----------

In Project > Build Options...> Project > Linker Tab have you checked Format hex file for download?



Regards

Jayanth D
 

Attachments

  • ss.jpg
    ss.jpg
    119.4 KB · Views: 27

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
I am getting the errors shown in the image. I don't know htc, I use mikroC. Tell me how to make the compiler recognize ADCON0, etc.
 

Attachments

  • ss1.jpg
    ss1.jpg
    243.2 KB · Views: 24

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
The adc part is not working. Otherwise it can display values in the second line.

Code:
#include <htc.h>
#include <stdio.h>
#include <pic16f887.h>

/*******************************************************************************
* DEVICE CONFIGURATION WORDS FOR PIC16F887                                     *
*******************************************************************************/
// Configuration Bits 
//__CONFIG(HS&WDTDIS&PWRTEN&BORDIS&LVPDIS&DEBUGDIS&UNPROTECT);

#define _XTAL_FREQ 20000000

#define bitset(var,bitno) ((var) |= (1 << (bitno)))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define bittst(var,bitno) (var & (1 << (bitno)))
// If PIC16F887 is being selected as device

// 16x2 LCD controller
// (max characters is 40)
// Initialization: lcd_init();
// To print a string: printf("Hello World");
// A few more formatting subroutines are available. 
// See towards the end of this page. 

// macros to isolate interface dependencies
// LCD is connected to PORTD
#define LCDPort		PORTD
#define LCDTris		TRISD
#define Epin		6
#define RWpin		5
#define RSpin		4
#define BUSYpin		3
#define DATA0pin	0
#define DATA1pin	1
#define DATA2pin	2
#define DATA3pin	3

#define EHIGH          bitset(LCDPort, Epin)
#define ELOW           bitclr(LCDPort, Epin)
#define E_OUTPUT       bitclr(LCDTris, Epin)
#define RSHIGH         bitset(LCDPort, RSpin)
#define RSLOW          bitclr(LCDPort, RSpin)
#define RS_OUTPUT      bitclr(LCDTris, RSpin)
#define RWHIGH         bitset(LCDPort, RWpin)
#define RWLOW          bitclr(LCDPort, RWpin)
#define RW_OUTPUT      bitclr(LCDTris, RWpin)
#define BUSY_FLAG      bittst(LCDPort, BUSYpin)
#define DATA_DIR_RD    {bitset(LCDTris,DATA3pin);bitset(LCDTris,DATA2pin);bitset(LCDTris,DATA1pin);bitset(LCDTris,DATA0pin);}
#define DATA_DIR_WR    {bitclr(LCDTris,DATA3pin);bitclr(LCDTris,DATA2pin);bitclr(LCDTris,DATA1pin);bitclr(LCDTris,DATA0pin);}
#define OUTPUT_DATA(x) {int aval=LCDPort&0xF0; x = x & 0x0F; LCDPort=aval+x;}

//******************************************************************************/

long read_adc(unsigned char channel);
void  epulse(void);
void lcd_write(unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag);
void lcd_init(void);
void putch(char c);
void lcd_clear(void);
void lcd_2ndline(void);
void lcd_shiftleft(void);
void lcd_shiftright(void);
void lcd_blinkcursor(void);
void lcd_printbar(int bar);
void lcd_printstring(const char *s);

void epulse(void){
	__delay_us(1);
	EHIGH;
	__delay_us(1); 
	ELOW; 
	__delay_us(1);
}

void lcd_write(unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag){
	char bflag,c;

	if (chk_busy) {
		RSLOW;       						//RS = 0 to check busy
											// check busy
		DATA_DIR_RD;  						//set data pins all inputs
		RWHIGH;       						// R/W = 1, for read
		do {
			EHIGH; 
			__delay_us(1);  				// upper 4 bits
			bflag = BUSY_FLAG;  
			ELOW; 
			__delay_us(1);
			epulse();
		} while(bflag);
	} else {
		__delay_ms(10); 					// don't use busy, just delay
	}

	DATA_DIR_WR;
	if (data_flag)  RSHIGH;   				// RS=1, data byte
	else    RSLOW;   						// RS=0, command byte
											// device is not busy
	RWLOW;       							// R/W = 0, for write
	c = cmd >> 4;  							// send upper 4 bits
	OUTPUT_DATA(c);
	epulse();
	if (dflag) {
		c = cmd & 0x0F;  					//send lower 4 bits
		OUTPUT_DATA(c);
		epulse();
	}
}

void lcd_init(void) {
	// configure, see control pins as outputs
	// initialize as low
	E_OUTPUT;  RS_OUTPUT;  RW_OUTPUT;
	ELOW; RSLOW;  RWLOW; 
	
	__delay_ms(25);  //wait for device to settle
	__delay_ms(25);
	lcd_write(0x20,0,0,0);  // 4 bit interface
	lcd_write(0x28,0,0,1);  // 2 line display, 5x7 font
	lcd_write(0x28,0,0,1);  // repeat
	lcd_write(0x06,0,0,1);  // enable display
	lcd_write(0x0C,0,0,1);  // turn display on; cursor, blink is off
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
	__delay_ms(3);   // wait for busy flag to be ready
}

// send 8 bit char to LCD
void putch(char c) {
    lcd_write(c,1,1,1);
}

void lcd_clear(void){
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
}

void lcd_2ndline(void){
	lcd_write(0xC0,0,1,1);  // cursor to 2nd line
}

void lcd_shiftleft(void){
	lcd_write(0x18,0,1,1);  // shift left
}
 
void lcd_shiftright(void){
	lcd_write(0x1C,0,1,1);  // shift right
}   

void lcd_blinkcursor(void){
	lcd_write(0x0F,0,1,1);  // displays and blink a cursor
}

void lcd_printbar(int bar){
	for(int i=0; i<bar; i++){
		lcd_write(0xFF,1,1,1);	// print bars on the LCD
	}
}

void lcd_printstring(const char *s)			//send a string to display in the lcd
{          
	unsigned char i=0;
  	while (s && *s)lcd_write(*s++,1,1,1);

}

long read_adc(unsigned char channel)
{
	long result;
	ADRESL = 0x00;
	ADRESH = 0x00;
	//__delay_ms(2);

	ADON = 1;											
	while(ADON == 1) 
		continue;
						
	result = ADRESH;        // copy high byte to result
    result <<= 8;           // shift low byte to 2nd byte
    result |= ADRESL;       // OR result with ADRESL to get both the bytes into one var.
    //__delay_ms(5);
    return result;
}

main()
{
	TRISD = 0x00;
	TRISA = 0xFF;
	ANSEL  = 0x02;		// 00000010
	ANSELH = 0x00;		// 00000000
	ADCON0 = 0x84;		// 10000100											
	ADCON1 = 0x80;		// 10000000

	unsigned char i;
	long an1;
 											
	lcd_init();
	printf("Temperature");

while(1) {
			//an1 = read_adc(1);
			//an1 = (4.888 * an1); 	
			lcd_2ndline();
			printf("%f",12.3);
			//printf("%f",an1);
			//printf(".");
			//printf("%f",an1%10);
			//printf("Celcius   ");
			//__delay_ms(1000);
}

   	
}

Try this in your real hardware.

Code:
#include <htc.h>
#include <stdio.h>
#include <pic16f887.h>

/*******************************************************************************
* DEVICE CONFIGURATION WORDS FOR PIC16F887                                     *
*******************************************************************************/
// Configuration Bits 
//__CONFIG(HS&WDTDIS&PWRTEN&BORDIS&LVPDIS&DEBUGDIS&UNPROTECT);

#define _XTAL_FREQ 20000000

#define bitset(var,bitno) ((var) |= (1 << (bitno)))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define bittst(var,bitno) (var & (1 << (bitno)))
// If PIC16F887 is being selected as device

// 16x2 LCD controller
// (max characters is 40)
// Initialization: lcd_init();
// To print a string: printf("Hello World");
// A few more formatting subroutines are available. 
// See towards the end of this page. 

// macros to isolate interface dependencies
// LCD is connected to PORTD
#define LCDPort		PORTD
#define LCDTris		TRISD
#define Epin		6
#define RWpin		5
#define RSpin		4
#define BUSYpin		3
#define DATA0pin	0
#define DATA1pin	1
#define DATA2pin	2
#define DATA3pin	3

#define EHIGH          bitset(LCDPort, Epin)
#define ELOW           bitclr(LCDPort, Epin)
#define E_OUTPUT       bitclr(LCDTris, Epin)
#define RSHIGH         bitset(LCDPort, RSpin)
#define RSLOW          bitclr(LCDPort, RSpin)
#define RS_OUTPUT      bitclr(LCDTris, RSpin)
#define RWHIGH         bitset(LCDPort, RWpin)
#define RWLOW          bitclr(LCDPort, RWpin)
#define RW_OUTPUT      bitclr(LCDTris, RWpin)
#define BUSY_FLAG      bittst(LCDPort, BUSYpin)
#define DATA_DIR_RD    {bitset(LCDTris,DATA3pin);bitset(LCDTris,DATA2pin);bitset(LCDTris,DATA1pin);bitset(LCDTris,DATA0pin);}
#define DATA_DIR_WR    {bitclr(LCDTris,DATA3pin);bitclr(LCDTris,DATA2pin);bitclr(LCDTris,DATA1pin);bitclr(LCDTris,DATA0pin);}
#define OUTPUT_DATA(x) {int aval=LCDPort&0xF0; x = x & 0x0F; LCDPort=aval+x;}

//******************************************************************************/

long read_adc();
void  epulse(void);
void lcd_write(unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag);
void lcd_init(void);
void putch(char c);
void lcd_clear(void);
void lcd_2ndline(void);
void lcd_shiftleft(void);
void lcd_shiftright(void);
void lcd_blinkcursor(void);
void lcd_printbar(int bar);
void lcd_printstring(const char *s);
void Delay_ms(unsigned int time);

void epulse(void){
	__delay_us(1);
	EHIGH;
	__delay_us(1); 
	ELOW; 
	__delay_us(1);
}

void lcd_write(unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag){
	char bflag,c;

	if (chk_busy) {
		RSLOW;       						//RS = 0 to check busy
											// check busy
		DATA_DIR_RD;  						//set data pins all inputs
		RWHIGH;       						// R/W = 1, for read
		do {
			EHIGH; 
			__delay_us(1);  				// upper 4 bits
			bflag = BUSY_FLAG;  
			ELOW; 
			__delay_us(1);
			epulse();
		} while(bflag);
	} else {
		__delay_ms(10); 					// don't use busy, just delay
	}

	DATA_DIR_WR;
	if (data_flag)  RSHIGH;   				// RS=1, data byte
	else    RSLOW;   						// RS=0, command byte
											// device is not busy
	RWLOW;       							// R/W = 0, for write
	c = cmd >> 4;  							// send upper 4 bits
	OUTPUT_DATA(c);
	epulse();
	if (dflag) {
		c = cmd & 0x0F;  					//send lower 4 bits
		OUTPUT_DATA(c);
		epulse();
	}
}

void lcd_init(void) {
	// configure, see control pins as outputs
	// initialize as low
	E_OUTPUT;  RS_OUTPUT;  RW_OUTPUT;
	ELOW; RSLOW;  RWLOW; 
	
	__delay_ms(25);  //wait for device to settle
	__delay_ms(25);
	lcd_write(0x20,0,0,0);  // 4 bit interface
	lcd_write(0x28,0,0,1);  // 2 line display, 5x7 font
	lcd_write(0x28,0,0,1);  // repeat
	lcd_write(0x06,0,0,1);  // enable display
	lcd_write(0x0C,0,0,1);  // turn display on; cursor, blink is off
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
	__delay_ms(3);   // wait for busy flag to be ready
}

// send 8 bit char to LCD
void putch(char c) {
    lcd_write(c,1,1,1);
}

void lcd_clear(void){
	lcd_write(0x01,0,0,1);  // clear display, move cursor to home
}

void lcd_2ndline(void){
	lcd_write(0xC0,0,1,1);  // cursor to 2nd line
}

void lcd_shiftleft(void){
	lcd_write(0x18,0,1,1);  // shift left
}
 
void lcd_shiftright(void){
	lcd_write(0x1C,0,1,1);  // shift right
}   

void lcd_blinkcursor(void){
	lcd_write(0x0F,0,1,1);  // displays and blink a cursor
}

void lcd_printbar(int bar){
	for(int i=0; i<bar; i++){
		lcd_write(0xFF,1,1,1);	// print bars on the LCD
	}
}

void lcd_printstring(const char *s)			//send a string to display in the lcd
{          
	unsigned char i=0;
  	while (s && *s)lcd_write(*s++,1,1,1);

}

void Delay_ms(unsigned int time)
		{
			unsigned int i,j;
	
			for(i = 0 ; i < time ; i++);
			for(j = 0; j < 165 ; j++);
		}

long read_adc()
{
	long result;

	ADCON0 = 0x88;		// 10000100											
	ADCON1 = 0x80;		// 10000000
	ADRESL = 0x00;
	ADRESH = 0x00;
	Delay_ms(5);
	ADCON0bits.ADON = 1;
	Delay_ms(1);
	ADCON0bits.GO = 1;
	while(ADCON0bits.GO);
	ADCON0bits.ADON = 0;
	result = ADRESH;        
	result <<= 8;            
	result |= ADRESL;       
	Delay_ms(5);
	return result;
}

main()
{
	TRISD = 0x00;
	TRISA = 0xFF;
	PORTA = 0x00;
	PORTD = 0x00;
	ANSEL  = 0x04;		// 00000010
	ANSELH = 0x00;		// 00000000
	C1ON = 0;
	C2ON = 0;

	unsigned char i;
	long an1;
 											
	lcd_init();
	printf("Temperature");

	while(1) {
			an1 = read_adc();
			an1 = (4.888 * an1);
			lcd_2ndline();
			printf("%f",an1);
			//printf(".");
			//printf("%f",an1%10);
			printf("Celcius   ");
			//__delay_ms(1000);
			Delay_ms(1000);
	}
}

The problem is with printf function. It is not printing from variables.
 

Attachments

  • ss2.jpg
    ss2.jpg
    125.9 KB · Views: 29
  • ss4.jpg
    ss4.jpg
    136.7 KB · Views: 31
Last edited:

nyeda

Newbie level 5
Joined
Jul 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
means i have to try the second coding isit ?

thnak you for helping me . i'll try to do using your coding
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top