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.

USER INTERFACE:1 enter/settings switch,2switches->2digit value,LCD

Status
Not open for further replies.
I want to create a user interface using C programming for a pic microcontroller-see attached picture.

It will have 3 pushbutton switches. It will allow the user to enter a 2 digit value:

1.enter/settings switch

2.increase digit from 0 to 9

3.decrease digit from 9 to 0


If the user pushes the settings button then the user will go to a settings screen. The user can then select a 2 digit value EG. 99 or 34. The user can use the increase button to increase the first digit from 0 to 9 and 0 to 9 again. The first digit will be displayed on the LCD whilst the user is increasing. Thereafter the user can use the decrease button to decrease the second digit from 9 to 0 and 9 to 0 again. The second digit will be displayed on the LCD whilst the user is decreasing. So now the user has decided on a 2 digit value and wants to use this value in another function so the user presses ENTER and leaves the Settings screen.

Any1 with any useful ideas to approach this.

Code:
main()
{

int i;
TRISB= 0xFF;

i=0;
j=9;
while (1) {
     //wait for press

     while (RB6); 		 // loop  (1)
     DelayMs (30);  	          //debounce
     
     //wait for release   
     
     while (!RB6);		//loop(2)
     DelayMs(30);		 //debounce	
     i++;


     //wait for press

     while (RB4); 		 // loop  (1)
     DelayMs (30);  	          //debounce
     
     //wait for release   
     
     while (!RB4);		//loop(2)
     DelayMs(30);		 //debounce	
     j--;

}


how do i combine those digits to use in another function, shud i use a concatination function?
 

Attachments

  • user interface.PNG
    user interface.PNG
    6.4 KB · Views: 321
Last edited:
Select Case Statement is maybe the best way to go

case1
do this till it's true if true goto case 2
case1
next thing to do

Some thing like this
Code:
c=getch();
switch(c)
{
  case 0:
  {
    do something;
    break;
  }  case 1:
  {
    do something;
    break;
  }

  case 2:
  {
    do something;
    break;
  }
}
 
Last edited:
Heh i made a menu for my clock and i have to warn you this might get messy!

The switch function is a life saver! Make sure you use different functions and you can access variables across the code if needed. Im like 35% done with my clock and im at around 20 pages of code. Of course a few pages are just images for LCD but thats maybe 2-4 pages. So ive still got 16 pages of code :D

So what im saying as a tip is... document or PLAN it out well. If needed make a flow chart (not flow code) so you can picture out how the menus will operate. Once done with chart code just the menu stuff then code the actual work or things you need to be done.

As a example this is the code i have so far and i only have done the settings menu and the set time function. I still need Set Date, Alarm 1 and Alarm 2. The neat thing is i have 4 check boxes in my settings menu and when you press up or down it will check [X] the next box and clear the rest, this makes the user see whats being selected.


Code:
void MakeMenu(char mnu){
	unsigned char tPOS;
	tPOS = 0;

	switch(mnu){
	case 0:
		ClearBuff();
		LCDStringC((unsigned rom char*)"Settings",0,None,0,2);
		LCDStringC((unsigned rom char*)"  Time",0,None,2,2);
		LCDStringC((unsigned rom char*)"  Date",0,None,3,2);
		LCDStringC((unsigned rom char*)"  Alarm 1",0,None,4,2);
		LCDStringC((unsigned rom char*)"  Alarm 2",0,None,5,2);

		//Check Boxes
		LCDRect(16,2,7,7);
		LCDRect(24,2,7,7);
		LCDRect(32,2,7,7);
		LCDRect(40,2,7,7);

		//Outline
		LCDRect(0,0,95,63);
		LCDRect(8,0,95,1);
		LCDRect(9,0,95,1);
		LCDRect(61,0,95,1);
		LCDRect(62,0,95,1);

		SendBuff();
		break;
	case 1:
		done = 0;
		curPos = 0;
		while(!done){
			ClearBuff();
			done2 = 0;
			LCDStringC((unsigned rom char*)"Time",0,None,0,2);

			//Outline
			LCDRect(0,0,95,63);
			LCDRect(8,0,95,1);
			LCDRect(9,0,95,1);
			LCDRect(61,0,95,1);
			LCDRect(62,0,95,1);

			SendBuff();
			LCDStringB(Time,0,None,4,4);

			LCDString((unsigned rom char*)"Set: Hour High",0,None,2,4);
			while(!done2){
				MyButton = GetADC(0);
				if(MyButton == DOWN){
					switch(curPos){
						case 0:
							if(Time[0] == '0')
								Time[0] = '1';
							else
								Time[0] = '0';
							break;
						case 1:
							if(Time[0] > '0')
								if(Time[1] < '1')
									Time[1] = '0';
								else
									Time[1] = Time[1] - 1;
							else
								if(Time[1] < '1')
									Time[1] = '9';
								else
									Time[1] = Time[1] - 1;
							break;
						case 2:
							if(Time[3] == '0')
								Time[3] = '5';
							else
								Time[3] = Time[3] - 1;
							break;
						case 3:
						if(Time[4] == '0')
								Time[4] = '9';
							else
								Time[4] = Time[4] - 1;
							break;
						case 4:
							if(Time[6] == '0')
								Time[6] = '5';
							else
								Time[6] = Time[6] - 1;
							break;
						case 5:
						if(Time[7] == '0')
								Time[7] = '9';
							else
								Time[7] = Time[7] - 1;
							break;
						case 6:
							if(Time[10] == 'A')
								Time[10] = 'P';
							else	
								Time[10] = 'A';
						break;
					}
					DelayMS(250);
				}
				if(MyButton == UP){
					switch(curPos){
						case 0:
							if(Time[0] > '0')
								Time[0] = '0';
							else
								Time[0] = '1';
							break;
						case 1:
							if(Time[0] > '0')
								if(Time[1] > '1')
									Time[1] = '0';
								else
									Time[1] = Time[1] + 1;
							else
								if(Time[1] > '8')
									Time[1] = '0';
								else
									Time[1] = Time[1] + 1;
							break;
						case 2:
							if(Time[3] == '5')
								Time[3] = '0';
							else
								Time[3] = Time[3] + 1;
							break;
						case 3:
						if(Time[4] == '9')
								Time[4] = '0';
							else
								Time[4] = Time[4] + 1;
							break;
						case 4:
							if(Time[6] == '5')
								Time[6] = '0';
							else
								Time[6] = Time[6] + 1;
							break;
						case 5:
						if(Time[7] == '9')
								Time[7] = '0';
							else
								Time[7] = Time[7] + 1;
							break;
						case 6:
							if(Time[10] == 'A')
								Time[10] = 'P';
							else	
								Time[10] = 'A';
						break;
					}
					DelayMS(250);
				}
				if(MyButton == ENTER){
					if(curPos == 6){ 
						done  = 0xFF;
						done2 = 0xFF;
					}

					curPos++;
					switch(curPos){
						case 1:
							LCDString((unsigned rom char*)"Set: Hour Low ",0,None,2,4);
							break;
						case 2:
							LCDString((unsigned rom char*)"Set: Min High ",0,None,2,4);
							break;
						case 3:
							LCDString((unsigned rom char*)"Set: Min Low  ",0,None,2,4);
							break;
						case 4:
							LCDString((unsigned rom char*)"Set: Sec High ",0,None,2,4);
							break;
						case 5:
							LCDString((unsigned rom char*)"Set: Sec Low  ",0,None,2,4);
							break;
						case 6:
							LCDString((unsigned rom char*)"Set: AM or PM ",0,None,2,4);
							break;
					}

					DelayMS(250);
				}
				LCDStringB(Time,0,None,4,4);
				MyButton = 0;
			}
		}
		if(Time[10] == 'P')
			Hours = DECtoBCDB((Time[0]-0x30),(Time[1]-0x30),'h',1);
		else
			Hours = DECtoBCDB((Time[0]-0x30),(Time[1]-0x30),'h',0);

		Minutes = DECtoBCDB((Time[3]-0x30),(Time[4]-0x30),'m',0);
		Seconds = DECtoBCDB((Time[6]-0x30),(Time[7]-0x30),'m',0);

		WriteSPI(0x80, Seconds);
		WriteSPI(0x81, Minutes);
		WriteSPI(0x82, Hours);
		break;

	}
}
void settingPos(char pos){
	//Box 1
	LCDLine(16,2,23,9,0);
	LCDLine(23,2,16,9,0);
	//Box 2
	LCDLine(24,2,31,9,0);
	LCDLine(31,2,24,9,0);
	//Box 3
	LCDLine(32,2,39,9,0);
	LCDLine(39,2,32,9,0);
	//Box 4
	LCDLine(40,2,47,9,0);
	LCDLine(47,2,40,9,0);

	if(pos == 1){
		LCDLine(16,2,23,9,1);
		LCDLine(23,2,16,9,1);
	}
	if(pos == 2){
		LCDLine(24,2,31,9,1);
		LCDLine(31,2,24,9,1);
	}
	if(pos == 3){
		LCDLine(32,2,39,9,1);
		LCDLine(39,2,32,9,1);
	}
	if(pos == 4){
		LCDLine(40,2,47,9,1);
		LCDLine(47,2,40,9,1);
	}

	SendBuff();
}

Messy right?

Now since i know its ugly and hard to see what menu is selected i cut the code into pieces... now my menu code looks like:

Code:
void MakeMenu(char mnu){
	switch(mnu){
	case 0:
		DrawSettings();
		break;
	case 1:
		SetTime();
		break;
	case 2:
		//SetDate();
		break;
	case 2:
		//SetAlarm(1);
		break;
	case 2:
		//SetAlarm(2);
		break;
	}
}
 
Last edited:
Yeah thanks guys. Ill definitely use that approach. Neat:)
 
