Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //??
- /*
- * LCD_FUNC.h
- *
- * Created on: Mar 29, 2017
- * Author: Administrator PC
- */
- #ifndef LCD_FUNC_H_
- #define LCD_FUNC_H_
- #include "stdio.h"
- #include "stdbool.h"
- #include "stdint.h"
- #include "inc/hw_types.h"
- #include "inc/hw_memmap.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/gpio.h"
- //RS=1->nhap lenh, RS=0->nhap du lieu
- #define LCD_RS GPIO_PIN_1
- //R/W
- #define LCD_RW GPIO_PIN_2
- //Enable
- #define LCD_E GPIO_PIN_3
- //data
- #define LCD_D4 GPIO_PIN_4
- #define LCD_D5 GPIO_PIN_5
- #define LCD_D6 GPIO_PIN_6
- #define LCD_D7 GPIO_PIN_7
- //Display LCD
- #define CLEAR 0x01
- #define HOME 0x02
- #define CURSOR_SHIFT_L 0x04
- #define CURSOR_SHIFT_R 0x06
- #define DISPLAY_SHIFT_R 0x05
- #define DISPLAY_SHIFT_L 0x07
- #define CURSOR_DISPLAY_OFF 0x08
- #define DOFF_CON 0x0A
- #define DON_COFF 0x0C
- #define DON_BLINKC 0x0E
- #define SHIFT_ALL_L 0x18
- //Function
- void lcd_init(void); //khoi dong lcd
- void lcd_clear(void); //xoa man hinh lcd
- void lcd_gotoxy(unsigned char col, unsigned char row); //dich chuyen con tro toi vi tri co toa do (x,y)
- void lcd_delay_ms(unsigned long t); //delay t ms
- void lcd_dd_mm_yy(int d, int m, int y); //hien thi ngay thang nam
- void lcd_hh_mm_ss(int h, int m, int s); //hien thi gio phut giay
- void lcd_send_byte(signed char add, signed char n); //gui 1 byte len lcd
- void lcd_putc(unsigned int X);
- int LCD_DX[4] = {LCD_D4,LCD_D5,LCD_D6,LCD_D7};
- #endif /* LCD_FUNC_H_ */
- //===============================================================================================================================
- //===============================================================================================================================
- //===============================================================================================================================
- /*
- * LCD_FUNC.c
- *
- * Created on: Mar 29, 2017
- * Author: Administrator PC
- */
- #include "LCD_FUNC.h"
- #include "stdio.h"
- #include "stdbool.h"
- #include "stdint.h"
- #include "inc/hw_types.h"
- #include "inc/hw_memmap.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/gpio.h"
- void lcd_init()
- {
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,LCD_RS|LCD_E|LCD_RW|LCD_D4|LCD_D5|LCD_D6|LCD_D7);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,0);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
- lcd_delay_ms(200);
- lcd_delay_ms(2);
- lcd_send_byte(0,0x38); //5x7,multi
- lcd_delay_ms(2);
- lcd_send_byte(0,DON_BLINKC);
- lcd_delay_ms(2);
- lcd_send_byte(0,0x01);
- }
- void lcd_clear()
- {
- lcd_send_byte(0,0x01);
- lcd_delay_ms(10);
- }
- void lcd_gotoxy(unsigned char row, unsigned char col)
- {
- unsigned char address;
- if(row==1)
- address= 0x40 + col;
- else
- address = 0x80 + col;
- lcd_send_byte(0,address);
- lcd_delay_ms(1);
- }
- void lcd_delay_ms(unsigned long t)
- {
- while(t--)
- {
- SysCtlDelay(SysCtlClockGet()/3000);
- }
- }
- void lcd_dd_mm_yy(int dd, int mm, int yy)
- {
- int x= 0x3A;
- lcd_send_byte(1,dd);
- lcd_delay_ms(1);
- lcd_send_byte(1,x);
- lcd_delay_ms(1);
- lcd_send_byte(1,mm);
- lcd_delay_ms(1);
- lcd_send_byte(1,x);
- lcd_delay_ms(1);
- lcd_send_byte(1,yy);
- lcd_delay_ms(1);
- }
- void lcd_hh_mm_ss(int hh, int mm, int ss)
- {
- int x = 0x3A;
- lcd_send_byte(1,hh);
- lcd_delay_ms(1);
- lcd_send_byte(1,x);
- lcd_delay_ms(1);
- lcd_send_byte(1,mm);
- lcd_delay_ms(1);
- lcd_send_byte(1,x);
- lcd_delay_ms(1);
- lcd_send_byte(1,ss);
- lcd_delay_ms(1);
- }
- void lcd_send_byte(signed char add, signed char n)
- {
- int t,i;
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,0);
- if(add) GPIOPinWrite(GPIO_PORTF_BASE,LCD_RS,1);
- lcd_delay_ms(10);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
- for (i=0;i<4;i++)
- {
- t= n & (0x10<<i);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_DX[i],t);
- }
- lcd_delay_ms(1);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,1<<3);
- lcd_delay_ms(1);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
- for (i=0;i<4;i++)
- {
- t= n & (0x01<<i);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_DX[i],t);
- }
- lcd_delay_ms(1);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,1<<3);
- lcd_delay_ms(1);
- GPIOPinWrite(GPIO_PORTF_BASE,LCD_E,0);
- }
- void lcd_putc(unsigned int X)
- {
- lcd_send_byte(1,X);
- lcd_delay_ms(2);
- }
- //================================== End of file ==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement