Guest User

Untitled

a guest
May 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. //PIC16F887 - Internal Clock...
  2.  
  3. #define _XTAL_FREQ 8000000;
  4. #include <htc.h>
  5. __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRC_CLKOUT);
  6.  
  7. #define E RA0
  8. #define RS RA1
  9. #define RW RA2
  10.  
  11. /**********************************************************/
  12. const char ScreenData[38] = {
  13. 0x41, //A 0
  14. 0x42, //B 1
  15. 0x43, //C 2
  16. 0x44, //D 3
  17. 0x45, //E 4
  18. 0x46, //F 5
  19. 0x47, //G 6
  20. 0x48, //H 7
  21. 0x49, //I 8
  22. 0x4A, //J 9
  23. 0x4B, //K 10
  24. 0x4C, //L 11 //CHARACTER DEFINITIONS!
  25. 0x4D, //M 12
  26. 0x4E, //N 13 //ADD 32 TO GET LOWERCASE!
  27. 0x4F, //O 14
  28. 0x50, //P 15
  29. 0x51, //Q 16
  30. 0x52, //R 17
  31. 0x53, //S 18
  32. 0x54, //T 19
  33. 0x55, //U 20
  34. 0x56, //V 21
  35. 0x57, //W 22
  36. 0x58, //X 23
  37. 0x59, //Y 24
  38. 0x5A, //Z 25
  39. 0x20, //SPACE 26
  40. 0x3A, //: 27
  41. 0x30, //0 28
  42. 0x31, //1 29
  43. 0x32, //2 30
  44. 0x33, //3 31
  45. 0x34, //4 32
  46. 0x35, //5 33
  47. 0x36, //6 34
  48. 0x37, //7 35
  49. 0x38, //8 36
  50. 0x39 //9 37
  51. };
  52.  
  53. /**********************************************************/
  54.  
  55. void Busy_Flag()
  56. {
  57. RW = 1;
  58. TRISB=1;
  59. _delay(900);
  60. while(RB7==1)
  61. {
  62. //Loop until finished
  63. }
  64. RW=0; //always return to write mode...
  65. TRISB=0;
  66. }
  67. void Write_LCD()
  68. {
  69. E=1;
  70. _delay(5000);
  71. E=0;
  72. Busy_Flag();
  73. }
  74.  
  75. void AddressDisplay(unsigned char c)
  76. {
  77. RS=0;
  78. PORTB=c;
  79. Write_LCD();
  80. RS=1;
  81. }
  82.  
  83. /**********************************************************/
  84.  
  85. programname()
  86. {
  87. float a = 0x00;
  88. RS = 1;
  89. PORTB=ScreenData[2];
  90. Write_LCD();
  91. PORTB=ScreenData[14]+32;
  92. Write_LCD();
  93. PORTB=ScreenData[12]+32;
  94. Write_LCD();
  95. PORTB=ScreenData[15]+32;
  96. Write_LCD();
  97. PORTB=ScreenData[14]+32;
  98. Write_LCD();
  99. PORTB=ScreenData[18]+32;
  100. Write_LCD();
  101. PORTB=ScreenData[19]+32;
  102. Write_LCD();
  103. PORTB=ScreenData[4]+32;
  104. Write_LCD();
  105. PORTB=ScreenData[17]+32;
  106. Write_LCD();
  107. PORTB=ScreenData[26];
  108. Write_LCD();
  109. PORTB=ScreenData[26];
  110. Write_LCD();
  111. PORTB=ScreenData[21];
  112. Write_LCD();
  113. PORTB=ScreenData[4]+32;
  114. Write_LCD();
  115. PORTB=ScreenData[17]+32;
  116. Write_LCD();
  117. PORTB=ScreenData[27];
  118. Write_LCD();
  119. PORTB=ScreenData[29];
  120. Write_LCD();
  121. AddressDisplay(0x40);
  122. RS = 0;
  123. }
  124. /********************************************************/
  125. lcd_init()
  126. {
  127. PORTB = 0x0F;
  128. Write_LCD();
  129. _delay(500);
  130. PORTB = 0x01;
  131. Write_LCD();
  132. _delay(500);
  133. }
  134.  
  135. /********************************************************/
  136.  
  137. //2000 = 1ms
  138.  
  139. main()
  140. {
  141. TRISA=0;
  142. TRISB=0;
  143. TRISC=0;
  144. TRISD=0;
  145. TRISE=0;
  146. ANSEL=0;
  147. PORTA=0;
  148. PORTB=0;
  149. PORTC=0;
  150. PORTD=0;
  151. PORTE=0;
  152. E=1;
  153. lcd_init();
  154. programname();
  155. while(1){}
Add Comment
Please, Sign In to add comment