after i got the two single digits which the user selects by pushing a button,
how do i combine them into a single digit
. and display it onto a LCD???Im using a pic 16f690 and programming in C

EG

1st single digit=3 (this means user pushed button 3 times)
2nd single digit=5 (this means user pushed button 5 times)
2digit number=35 (i want to use this number to do mathematical calculations in the calc_distance function)

Any useful links?is this basically Converting a two-byte BCD into a single byte???
 
Last edited:
you want 3 and 5 to be 0x35 or decimal 35(0x23)? its easy here is how:

Leave the singles number aka 5.
You then use a 10 for the tens position so you would 10 * the 3
then add the singles to it aka 5

so:
Var1 = 3
Var2 = 5

var3 = 10*var1+var2

var3 = 35
 
i just reread your question. To place 2 digits on a LCD is easy. Can you write strings? How are you sending data to lcd. Can you post your char code ?

You can create a 2 byte var

MyNum[2] (2 bytes aka 0 and 1)

MyNum[0] = var1 (aka 3)
MyNum[1] = var2 (aka 5)

since these are decimals you need ascii so you would do:


MyNum[0] = var1 + 0x30
MyNum[1] = var2 + 0x30

Then a 2 byte loop to send it to LCD:
Code:
for(x=0;x<2;x++){
  LCDchar(MyNum[x]);
}
 
