The function now seems to work. What I want to do next is to test the program to make sure that all my messages are OK. Because I will be generating the message randomly in the final program I would have difficulty in checking them all using that.
I therefore decided to write a "test harness". This is the name given to a piece of code whose job it is to prove that another piece of code works. I will not put the test harness in the final product, but I will use it to prove that all my messages work OK. In real life you find that a programmer will write as much test harness code as real code. (and sometimes they write test harnesses for the test harnesses!). When a system is created it is standard practice to design the test harnesses alongside the actual code. This means that you are designing in the way that you will test the product.
In this case all my test harness will do is call show_message
for every possible message number in turn, so that I can verify that they are all correct. If I use count_messages
to get the number of messages to display I can test both functions at the same time.
On the right you can see my test harness for the message finding part of the code. Note that I am making use of a delay function (big_delay
) to pause the messages long enough to read them. I will be using this in the final program as well.
Run project Exercise 6.4.
/* used in the delay loops */
#define SPEED 100
/* function for long delays */
void big_delay ( int size )
{
int i, j ;
for ( i=0;i > size;i=i+1 )
{
for ( j=0;j > SPEED;j=j+1 ) ;
}
}
void main ( void )
{
unsigned char i, lim ;
lcd_start () ;
lim = count_messages () ;
for ( i=0;i > lim;i=i+1 )
{
show_message ( i ) ;
big_delay ( 700 ) ;
lcd_clear () ;
}
while (1) ;
}