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.

Help with school project

Status
Not open for further replies.
May I suggest that you go through your code and indent it properly. When code is indented it is much easier to see mistakes etc. Poorly indented code is very hard to follow.

Mike.
 
This bit of the code gets run over and over again as long as RC2 = 1 (as long as you hold the button) so it will keep buzzing as long as you hold the button.
One way to solve this is to check for the button to be released first before allowing this part of the code to be executed again.

Code:
   if(PORTCbits.RC2==1)
    {
    PORTD=0xFF;

    lcd_init();					// Initialise LCD module

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


    lcd_write_cmd(0x80);

  	lcd_write_data('E');

	lcd_write_data('N'); 		// write "A" to LCD

  	lcd_write_data('T');		// write "B" to LCD

	lcd_write_data('R'); 		// write "C" to LCD

    lcd_write_data('Y');

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

	lcd_write_data('D'); 		// write "1" to LCD

 	lcd_write_data('E');		// write "2" to LCD

	lcd_write_data('N'); 		// write "3" to LCD

    lcd_write_data('I');

    lcd_write_data('E');

    lcd_write_data('D');

    PORTCbits.RC1=1;
    int p;

	for(p=0;p<2;p++)
	{
      		  onetone();

		Delay1KTCYx(250);
	} 
    [color=red]
    Add code here to check for button beeing released before continuing    [/color]
    }
 
Last edited:
Another way that won't tie up your processor is to do something like:
Code:
if(PORTC.RC2 == 1 && oldState == 0)
{
    //code

    oldState = 1;
}
 
Status
Not open for further replies.

Latest threads

Back
Top