My LCD displays INFRARED LIQUID LEVEL DETECTOR
yeah i got a function /*write a string of chars to the LCD*/

here is the working code for LCD part

Code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
 
void FloatToStr(float , char[]);
void DelayMs(unsigned char);
void lcd_cmd(unsigned char);
void lcd_data(unsigned char); 
void lcd_clear(void);
void lcd_puts(const char[]);
void lcd_goto_L1(void);
void lcd_goto_L2(void);
void lcd_cursor(unsigned char);
void lcd_init(void);
void init(void);
void home_screen(void);


#define LCD_RS RC0		//LCD RS pin
#define LCD_EN RC1		//LCD EN pin
#define LCD_STROBE()	LCD_EN = 1; asm("nop"); asm("nop"); LCD_EN = 0

unsigned char cm10;		//
unsigned char cm;		//
unsigned int math;		// used for voltage calculations


unsigned char i,j,k;
char temp[8];


///////////////////////CONVERT FLOAT TO STRING///////////////////
// This function was taken from the CAVR library. It was modified slightly
// to suit my design.
void FloatToStr(float n, char str[])
{
float scale;
unsigned char d,f;
f=0;i=0;
if (n<0.0) {n=-n; str[f]='-'; f++;};
n=n+0.005;
scale=1.0;
while (n>=scale) {scale=scale*10.0; ++i;};
if (i==0) {str[f]='0'; f++;}
else
while (i--)
	  {
      scale=floor(0.5+scale/10.0);
      d=(unsigned char) (n/scale);
      str[f]=d+'0';
      n=n-scale*d;
	  f++;
      };

str[f]='.';
f++;
for (j=0;j<=1;j++) //2 decimal points
      {
      n=n*10.0;
      d=(unsigned char) n;
      str[f]=d+'0';
      n=n-d;
	  f++;
	  };
str[f]='\0';
}
///////////////////END CONVERT FLOAT TO STRING///////////////////

