Continue to Site

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.

LCD Increment/Decrement help, urgent!!!

Status
Not open for further replies.

SixPathSage

Newbie level 2
Joined
Nov 17, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,318
I need my LCD to display Queue="number" , "number" starts at 0
1) "number" count up by 1 pressing button A // (PORTAbits.RA1==0);
2) "number" count down by 1 pressing button B // (PORTCbits.RC1==0);
Please help..
HTML:
void lcd_init(void)
{
    TRISD = 0x00;
    PORTD = 0x00;				// PORTD is connected to LCD data pin
    LCD_EN = 0;
    LCD_RS = 0;					// Select LCD for command mode
    LCD_WR = 0;					// Select LCD for write mode
   
    Delay10KTCYx(250);			// Delay a total of 1 s for LCD module to
    Delay10KTCYx(250);			//
    Delay10KTCYx(250);			//
    Delay10KTCYx(250);			// finish its own internal initialisation

    /* The data sheets warn that the LCD module may fail to initialise properly when
       power is first applied. This is particularly likely if the Vdd
       supply does not rise to its correct operating voltage quickly enough.

       It is recommended that after power is applied, a command sequence of
       3 bytes of 30h be sent to the module. This will ensure that the module is in
       8-bit mode and is properly initialised. Following this, the LCD module can be
       switched to 4-bit mode.
    */

    lcd_write_cmd(0x33);
    lcd_write_cmd(0x32);
      
    lcd_write_cmd(0x28);		// 001010xx ?Function Set instruction
    							// DL=0 :4-bit interface,N=1 :2 lines,F=0 :5x7 dots
   
    lcd_write_cmd(0x0E);		// 00001110 ?Display On/Off Control instruction
    							// D=1 :Display on,C=1 :Cursor on,B=0 :Cursor Blink on
   
    lcd_write_cmd(0x06);		// 00000110 ?Entry Mode Set instruction
    							// I/D=1 :Increment Cursor position
   								// S=0 : No display shift
   
    lcd_write_cmd(0x01);		// 00000001 Clear Display instruction
 
    Delay1KTCYx(20);			// 20 ms delay

}

unsigned int i;		/* 16 bit data type, range 0 to 65,535 */
unsigned char j;	/* 8 bit data type, range 0 to 255     */

void main(void)
{
// Do not remove these as well=============
	ADCON1 = 0x0F;				// Configure PORTA to be digital I/O
	CMCON = 0x07;
// ========================================
// Your MAIN program Starts here: =========

	TRISA = 0b11111111;
	TRISC = 0b11111111;
	
	lcd_init();					// Initialise LCD module

	LCD_RS = 1;					// Select LCD for character data mode
	Delay1KTCYx(1);				// 1 ms delay

	while(1)
	{


  	lcd_write_cmd(0x80);		// Move cursor to line 1 position 1

	lcd_write_data(0x51); 		// write "Q" to LCD

 	lcd_write_data(0x55);		// write "U" to LCD

	lcd_write_data(0x45); 		// write "E" to LCD

	lcd_write_data(0x55); 		// write "U" to LCD

 	lcd_write_data(0x45);		// write "E" to LCD

	lcd_write_data(0x3D); 		// write "=" to LCD


  	
	//while(1);					//stop here for now


	}

}
 

use a counter and increment or decrement depending upon up/down button pressed. convert the integer value of counter to char and display it on LCD.
 

I'm really a newbie at this.. mind writing one example for increment?

- - - Updated - - -

I tried to add a little, it seem to make the display go crazy..
HTML:
unsigned int i=0x30;		/* 16 bit data type, range 0 to 65,535 */
unsigned char j;	/* 8 bit data type, range 0 to 255     */

void main(void)
{
// Do not remove these as well=============
	ADCON1 = 0x0F;				// Configure PORTA to be digital I/O
	CMCON = 0x07;
// ========================================
// Your MAIN program Starts here: =========

	TRISA = 0b11111111;
	TRISC = 0b11111111;
	
	lcd_init();					// Initialise LCD module

	LCD_RS = 1;					// Select LCD for character data mode
	Delay1KTCYx(1);				// 1 ms delay

while(1)

	//modification point
{
//

//
  	lcd_write_cmd(0x80);		// Move cursor to line 1 position 1

	

	lcd_write_data(0x51); 		// write "Q" to LCD

 	lcd_write_data(0x55);		// write "U" to LCD

	lcd_write_data(0x45); 		// write "E" to LCD

	lcd_write_data(0x55); 		// write "U" to LCD

 	lcd_write_data(0x45);		// write "E" to LCD

	lcd_write_data(0x3D); 		// write "=" to LCD

	lcd_write_cmd(j); 		// write "Variable" to LCDD

	if (PORTAbits.RA1==0)
		{
		j=i++;
		//PORTDbits.RD0=1; // turn on LED at _____
                Delay10TCYx (250); // for a while
		}
		else if (PORTCbits.RC1==0)
		{
		j=i--;	
		//PORTDbits.RD1=1;
		Delay10TCYx (250); // for a while 
		}


  	
	//while(1);					//stop here for now


	}
					
}
 

Do something like this

Code:
void IntToStr(unsigned int intval);

//Global variables
unsigned int counter = 0;
unsigned char myString[6];

void IntToStr(unsigned int intval) {
        myString[0] = (befdec/10000) + 48;
        myString[1] = (befdec/1000)%10 + 48;
        myString[2] = (befdec/100)%10 + 48;
        myString[3] = (befdec/10)%10 + 48;
        myString[4] = (befdec/1)%10 + 48;
	myString[5] = '\0';
}

void main() {

while(1) {

if(PORTAbits.RA1 == 1) {
	Delay10TCYx (150);
	if(PORTAbits.RA1 == 1) {
                if(counter <= 65535) {
                            counter++;
                }
		
	}
}
else if(PORTCbits.RC1 == 1) {
	Delay10TCYx (150);
	if(PORTCbits.RC1 == 1) {
		 if(counter >= 0) {
                            counter--;
                }
	}
}


IntToStr(counter);
//myString contains the string equivalent of counter's value.
//Send it to LCD

}
}
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top