NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » using pushbutton to clear lcd as reset

April 27, 2013
by uistrol_17
uistrol_17's Avatar

hey everyone i am trying to use pushbutton to clear the lcd( one in kit). the button is connected to PC3 as an input but i dont know what to do aftet that. please help uistrol_17

April 27, 2013
by pcbolt
pcbolt's Avatar

Hi uistrol_17 -

You should connect the smallest pin of the button to ground (blue rail) and the middle pin of the button to PC3 (you may have to use jumper wires to make the connection). Then in your code after "main()" but before "while(1)" add this code:

DDRC &= ~(1<<PC3);
PORTC |= (1<<PC3);

This will setup PC3 as an input and turn on a pullup resistor so that when no connection is made with ground, PC3 will be set to a high value (5 volts).

Next you just have to add a test inside the "while(1)" loop to test if PC3 ever goes low (when the button is pushed PC3 will be connected to ground and read low). You can do this with:

if ((PINC & (1<<PC3)) == 0){
  lcd_clear_and_home();
}
April 28, 2013
by uistrol_17
uistrol_17's Avatar

hey pc bolt, thanks for the sample, but i tried using these lines of code and placed the while loop in multiple locations to test it and the only result i get is either a continous reset(blank screen) or program runs but pressing switch results in nothing. what do you think?

April 28, 2013
by pcbolt
pcbolt's Avatar

17 -

Is this part of the morse code project you're working on? I posted some changes to that thread for you to look at. If not, you should post the code you are working on here so I can have a better look. When you paste your code, make sure you highlight it and use the "Indent Selection as Code Block" button right under the "Post a Reply" box.

Post a Reply

Please log in to post a reply.

Did you know that one NerdKits customer controlled a laser pointer with his computer using a microcontroller? Learn more...