University projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
1.5 KiB

  1. /*
  2. * Authors: Sam Black, Sam Burras, Ben Francis
  3. *
  4. * Version 1.0 Date: 07/02/07
  5. *
  6. * Program to send strings to the LCD using
  7. * a 4-bit driver
  8. *
  9. */
  10. #include <16F648A.h>
  11. #include <string.h>
  12. #use delay(clock=4000000)
  13. #fuses NOWDT, INTRC_IO, NOPUT, NOPROTECT, NOLVP, NOMCLR
  14. #include "LCD_4BIT.H"
  15. char INITMESSAGE[16] = "How can I help?";
  16. char MESSAGE1[16] = "The answer?";
  17. char MESSAGE2[16] = "Forty Two.";
  18. char MESSAGE3[16] = " ?noitseuQ ehT";
  19. void send_string(int delay, char string[])
  20. {
  21. int i;
  22. /* send the string */
  23. for(i=0; string[i] != '\0'; i++)
  24. {
  25. lcd_putc(string[i]);
  26. delay_ms(delay);
  27. }
  28. }
  29. void send_string_reverse(int delay, char string[])
  30. {
  31. int i;
  32. /* send the string */
  33. for(i=14; i>=0; i--)
  34. {
  35. lcd_putc(string[i]);
  36. delay_ms(delay);
  37. }
  38. }
  39. int main(void)
  40. {
  41. /* Init the Display */
  42. lcd_init(2);
  43. /* Clear the screen */
  44. lcd_putc('\f');
  45. /* Send the message */
  46. send_string(5, INITMESSAGE);
  47. /* Display on the first line after button press */
  48. while(lcd.button == 1)
  49. { }
  50. lcd_putc('\f');
  51. send_string(1000, MESSAGE1);
  52. while(lcd.button == 1)
  53. { }
  54. lcd_putc('\f');
  55. /* New line */
  56. lcd_putc('\n');
  57. send_string(5, MESSAGE2);
  58. /* Add delay for button debouncing */
  59. delay_ms(500);
  60. /*wait for button press*/
  61. while(lcd.button == 1)
  62. { }
  63. /* Re-initialise the display to scroll */
  64. lcd_init(3);
  65. while(1) {
  66. send_string(200, MESSAGE3);
  67. }
  68. return 0;
  69. }