In the calls I made of the delay function above you will have noticed that there are no numbers. Instead I write things like:
lcd_delay ( PUTCH_DELAY) ;
This is so that I can make my code more readable and flexible. Rather than put numbers in the calls of delay I have used #define
d values which the pre-processor will insert for me. I can then indicate what the delay is doing by using an appropriate name and also easily change the value of the number if I change to a faster PICmicro. On the right you can see all the #define
d values used in the LCD code.
Note that I have also used #define
to indicate bit numbers and masks for use in the code.
/* masks for control bits */
#define RSMASK 0x10
#define EBIT 0x05
/* defined values for delays */
/* tested up to 20Mhz PICmicro */
/* standard write delay */
#define PUTCH_DELAY 250
/* clear and cursor home take */
/* longer - special delay for them */
#define CLEAR_DELAY 5000
/* delay to let the LCD settle */
#define POWER_UP_DELAY 10000
/* delay to let the ports settle */
#define BIT_DELAY 2