Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC Doesnt do ANYTHING! (PIC18F2550 with C18 Code)

Status
Not open for further replies.

kylemaes

Banned
heres my code
Code:
#include <p18f2550.h>
#include "delays.h"
#include "adc.h"
#pragma config  PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 1, FOSC = HS, FCMEN = OFF, IESO = OFF
#pragma config  PWRT = ON,  BOR = OFF, VREGEN = OFF, WDT = OFF, PBADEN = OFF,  LPT1OSC = OFF,  MCLRE = OFF
#pragma config  STVREN = OFF,  LVP = OFF, DEBUG = OFF 

void main(void); /* main code */
void foo(void); /* Interupt Service Routine */
void lcd_init();
void Write_LCD();
void Busy_flag();
void Strobe_LCD();
void OpenADC(unsigned char config,
unsigned char config2 ,
unsigned char portconfig);
int ReadADC( void );
void SetChanADC( unsigned char channel );
/*****************************************************************************************************************************/
#define E PORTAbits.RA5
#define RS PORTAbits.RA4
#define RW PORTAbits.RA3
char fare = 0;
char huns = 0;
char tens = 0;
char ones = 0;
char huns2 = 0;
char tens2 = 0;
char ones2 = 0;
char remain = 0;
char mainnum = 0;

const char ScreenData[39] = {
0x41, //A 0
0x42, //B 1
0x43, //C 2
0x44, //D 3
0x45, //E 4
0x46, //F 5
0x47, //G 6
0x48, //H 7
0x49, //I 8
0x4A, //J 9
0x4B, //K 10
0x4C, //L 11														//CHARACTER DEFINITIONS!
0x4D, //M 12
0x4E, //N 13
0x4F, //O 14
0x50, //P 15
0x51, //Q 16
0x52, //R 17
0x53, //S 18
0x54, //T 19
0x55, //U 20
0x56, //V 21
0x57, //W 22
0x58, //X 23
0x59, //Y 24
0x5A, //Z 25
0x20, //SPACE 26
0x3A, //: 27
0x30, //0 28
0x31, //1 29
0x32, //2 30
0x33, //3 31
0x34, //4 32
0x35, //5 33
0x36, //6 34
0x37, //7 35
0x38, //8 36
0x39, //9 37
0x25 //% 38
};

void Busy_Flag() 
{ 
  RW = 1;     //read mode
  while(PORTBbits.RB7);     //Loop until finished 
  RW=0;       //default to write mode... 
} 


void Strobe_LCD()
{
	E=1;
	Delay1KTCYx(4);
    E=0;
}
void Write_LCD(unsigned char d,unsigned char x)			//USE "Write_LCD(tabledata,1=cap0=lowercase);" (IF number Cap selection must equal 0!)
{
	char z = 0x00;
	if(!x)
		{
			z=0x20;
		}
	TRISB=0x00;
	PORTB=d+z;
	Strobe_LCD();
	Busy_Flag();
	TRISB=0xFF;
}

void lcd_init()
{
	Write_LCD(0x38,1);
	Write_LCD(0x0C,1);
	Write_LCD(0x01,1);
}


void AddressDisplay(unsigned char c) 
{ 
  Busy_Flag();    //check LCD ready
  TRISB = 0x00;    //PORTB output
  RW = 0;     //write mode
  RS=0;       //command mode
  PORTB=c;     //place data on data port
  TRISB = 0;    //PORTB output
  Strobe_LCD();
  RS=1;
  TRISB = 0xFF;    //PORTB input
}

const char programnametext[16] = {
2,14,12,15,14,18,19,4,17,26,26,21,4,17,27,30
/*Co  m p   o  s  t  e  r        V  e  r :   2*/
};

programname()
{
	char a = 0;
	char b;
	char c;
	Write_LCD(0x01,1);
	RS = 1;
	while(a != 16)
		{
			if((a==14) | (a==0) | (a==9) | (a==10) | (a==15) | (a==11)){c=1;}
			Write_LCD(ScreenData[programnametext[a]],c);
			c=0;
			a++;
		}
	RS = 0;
}

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



