My version is the program shown on the right. It simply monitors the state of PORTA bit 0 and prints an appropriate message. It does this so quickly that the message appears to change instantaneously when the button is pressed. I use the & operator to split of the bottom bit of PORTA for the testing.
I hope you didn't forget the set up the ports correctly. The call of lcd_setup
will set up those ports needed by the LCD but I have added my own setup function to set up TRISA for PORTA.
Note how I have added spaces onto the end of the "up
" message so that the "wn
" part of the down message is erased each time the display is updated. Note also I am not clearing the display between redraws. If you do this the screen will flicker horribly.
Run project called Exercise 8.1. Press LA0 and note how the message changes.
/* Ex 8.1 Reaction Timer */
/* Rob Miles April 2000 */
#include <lcdlib.h>
void setup_hardware (void)
{
/* Set PortA to use digital inputs */
ANSELA = 0x00;
/* bits 0-4 of PORTA for input */
TRISA = 0x1f ;
}
const unsigned char down [5] =
{
'd','o','w','n',0x00
} ;
const unsigned char up [5] =
{
'u','p',' ',' ',0x00
} ;
void main ( void )
{
lcd_start () ;
setup_hardware () ;
while (1)
{
lcd_cursor ( 0, 0 ) ;
if ( PORTA & 0x01 )
{
lcd_print ( down ) ;
}
else
{
lcd_print ( up ) ;
}
}
}