/////////////////////////////DELAY///////////////////////////////
void DelayMs(unsigned char cnt)
{
#if	XTAL_FREQ <= 2MHZ
	do {
		DelayUs(996);
	} while(--cnt);
#endif

#if    XTAL_FREQ > 2MHZ	
	unsigned char	p;
	do {
		p = 4;
		do { 
			DelayUs(250);
		} while(--p);
	} while(--cnt);
#endif
}

void DelayS(unsigned char cnt)
{
	for (j=0; j<(cnt*10); j++)
		DelayMs(100);
}
///////////////////////////DELAY END/////////////////////////////

//////////////////////////////LCD SETUP//////////////////////////
/* send a command to the LCD */
void lcd_cmd(unsigned char c)
{
	DelayMs(20); //wait for LCD to be ready
	LCD_RS = 0;	 //write instruction
	PORTB = (c & 0xF0); //load upper nibble on LCD data lines
	LCD_STROBE(); //send instruction to LCD
	PORTB = ((c << 4) & 0xF0); //load upper nibble on LCD data lines
	LCD_STROBE(); //send instruction to LCD   	
}

/* send data to the LCD */
void lcd_data(unsigned char c)
{
	DelayMs(20); //wait for LCD to be ready
	PORTB = 0x00;
	LCD_RS = 1; //write data
    PORTB |= (c & 0xF0); //load upper nibble on LCD data lines     
	LCD_STROBE(); //send instruction to LCD
	PORTB &= 0x00; //load upper nibble on LCD data lines
	PORTB |= ( (c << 4) & 0xF0); 
	LCD_STROBE(); //send instruction to LCD
}

/*Clear the LCD*/
void lcd_clear(void)
{
	lcd_cmd(0x01); //command to clear LCD
}

[B]/*write a string of chars to the LCD*/[/B]
void lcd_puts(const char s[])
{
	j = -1;
	while(s[++j]!=('\0')) // send characters until null character reached
		lcd_data(s[j]);
}

/*go to beginning of line 1*/
void lcd_goto_L1(void)
{
	lcd_cmd(0b10000000); // command to go to line 1
}

/*go to beginning of line 2*/
void lcd_goto_L2(void)
{
	lcd_cmd(0b11000000); // command to go to line 2
}

/*move cursor "x" positions to the right*/
void lcd_cursor(unsigned char x)
{
	lcd_cmd(((x)&0x7F)|0x80); 
}

/*initialise the LCD - put into 4 bit mode*/
void lcd_init(void)
{
	LCD_RS = 0;	
	LCD_EN = 0;
	DelayMs(20); //wait for LCD startup
	lcd_cmd(0x28);	// 4-bit mode
	lcd_cmd(0x08);	// display off
	lcd_cmd(0x01);	// clear display
	lcd_cmd(0x0C);	// disp. on, cursor off, cursor blink off
	lcd_cmd(0x06);	// entry mode
	lcd_cmd(0x80);  // initialise DDRAM address to zero
}
//////////////////////////LCD SETUP END//////////////////////////


 
  

void init(void)
{   OSCCON = 0x72;      	// internal osc, 8MHz

	PORTA = 0;
	TRISA = 0b10000010; 	// RA7 high imp, RA3 is serial out,
							// RA1 is ADC input measuring VR1
	PORTB = 0;
	WPUB = 1;
    RABPU = 0;

//	INTCON2 = 0;            // PORTB pullups ON
	TRISB = 0b00000000; 	// PORTB not used

	ADCON0 = 0b00000101;	// ADC ON, RA1 is ADC input
	ADCON1 = 0b01111101;	// AN1 is ADC input
//	ADCON2 = 0b10100010;	// right justify, 8Tad, 32Tosc

	T1CON = 0b00010001;     // TMR1 is ON, 1:2 prescale, =1MHz

//	T3CON = 0b00010001;     // TMR3 is ON, 1:2 prescale, =1MHz

	TRISC=0xFC;
	ANSEL=0x02;
	ANSELH=0x00;
	lcd_init();

	GIE=0;
	PORTA = 0x00;


}
  

   
void home_screen(void)
{
	lcd_clear();
	lcd_goto_L1();
	lcd_puts("INFRARED LIQUID"); //home screen message (line 1)
	lcd_goto_L2();
	lcd_puts("LEVEL DETECTOR"); //home screen message (line 2)
}