void main()
{
TRISA=0x07;
TRISB=0xFF;
TRISC=0;
lcd_init();
programname();
/**************************/
RCONbits.IPEN = 1; /* Set Priorities */
INTCONbits.GIEL = 0; /* disable low priority interrupts */
INTCONbits.GIEH = 1; /* enable high priority interrupts */
T1CONbits.RD16 = 1; /* Enable 16bit read/write of timer. */
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 1;															//INTERRUPT SETUP TIMER0
T1CONbits.TMR1CS = 0; /* Increment every instructrion cycle */
IPR1bits.TMR1IP = 1; /* Make high priority interrupt */
T1CONbits.TMR1ON = 1; /* Enable the timer */
PIE1bits.TMR1IE = 1; /* Enable timer1 interrupt */ 
TRISAbits.RA1=1;
TRISAbits.RA2=1;

/**/
				ADCON1 = 0b00001011;	//-Vref=Vdd, +Vref=Vss, AN0:An3 inputs,
				ADCON0 = 0b00000000;					
				ADCON2 = 0b10101010;	// (Fosc/32), 12 TAD (LM35 needs longer time, higher impedance)
				ADCON0bits.ADON = 1;	//Turn On ADC


/**/
/*************************/
	while(1)
		{

		}
}
#pragma interrupt foo
void foo(void) 
{

if(mainnum == 1)
	{

			ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRESH;		//TEMPERATURE			
			fare=fare*100;
			fare=fare/255;
			huns2=fare/100;
			remain=fare-(huns2*100);
			tens2=remain/10;
			ones2=remain-(tens2*10);
	}
//*******************+DISPLAY*************************//
if(mainnum == 2)
	{
		RS=1;
		AddressDisplay(0xC0);			//FANSPEED
		Write_LCD(ScreenData[5],1);
		Write_LCD(ScreenData[0],0);
		Write_LCD(ScreenData[13],0);
		Write_LCD(ScreenData[27],1);
		if(!huns){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns],1);}
		Write_LCD(ScreenData[28+tens],1);
		Write_LCD(ScreenData[28+ones],1);
		Write_LCD(ScreenData[38],1);
	
		AddressDisplay(0x90);
		Write_LCD(ScreenData[19],1);
		Write_LCD(ScreenData[4],0);
		Write_LCD(ScreenData[12],0);
		Write_LCD(ScreenData[15],0);
		Write_LCD(ScreenData[27],1);
		if(!huns2){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns2],1);} 				                  //FOR TEMPERATURE!
		Write_LCD(ScreenData[28+tens2],1);
		Write_LCD(ScreenData[28+ones2],1);
		Write_LCD(ScreenData[26],1);
		Write_LCD(ScreenData[3],0);
		Write_LCD(ScreenData[4],0);
		Write_LCD(ScreenData[6],0);
		RS=0;
	}



if(mainnum == 3)
	{
		mainnum = 0;
	}
mainnum++;
INTCONbits.TMR0IF=0;
}



#pragma code highvector=0x08
void highvector(void)
{

_asm goto foo _endasm
}
#pragma code


The part that doesnt work is:
Code:
	ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRESH;		//TEMPERATURE
			fare=fare*100;
			fare=fare/255;
			huns2=fare/100;
			remain=fare-(huns2*100);
			tens2=remain/10;
			ones2=remain-(tens2*10);

And the INIT is:
Code:
				ADCON1 = 0b00001011;	//-Vref=Vdd, +Vref=Vss, AN0:An3 inputs,
				ADCON0 = 0b00000000;					
				ADCON2 = 0b10101010;	// (Fosc/32), 12 TAD (LM35 needs longer time, higher impedance)
				ADCON0bits.ADON = 1;	//Turn On ADC

