Advertisement
anota

ko biet

Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. //??
  2. /*
  3. * LCD_FUNC.h
  4. *
  5. * Created on: Mar 29, 2017
  6. * Author: Administrator PC
  7. */
  8.  
  9. #ifndef LCD_FUNC_H_
  10. #define LCD_FUNC_H_
  11.  
  12. #include "stdio.h"
  13. #include "stdbool.h"
  14. #include "stdint.h"
  15. #include "inc/hw_types.h"
  16. #include "inc/hw_memmap.h"
  17. #include "driverlib/sysctl.h"
  18. #include "driverlib/gpio.h"
  19.  
  20. //RS=1->nhap lenh, RS=0->nhap du lieu
  21. #define LCD_RS GPIO_PIN_1
  22.  
  23. //R/W
  24. #define LCD_RW GPIO_PIN_2
  25.  
  26.  
  27. //Enable
  28. #define LCD_E GPIO_PIN_3
  29.  
  30. //data
  31. #define LCD_D4 GPIO_PIN_4
  32. #define LCD_D5 GPIO_PIN_5
  33. #define LCD_D6 GPIO_PIN_6
  34. #define LCD_D7 GPIO_PIN_7
  35.  
  36. //Display LCD
  37. #define CLEAR 0x01
  38. #define HOME 0x02
  39. #define CURSOR_SHIFT_L 0x04
  40. #define CURSOR_SHIFT_R 0x06
  41. #define DISPLAY_SHIFT_R 0x05
  42. #define DISPLAY_SHIFT_L 0x07
  43. #define CURSOR_DISPLAY_OFF 0x08
  44. #define DOFF_CON 0x0A
  45. #define DON_COFF 0x0C
  46. #define DON_BLINKC 0x0E
  47. #define SHIFT_ALL_L 0x18
  48.  
  49. //Function
  50. void lcd_init(void); //khoi dong lcd
  51. void lcd_clear(void); //xoa man hinh lcd
  52. void lcd_gotoxy(unsigned char col, unsigned char row); //dich chuyen con tro toi vi tri co toa do (x,y)
  53. void lcd_delay_ms(unsigned long t); //delay t ms
  54. void lcd_dd_mm_yy(int d, int m, int y); //hien thi ngay thang nam
  55. void lcd_hh_mm_ss(int h, int m, int s); //hien thi gio phut giay
  56. void lcd_send_byte(signed char add, signed char n); //gui 1 byte len lcd
  57. void lcd_putc(unsigned int X);
  58. int LCD_DX[4] = {LCD_D4,LCD_D5,LCD_D6,LCD_D7};
  59.  
  60. #endif /* LCD_FUNC_H_ */
  61.  
  62. //===============================================================================================================================
  63. //===============================================================================================================================
  64. //===============================================================================================================================
  65. /*
  66. * LCD_FUNC.c
  67. *
  68. * Created on: Mar 29, 2017
  69. * Author: Administrator PC
  70. */
  71. #include "LCD_FUNC.h"
  72. #include "stdio.h"
  73. #include "stdbool.h"
  74. #include "stdint.h"
  75. #include "inc/hw_types.h"
  76. #include "inc/hw_memmap.h"
  77. #include "driverlib/sysctl.h"
  78. #include "driverlib/gpio.h"
  79.  
  80. void lcd_init()
  81. {
  82. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  83. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,LCD_RS|LCD_E|LCD_RW|LCD_D4|LCD_D5|LCD_D6|LCD_D7);
  84. GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,0);
  85. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
  86. lcd_delay_ms(200);
  87. lcd_delay_ms(2);
  88. lcd_send_byte(0,0x38); //5x7,multi
  89. lcd_delay_ms(2);
  90. lcd_send_byte(0,DON_BLINKC);
  91. lcd_delay_ms(2);
  92. lcd_send_byte(0,0x01);
  93. }
  94.  
  95. void lcd_clear()
  96. {
  97. lcd_send_byte(0,0x01);
  98. lcd_delay_ms(10);
  99. }
  100.  
  101. void lcd_gotoxy(unsigned char row, unsigned char col)
  102. {
  103. unsigned char address;
  104. if(row==1)
  105. address= 0x40 + col;
  106. else
  107. address = 0x80 + col;
  108. lcd_send_byte(0,address);
  109. lcd_delay_ms(1);
  110. }
  111.  
  112. void lcd_delay_ms(unsigned long t)
  113. {
  114. while(t--)
  115. {
  116. SysCtlDelay(SysCtlClockGet()/3000);
  117. }
  118. }
  119.  
  120. void lcd_dd_mm_yy(int dd, int mm, int yy)
  121. {
  122. int x= 0x3A;
  123. lcd_send_byte(1,dd);
  124. lcd_delay_ms(1);
  125. lcd_send_byte(1,x);
  126. lcd_delay_ms(1);
  127. lcd_send_byte(1,mm);
  128. lcd_delay_ms(1);
  129. lcd_send_byte(1,x);
  130. lcd_delay_ms(1);
  131. lcd_send_byte(1,yy);
  132. lcd_delay_ms(1);
  133. }
  134.  
  135. void lcd_hh_mm_ss(int hh, int mm, int ss)
  136. {
  137. int x = 0x3A;
  138. lcd_send_byte(1,hh);
  139. lcd_delay_ms(1);
  140. lcd_send_byte(1,x);
  141. lcd_delay_ms(1);
  142. lcd_send_byte(1,mm);
  143. lcd_delay_ms(1);
  144. lcd_send_byte(1,x);
  145. lcd_delay_ms(1);
  146. lcd_send_byte(1,ss);
  147. lcd_delay_ms(1);
  148. }
  149.  
  150. void lcd_send_byte(signed char add, signed char n)
  151. {
  152. int t,i;
  153. GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,0);
  154. if(add) GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,1);
  155. lcd_delay_ms(10);
  156. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
  157. for (i=0;i<4;i++)
  158. {
  159. t= n & (0x10<<i);
  160. GPIOPinWrite(GPIO_PORTF_BASE,LCD_DX[i],t);
  161. }
  162. lcd_delay_ms(1);
  163. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,1<<3);
  164. lcd_delay_ms(1);
  165. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
  166. for (i=0;i<4;i++)
  167. {
  168. t= n & (0x01<<i);
  169. GPIOPinWrite(GPIO_PORTF_BASE,LCD_DX[i],t);
  170. }
  171. lcd_delay_ms(1);
  172. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,1<<3);
  173. lcd_delay_ms(1);
  174. GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
  175.  
  176. }
  177.  
  178. void lcd_putc(unsigned int X)
  179. {
  180. lcd_send_byte(1,X);
  181. lcd_delay_ms(2);
  182. }
  183.  
  184.  
  185.  
  186. //================================== End of file ==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement