File lcd.h

thienminh_npn

Thành Viên PIF
Hello các em, sáng nay em nào dùng chức năng shift trên lcd không được thì hãy dùng thử cái file lcd.h này View attachment lcd.rar nhé. Hồi nẩm học lớp C4 tụi anh cứ đắm đuối vì cái lỗi này.

Các em có thể dùng cách code sau đây để điều khiển Display, Cursor và Blink trên lcd.h này như sau:

lcd_put_byte(0, DON | CURSOR_UNDER_ON & BLINK_OFF), nghĩa là bật hiển thị và con trỏ, tắt nháy. Các define _OFF thì & còn _ON thì | nhé.

//LCD.H April 7th. Modified by Britsk

#ifndef _LCD_H_
#define _LCD_H_

#include <htc.h>

#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif


/* Display ON/OFF Control defines */
#define DON 0b00001100 /* Display on */
#define DOFF 0b11111011 /* Display off */
#define CURSOR_UNDER_ON 0b00001010 /* Cursor on */
#define CURSOR_UNDER_OFF 0b11111101 /* Cursor off */
#define BLINK_ON 0b00001001 /* Blink ON */
#define BLINK_OFF 0b11111110 /* Blink OFF*/

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT 0b00010000 /* Cursor shifts to the left */
#define SHIFT_CUR_RIGHT 0b00010100 /* Cursor shifts to the right */
#define SHIFT_DISP_LEFT 0b00011000 /* Display shifts to the left */
#define SHIFT_DISP_RIGHT 0b00011100 /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT 0b00101100 /* 4-bit Interface */
#define EIGHT_BIT 0b00111100 /* 8-bit Interface */
#define LINE_5X7 0b00110000 /* 5x7 characters, single line */
#define LINE_5X10 0b00110100 /* 5x10 characters */
#define LINES_5X7 0b00111000 /* 5x7 characters, multiple line */


/* Pins mapping */
#ifndef LCD_RS
#define LCD_RS RD1
#define LCD_EN RD3
#define LCD_RW RD2
#define LCD_DATA4 RD4
#define LCD_DATA5 RD5
#define LCD_DATA6 RD6
#define LCD_DATA7 RD7

#define LCD_RS_TRIS TRISD1
#define LCD_EN_TRIS TRISD3
#define LCD_RW_TRIS TRISD2
#define LCD_DATA4_TRIS TRISD4
#define LCD_DATA5_TRIS TRISD5
#define LCD_DATA6_TRIS TRISD6
#define LCD_DATA7_TRIS TRISD7
#endif

//typedef unsigned char unsigned char; // 8

-bit unsigned

typedef union _BYTE_VAL
{
unsigned char Val;
struct
{
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
} bits;
} BYTE_VAL;

void lcd_init();
unsigned char lcd_busy();
unsigned char lcd_get_byte(unsigned char rs);
void lcd_put_byte(unsigned char a,unsigned char b);
void lcd_gotoxy(unsigned char col, unsigned char row);
void lcd_putc(char c);
void lcd_puts(const char* s);
void lcd_clear();
#endif
 
Top