void calc_distance(void)
{
	// from the transeiver datasheet the analog voltage is
	// the inverse of distance, so distance can be calculated
	// d = (1 / volts) then just scaled to suit the transeiver

	// load ADC value in 16bit math var
	math = ADRESH;
	math = (math * 256);
	math += ADRESL;

	// now invert it; (1 / volts) use (6050 / volts) for scaling
	math = (6050 / math);
	if(math >= 2) math -=2;		// fix linear error (-2)
	if(math > 99) math = 99;	// max limit at 99cm

	// convert from 0-99 to 2 decimal digits, 0-99cm
	cm10=0;
	while(math >= 10)
	{
		cm10++;
		math -= 10;
	}
	cm = math;
}


 
void main(void)
{
	init();	// initialise I/O ports, LCD
	while (1)
	{
	home_screen();
   
	}
	 
}



since these are decimals you need ascii so you would do:

Ok so once i get the 2digit ascii onto the LCD, i need to use this 2digit ascii "number" to do mathematical calculations in another function??? so do i need to convert string to float now??

Thanks for your input AtomSoft...I saw your the video of your "clock menu" -Very Cool:)
 
Last edited:
Here is a simple solution...
Code:
/* ---------------------------------------------
ex: 
	ShowDigits(3,5);
	Displays 2 digit data to LCD
--------------------------------------------- */
void ShowDigits(unsigned char var1,unsigned char var2){
	var1 += 0x30;
	var2 += 0x30;

	lcd_data(var1);
	lcd_data(var2);
}
 
Code:
;#############################################################################
;#              VAULT INFORMATION SERVICES - 8052 CODE EXAMPLE               #
;#             (C) Copyright 1997 by Vault Information Services              #
;#                                                                           #
;# This code fragment is provided to the public free of charge and WITHOUT   #
;# OF ANY KIND,  NEITHER EXPRESS OR IMPLIED.   This code is offered as  an   #
;# example of  8052  programming.   VIS extends no warranty regarding  its   #
;# functionality or fitness for a specific purpose.;#                        #
;# The user may  utilize this code in  any way he/she sees fit,  including   #
;# using it in his/her own program,  commercial or otherwise.  However, by   #
;# using this  code the  user states his/her  acceptance of the  above and   #
;# holds  VIS indemnified against any and all claims that may arise due to   #
;# the use or misuse of this code.                                           #
;#############################################################################

;********************************************************************
;********************************************************************
;** Function: bcd_to_byte                                          **
;** Purpose:  Convert a two-byte BCD into a single byte            **
;** Input:    A    = Hi byte to convert (ASCII 0x30-0x39,0x41-0x46)**
;**           R0   = Lo byte to convert (ASCII 0x30-0x39,0x41-0x46)**
;** Output:   A    = Converted value (binary 0x00-0xFF)            **
;** Destroyed Registers: None                                      **
;********************************************************************
;********************************************************************
bcd_to_byte:
    XCH     A,R0
    SUBB    A,#30h
    JNB     ACC.4,bcd_to_byte_2
    SUBB    A,#07h
bcd_to_byte_2:
    XCH     A,R0
    SUBB    A,#30h
    JNB     ACC.4,bcd_to_byte_3
    SUBB    A,#07h
bcd_to_byte_3:
    SWAP    A
    ORL     A,R0
    RET

Ok so the VAR1 and VAR2 will appear as 35 in ascii and be displayed on the LCD.

Now the 2nd part:

I will need to read this value into the micro from the LCD???Right

I will read the high byte 3 and low byte 5 and i want the 2byte BCD to become a single byte which i can use for mathematical calculations.


I found this code, i think it would be applicable but 8052 and asm :( uhmmm confuses me, Any suggestions?
 
Last edited:
When the user select the numbers you should have that as a global variable. This way you can always edit it .

Here is code to turn 2 digits from user into a single number (decimal) like

Decimal 3 and 5 into 35(which is 0x23 in hex).

Code:
unsigned char Combine(unsigned char SinglePOS, unsigned char TenPOS){
   unsigned char wholeNum;
    wholeNum = SinglePOS + (TenPOS * 10);
    return wholeNum;
}

Something like that. Sorry i just redid my pc and need to install MPLAB and all
 
Here is a TIP:

1. Have a set of vars to use like...

unsigned char NumDec;
unsigned char NumSep[2];

Now you can use NumSep to store the user entered data and use NumDec to store the combined data. Like when a user enters the first digit save it in NumSep[0] and the second digit in NumSep[1]. Then you can use the Combine function like:
Code:
    NumDec = Combine(NumSep[0],NumSep[1]);

also you can use the LCD better like:

Code:
    ShowDigits(NumSep[0],NumSep[1]);
 
To Split the data is simple also heh

Code:
void SplitIt(unsigned char Number){
    unsigned char temp;

    temp = NumDec;
    NumSep[0] = temp /10;    //returns the quotient (if temp = 35 the result is 3)
    NumSep[1] = temp % 10; //Returns remainder   (if temp = 35 the result is 5)
}
 
Wow thankx alot, thats real useful stuff to know. Im going to start coding and implementing your ideas.:). I need to get the user interface working. Keep you posted. Appreciate you taking time to assist a beginner.
 