Now anyways the problem, I have only RA0 RA1 and RA2 available to use... And the it doesnt have ANY input signal! I have had all my stuff working just fine on a PIC16F877A but im trying to update to a 18F pic with USB so I can controll stuff... What is wrong with this code? (I have tried with C18's librarys aswell same problem) Thankyou so much for helping me :p
 
Last edited:
fare=ADRESH; //TEMPERATURE
Is only the high bits[8..9]

The PIC has a 10 bit ADC.
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
ADRES is a unsigned int with the complete 10 bit value.
 
When you #include delays.h and ADC.h, they should also be placed inside of <>, not quotation marks. You also don't need most of those pragma configs. The most important ones you need are the ones that define your oscillator and turn off the watchdog timer. Other than that, you probably don't need any of the ones you have. I also don't see where you read the ADC value.
 
Code:
	ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRESH;		//TEMPERATURE

In the second CODE Tag...

I did change it to:
Code:
	ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRES;		//TEMPERATURE
Without any luck... And DerStrom8, that didnt work either :(
 
Code:
	ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRESH;		//TEMPERATURE

In the second CODE Tag...

I did change it to:
Code:
	ADCON0bits.GO_DONE = 1;//Start A/D Conversion
			while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
			fare=ADRES;		//TEMPERATURE
Without any luck... And DerStrom8, that didnt work either :(

I'm not sure just reading ADRES will give you the full value. I think you really need the ReadADC function unless you go through the rest of the code to read it manually without the library function.
 
Last edited:
i tried the ReadADC, Still doesnt work...

You can't just put it in. You need to know how to use it first. I generally use a variable that I set = ReadADC().

kyle, I think you're going faster than you can really work. You're leaving out so much that it is almost impossible to know what all you're missing. Try to slow it down a bit, start from the beginning, and take it easy. It will make it a lot less difficult for you. Trust me. It was not long ago that I was learning to use the ADC on a PIC myself.
 
This works

Gives you a start
Code:
#include <p18f2550.h>
#include "delays.h"
#include "adc.h"
#pragma config  PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 1, FOSC = HS, FCMEN = OFF, IESO = OFF
#pragma config  PWRT = ON,  BOR = OFF, VREGEN = OFF, WDT = OFF, PBADEN = OFF,  LPT1OSC = OFF,  MCLRE = OFF
#pragma config  STVREN = OFF,  LVP = OFF, DEBUG = OFF 
 
void main(void); /* main code */
void foo(void); /* Interupt Service Routine */
void lcd_init();
void Write_LCD();
void Busy_flag();
void Strobe_LCD();

/*****************************************************************************************************************************/
#define E PORTAbits.RA5
#define RS PORTAbits.RA4
#define RW PORTAbits.RA3
char fare = 0;
char huns = 0;
char tens = 0;
char ones = 0;
char huns2 = 0;
char tens2 = 0;
char ones2 = 0;
char remain = 0;
char mainnum = 0;
 
const char ScreenData[39] = {
0x41, //A 0
0x42, //B 1
0x43, //C 2
0x44, //D 3
0x45, //E 4
0x46, //F 5
0x47, //G 6
0x48, //H 7
0x49, //I 8
0x4A, //J 9
0x4B, //K 10
0x4C, //L 11														//CHARACTER DEFINITIONS!
0x4D, //M 12
0x4E, //N 13
0x4F, //O 14
0x50, //P 15
0x51, //Q 16
0x52, //R 17
0x53, //S 18
0x54, //T 19
0x55, //U 20
0x56, //V 21
0x57, //W 22
0x58, //X 23
0x59, //Y 24
0x5A, //Z 25
0x20, //SPACE 26
0x3A, //: 27
0x30, //0 28
0x31, //1 29
0x32, //2 30
0x33, //3 31
0x34, //4 32
0x35, //5 33
0x36, //6 34
0x37, //7 35
0x38, //8 36
0x39, //9 37
0x25 //% 38
};
 
void Busy_Flag() 
{ 
  RW = 1;     //read mode
  while(PORTBbits.RB7);     //Loop until finished 
  RW=0;       //default to write mode... 
} 
 
 
void Strobe_LCD()
{
	E=1;
	Delay1KTCYx(4);
    E=0;
}
void Write_LCD(unsigned char d,unsigned char x)			//USE "Write_LCD(tabledata,1=cap0=lowercase);" (IF number Cap selection must equal 0!)
{
	char z = 0x00;
	if(!x)
		{
			z=0x20;
		}
	TRISB=0x00;
	PORTB=d+z;
	Strobe_LCD();
	Busy_Flag();
	TRISB=0xFF;
}
 
void lcd_init()
{
	Write_LCD(0x38,1);
	Write_LCD(0x0C,1);
	Write_LCD(0x01,1);
}
 
 
void AddressDisplay(unsigned char c) 
{ 
  Busy_Flag();    //check LCD ready
  TRISB = 0x00;    //PORTB output
  RW = 0;     //write mode
  RS=0;       //command mode
  PORTB=c;     //place data on data port
  TRISB = 0;    //PORTB output
  Strobe_LCD();
  RS=1;
  TRISB = 0xFF;    //PORTB input
}
 
const char programnametext[16] = {
2,14,12,15,14,18,19,4,17,26,26,21,4,17,27,30
/*Co  m p   o  s  t  e  r        V  e  r :   2*/
};
 
programname()
{
	char a = 0;
	char b;
	char c;
	Write_LCD(0x01,1);
	RS = 1;
	while(a != 16)
		{
			if((a==14) | (a==0) | (a==9) | (a==10) | (a==15) | (a==11)){c=1;}
			Write_LCD(ScreenData[programnametext[a]],c);
			c=0;
			a++;
		}
	RS = 0;
}
 
/*****************************************************************************************************************************/
 
 
 
void main()
{
TRISA=0x07;
TRISB=0xFF;
TRISC=0;
lcd_init();
programname();
/**************************/
RCONbits.IPEN = 1; /* Set Priorities */
INTCONbits.GIEL = 0; /* disable low priority interrupts */
INTCONbits.GIEH = 1; /* enable high priority interrupts */
T1CONbits.RD16 = 1; /* Enable 16bit read/write of timer. */
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 1;															//INTERRUPT SETUP TIMER0
T1CONbits.TMR1CS = 0; /* Increment every instructrion cycle */
IPR1bits.TMR1IP = 1; /* Make high priority interrupt */
T1CONbits.TMR1ON = 1; /* Enable the timer */
PIE1bits.TMR1IE = 1; /* Enable timer1 interrupt */ 
TRISAbits.RA1=1;
TRISAbits.RA2=1;
TRISAbits.RA0=1;
 
/**/
		OpenADC( ADC_FOSC_32      &
          		 ADC_RIGHT_JUST   &
         		 ADC_12_TAD,
         		 ADC_CH0          &
                 ADC_REF_VDD_VSS  &
           	 	 ADC_INT_OFF, ADC_CH0 );
 
 
/**/
/*************************/
	while(1)
		{
 
		}
}
#pragma interrupt foo
void foo(void) 
{
 long tmp;
if(mainnum == 1)
	{

 
  			Delay10TCYx( 5 );     // Delay for 50TCY
  			ConvertADC();         // Start conversion
  			while( BusyADC() );   // Wait for completion
		
			tmp=ReadADC();		//TEMPERATURE			
			tmp >>=2;
			tmp *= 100;
			tmp /= 255;
			huns2=tmp/100;
			remain=tmp-(huns2*100);
			tens2=remain/10;
			ones2=remain-(tens2*10);
	}
//*******************+DISPLAY*************************//
if(mainnum == 2)
	{
		RS=1;
		AddressDisplay(0xC0);			//FANSPEED
		Write_LCD(ScreenData[5],1);
		Write_LCD(ScreenData[0],0);
		Write_LCD(ScreenData[13],0);
		Write_LCD(ScreenData[27],1);
		if(!huns){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns],1);}
		Write_LCD(ScreenData[28+tens],1);
		Write_LCD(ScreenData[28+ones],1);
		Write_LCD(ScreenData[38],1);
 
		AddressDisplay(0x90);
		Write_LCD(ScreenData[19],1);
		Write_LCD(ScreenData[4],0);
		Write_LCD(ScreenData[12],0);
		Write_LCD(ScreenData[15],0);
		Write_LCD(ScreenData[27],1);
		if(!huns2){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns2],1);} 				                  //FOR TEMPERATURE!
		Write_LCD(ScreenData[28+tens2],1);
		Write_LCD(ScreenData[28+ones2],1);
		Write_LCD(ScreenData[26],1);
		Write_LCD(ScreenData[3],0);
		Write_LCD(ScreenData[4],0);
		Write_LCD(ScreenData[6],0);
		RS=0;
	}
 
 
 
