View previous topic :: View next topic |
Author |
Message |
HardWorkingStudent
Joined: 06 Feb 2008 Posts: 3
|
LCD wont do what I want! |
Posted: Wed Feb 06, 2008 1:20 pm |
|
|
Hello everyone I am trying to program an 8-bit LCD 2 by 16 character display and I need it to do the following:
1.)On power up display a message on the first line
2.)On first push of button it should display a new message on the first line.
3.)On second push of the same button it should display a message on the second line
Then for every subsequent press of the button it should loop from 2.) to 3.) forever.
Sorry the PIC I am using is the 16F648A.
I have tried like every type of condition statements (C programing language) but the program will simply not recognise that the button has been previously been pressed. I know the solution is probably so simple but I cant for life of me find the solution!
I'll just include the main program
Code: |
void main()
{
int i;
int counter = 0;
char const message[10]={'G', 'R','O', 'U', 'P', '-','F', 'I', 'V', 'E'};
lcd_init(); // Carry out initialise function
printf(lcd_putc,"\fPower UP!");//initialise message
delay_ms(1000);
while(1)
{
if (lcd.input==1)
{
if(counter==0)
{
lcd_send_byte(0,0x01); // clears screen
for(i=0;i<10;i++)
{
lcd_putc(message[i]);
delay_ms(500);
}
counter = 1;
delay_ms(1000);
}
else(counter==1);
{
lcd_send_byte(0,0x01); // clears screen
lcd_gotoxy(1,2);// go to line 2
printf(lcd_putc, "\fGROUP-FIVE");
counter = 0;
delay_ms(1000);
}
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 06, 2008 2:05 pm |
|
|
If you want to wait for push-button input, then use a routine such as
wait_for_keypress() in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=19874
Just call it, and the program will wait until you press the push-button.
Then it will proceed. There is sample code in that post that shows how
to use it. Also read the instructions on how to connect the push-button
and the required pull-up resistor. |
|
|
kolio
Joined: 06 Feb 2008 Posts: 26
|
|
Posted: Fri Feb 08, 2008 5:35 am |
|
|
Try "if(lcd.input==0)" instead of "if(lcd.input==1)".
Good luck,
Kolio |
|
|
HardWorkingStudent
Joined: 06 Feb 2008 Posts: 3
|
|
Posted: Sat Feb 09, 2008 12:29 am |
|
|
PCM programmer wrote: | If you want to wait for push-button input, then use a routine such as
wait_for_keypress() in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=19874
Just call it, and the program will wait until you press the push-button.
Then it will proceed. There is sample code in that post that shows how
to use it. Also read the instructions on how to connect the push-button
and the required pull-up resistor. |
Code: | #define debounce 30//set time to wait while debouncing occurs (should be between 20ms & 30ms)
#define waitinputtime 1000//set time to wait after button press (1 second)
|
Code: | void inputpressed()//Detects if input pressed
{
if (input_high(PIN_A3))//If button is pressed on rising edge then do the following:
{
delay_ms(debounce);
delay_ms(waitinputtime);
}
else if (input_low(PIN_A3))//If button pressed on the falling edge then do the following:
{
delay_ms(debounce);
delay_ms(waitinputtime);
}
} |
I haven't tried implementing this yet but is this what you meant for a routine. I dont fully understand switch debounce and am not sure what the routine must do. Does the routine need to increment and decrement a counter? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 09, 2008 12:40 am |
|
|
I don't know. None of the code you posted is in the link that I gave.
It's clear that you want to use your own code, so go ahead. |
|
|
HardWorkingStudent
Joined: 06 Feb 2008 Posts: 3
|
|
Posted: Sat Feb 09, 2008 12:56 am |
|
|
PCM programmer wrote: | I don't know. None of the code you posted is in the link that I gave.
It's clear that you want to use your own code, so go ahead. |
Code: | #define DEBOUNCE_PERIOD_IN_MS 10
#define DEBOUNCE_COUNT 2 |
Code: | void wait_for_keypress(void)
{
char count;
count = 0;
while(1)
{
if(input(PIN_A3) == 1)
count++;
else
count = 0;
if(count == DEBOUNCE_COUNT)
break;
delay_ms(DEBOUNCE_PERIOD_IN_MS);
}
count = 0;
while(1)
{
if(input(PIN_A3) == 0)
count++;
else
count = 0;
if(count == DEBOUNCE_COUNT)
break;
delay_ms(DEBOUNCE_PERIOD_IN_MS);
}
} |
Well if my switch input is on RA3 and would this work?
Also why has count been declared as a char? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 09, 2008 1:50 am |
|
|
A 'char' is an unsigned 8-bit integer in CCS. |
|
|
|