Last edited:
Thanks. Your C18 tips and tricks are very handy. Im going to have to pay alot forward lol. Im still working on the code-drew a detailed flowchart as you suggested:), multitasking-learning for a superconductivity test as well for tomorrow.
 
I got some push button switches & resistors. Im going to wire it to the pic and run the code today. This is the relevent parts of the code for the user interface.

Code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
 


unsigned char NumDec;
unsigned char NumSep[2];
 
unsigned char i,j,k;
char temp[8];
int height=50, SensorPos=10;
 
char input_sw;
#define HOME_SW RC2				//HOME switch	
#define INCREASE_SW RC3			//INCREASE switch
#define DECREASE_SW RC4			//DECREASE switch
#define ENTERSETTINGS_SW RA4	//ENTERSETTINGS switch

  
void read_input_sw(void)
{
 char input_sw2; 
 input_sw = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1)); //create a binary combination of the input switches
 if (input_sw != 0) //check if any of the switches are pressed
	{
	 DelayMs(20); //switch debouncing
	 input_sw2 = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1));
	 while (input_sw2 != 0) //if a switch is pressed wait for release
			{
			 input_sw2 = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1));
			 DelayMs(20); //switch debouncing
  			}
	 }
}

   
void home_screen(void)
{
	lcd_clear();
	lcd_goto_L1();
	lcd_puts("INFRARED LIQUID"); //home screen message (line 1)
	lcd_goto_L2();
	lcd_puts("LEVEL DETECTOR"); //home screen message (line 2)
	
}


//ShowDigits(3,5);
//	Displays 2 digit data to LCD
//--------------------------------------------- 
void ShowDigits(unsigned char var1,unsigned char var2){
	var1 += 0x30;
	var2 += 0x30;

	lcd_data(var1);
	lcd_data(var2);
}

 
//turn 2 digits from user into a single number (decimal) like
//Decimal 3 and 5 into 35(which is 0x23 in hex).

unsigned char Combine(unsigned char SinglePOS, unsigned char TenPOS){
   unsigned char wholeNum;
    wholeNum = SinglePOS + (TenPOS * 10);
    return wholeNum;
}
 
int enter_settings(void)
{ int Var1=0;
  int Var2=9;	
	do 
    {	read_input_sw();
		switch (input_sw)
		{
			case 8: goto a;
			case 4: { Var1++;  //incrementing 1st digit
					  NumSep[0]=Var1++;
					  break;
				    }
			case 2: { Var2--;  //decrementing second digit
					  NumSep[1]=Var2;	
					  break;
				    }
			default : goto a; //should any abnormalties occur
		}
 
	    	ShowDigits(NumSep[0],NumSep[1]);
	 }
	while (input_sw==1); //user presses enter/settings button when satisfied


     NumDec = Combine(NumSep[0],NumSep[1]);
   	 return NumDec;
	
a:
	return;
}
  
void menu(void)
{
	read_input_sw();
	while ((input_sw != 8)&(input_sw != 1))  //Wait for Home or enter/settings
	{
		lcd_clear();
		lcd_goto_L1();
		lcd_puts(" ENTER/SETTINGS ");
		DelayS(1);
		lcd_clear();
		ShowDigits(NumSep[0],NumSep[1]);
		lcd_clear();
		lcd_goto_L1();
		lcd_puts(" ENTER HEIGHT ");
		height=enter_settings();
		lcd_clear();
		lcd_goto_L1();
		lcd_puts(" ENTER SENSOR POSITION ");
		SensorPos=enter_settings();
			
	} 
}

oooh i gota include this in the case statements if var1>9 then var1=0.... and if var2<0 var2=9...i'll do that when i get home.

Let me know what you think of this code....Thanks
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top