if(mainnum == 3)
	{
		mainnum = 0;
	}
mainnum++;
INTCONbits.TMR0IF=0;
}
 
 
 
#pragma code highvector=0x08
void highvector(void)
{
 
_asm goto foo _endasm
}
#pragma code
 
I'm not sure just reading ADRES will give you the full value. I think you really need the ReadADC function unless you go through the rest of the code to read it manually without the library function.

If you don't want to use the C18 functions in a isr ADRES will give you the complete value.

From the p18f2550.h file:

extern volatile near unsigned ADRES;
extern volatile near unsigned char ADRESL;
extern volatile near unsigned char ADRESH;

One of the main problem with his original ADC code was reading the wrong 8 bit value into a char variable and doing operations on that variable that required at least an int variable to hold the results.
 
No! the original problem was that the variable FARE was only a byte... as soon as it was filled, the OP then multiplied it by 100 then divided it by 255... oh dear... 'zero'

sorry..nsaspook... missed that last bit....At least it was found.
 
Last edited:
No! the original problem was that the variable FARE was only a byte... as soon as it was filled, the OP then multiplied it by 100 then divided it by 255... oh dear... 'zero'

sorry..nsaspook... missed that last bit....At least it was found.

I saw the FARE variable problem at my first reply but decided to give him a hint (ADRES is a unsigned int ) instead of just telling him what to do. Lessons learned by head banging usually stick.
 
Hey It was just the compiler that didnt work on my computer proper Im using Hi-Tech again it works fine now, Well the ADC isnt working now im still trying to fix something for some reason with the ADCONX bits being setup the PIC freezes and after reboot half the code is missing...
 
The ADC still does not function. I really am stuck here... The input voltage is around 0.20 volts is this enough to make it work? I have plugged it into power VDD directly and it reads nothing... This read 100% on a 16F887...
Any other suggestions ? Thanks.

Didnt notice there was a second page -.- but anyways ill try that. (this code worked fine on the 16f887)
 
Last edited:
No! the original problem was that the variable FARE was only a byte... as soon as it was filled, the OP then multiplied it by 100 then divided it by 255... oh dear... 'zero'
Oh gosh. I showed kyle how to scale numbers without talking about data types first. At what point is it safe to talk about anything? That was rhetorical.
 
Yes 3V0... ok.... I'll eat my words... Sorry Kylemaes... nsaspook and myself were talking about this... via PM.... we were hoping you would pick it up....

This is exactly the issue your addressing in "get help".... It wont happen again.
 
  • Like
Reactions: 3v0
You guys are being confusing... What is the problem here is the new code...

Code:
#include <p18f2550.h>
#include <delays.h>
#pragma config  PLLDIV = 12, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = HS, FCMEN = OFF, IESO = OFF
#pragma config  PWRT = ON,  BOR = OFF, VREGEN = ON, WDT = OFF, PBADEN = OFF,  LPT1OSC = OFF,  MCLRE = OFF
#pragma config  STVREN = OFF,  LVP = OFF, DEBUG = OFF
#define E RA5
#define RS RA4
#define RW RA3
char interruptnum = 0;
char huns;
char remain;
char tens;
char ones;
char fare;
char huns2;
char tens2;
char ones2;
char menu=1;
char prognametimes =0;
//__EEPROM_DATA(1,2,3,4,5,6,7,8); how to write to eeprom without using programmemory



const char ScreenData[10] = {
0x30, //0 28
0x31, //1 29
0x32, //2 30
0x33, //3 31
0x34, //4 32
0x35, //5 33
0x36, //6 34
0x37, //7 35
0x38, //8 36
0x39, //9 37
};

void Strobe_LCD()
{
	E=1; 
	_delay(9000);
    E=0;
}
/**********************************************************/

void Busy_Flag() 
{ 
  RW = 1;     //read mode
  while(RB7);     //Loop until finished 
  RW=0;       //default to write mode... 
} 

void Write_LCD(unsigned char d,unsigned char x)			//USE "Write_LCD(tabledata,1=cap0=lowercase);" (IF number Cap selection must equal 0!)
{
TRISB=0x0F;
PORTB = d; //put data on output Port
Strobe_LCD(); //Clock lower 4 bits
d = d<<4; //Shift over by 4 bits
PORTB = d; //put data on output Port
Strobe_LCD(); //Clock upper 4 bits
}

void Command(unsigned char c) 
{ 
  TRISB=0x0F;
  RW = 0;     //write mode
  RS=0;       //command mode
  PORTB=c;     //place data on data port
  Strobe_LCD();
  c=c<<4;
  PORTB=c;
  Strobe_LCD();
  RS=1;
  TRISB = 0x0F;    //PORTB input
}

void lcd_init()
{
	RS=0;
PORTB = 0x30; //put 0x30 on the output port
_delay(300); //must wait 5ms, busy flag not available
Strobe_LCD(); //command 0x30 = Wake up
_delay(100); //must wait 160us, busy flag not available
Strobe_LCD(); //command 0x30 = Wake up #2
_delay(100); //must wait 160us, busy flag not available
Strobe_LCD(); //command 0x30 = Wake up #3
_delay(100); //can check busy flag now instead of delay
PORTB= 0x20; //put 0x20 on the output port
Strobe_LCD(); //Function set: 4-bit interface

Write_LCD(0x28,1); //Function set: 4-bit/2-line
Write_LCD(0x10,1); //Set cursor
Write_LCD(0x0F,1); //Display ON; Blinking cursor
Write_LCD(0x06,1); //Entry Mode set
}



programname()
{
			RS=1;
			Write_LCD('C',1);
			Write_LCD('o',1);
			Write_LCD('m',1);
			Write_LCD('p',1);
			Write_LCD('o',1);
			Write_LCD('s',1);
			Write_LCD('t',1);
			Write_LCD('e',1);
			Write_LCD('r',1);
			Write_LCD(' ',1);
			Write_LCD(' ',1);
			Write_LCD('V',1);
			Write_LCD('e',1);
			Write_LCD('r',1);
			Write_LCD(':',1);
			Write_LCD('2',1);
			prognametimes=1;


	RS = 0;
}



void main()
{
	TRISA=0b11000111;
	TRISB=0x00;
	TRISC=0x00;
	ADCON0=0xE0;
	lcd_init();
	programname();
/*************************/
	ADRESL=0;
	ADRESH=0;
ADCS2=1;
ADCS1=1;
ADCS0=0;
VCFG1=0;
VCFG0=0;
PCFG3=1;
PCFG2=1;
ADFM=1;
ACQT0=1;
ACQT1=1;
ACQT2=1;
CHS0=1;
ADON=1;

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



	while(1)
	{
		if(menu==1)
		{
			RS=0;
			Command(0xD0);
			RS=1;
			Write_LCD('M',1);
			Write_LCD('e',1);
			Write_LCD('n',1);
			Write_LCD('u',1);
			Write_LCD(':',1);
			Write_LCD('1',1);
			Write_LCD('/',1);
			Write_LCD('2',1);
			RS=0;
			GO=1;
			while(GO);			//GET TEMP DATA!
			fare = ADRESL;		//TEMPERATURE CONVERSION
			fare = fare*100;
			fare = fare/255;
			huns = fare/100;
			remain = fare-(huns*100);
			tens = remain/10;
			ones = remain - (tens*10);
			RS=0;
			Command(0xC0);			//Temp Second line
			RS=1;
			Write_LCD('T',1);
			Write_LCD('e',1);
			Write_LCD('m',1);
			Write_LCD('p',1);
			Write_LCD('e',1);
			Write_LCD('r',1);
			Write_LCD('a',1);
			Write_LCD('t',1);
			Write_LCD('u',1);
			Write_LCD('r',1);
			Write_LCD('e',1);
			Write_LCD(':',1);
			Write_LCD(ScreenData[tens],1);
			Write_LCD(ScreenData[tens],1);
			Write_LCD(ScreenData[ones],1);
			Write_LCD(0xDF,1); //Degrees sign
			RS=0;
		}
		if(menu==2)
		{
			RS=0;
			Command(0xD0);
			RS=1;
			Write_LCD('M',1);
			Write_LCD('e',1);
			Write_LCD('n',1);
			Write_LCD('u',1);
			Write_LCD(':',1);
			Write_LCD('2',1);
			Write_LCD('/',1);
			Write_LCD('2',1);
			RS=0;
			RS=0;
			Command(0xC0);			//Temp Second line
			RS=1;
			Write_LCD('H',1);
			Write_LCD('u',1);
			Write_LCD('m',1);
			Write_LCD('i',1);
			Write_LCD('d',1);
			Write_LCD('i',1);
			Write_LCD('t',1);
			Write_LCD('y',1);
			Write_LCD(':',1);
			Write_LCD(ScreenData[tens2],1);
			Write_LCD(ScreenData[tens2],1);
			Write_LCD(ScreenData[ones2],1);
			Write_LCD('%',1);
			RS=0;
		}
if(RC0==1)
	{
	Command(0x01);
	menu++;
	if(menu==3){menu=1;}
	programname();
	Delay10KTCYx(79999);
	
	}

		}
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top