Mình đang cố đọc hiểu cách lập trình LCD qua C, nhưng mình không hiểu đoạn này lắm, rất mong được giải đáp:
mã lệnh "code" dùng để làm gì? và dấu "*" để diễn đạt điều gì?
Đoạn 2,
Nhất là cái câu LCD_PORT=cmd;
Đoạn 3:
Đặt tên biến kiểu *str là như thế nào?
Cả bài đó đây:
Code:
/* line1 to display on LCD */ code unsigned char *line1 = " noi dung 1 "; code unsigned char *line2 = " noi dung 2 "; code unsigned char *line3 = " noi dung 3 "; code unsigned char *line4 = " noi dung 4 ";
Đoạn 2,
Code:
void LCD_PutCmd(unsigned char cmd) { WaitReady(); // Wait for LCD ready WriteCommand; // set LCD to send mode LCD_PORT = cmd; // Prepare to send LatchData; // latch data out }
Đoạn 3:
Code:
void LCD_PrString(char *str) { while(*str!='\0') { LCD_PutChar(*str); ++str; } }
Cả bài đó đây:
Code:
/****************************************************************************/ /* */ /* File: lcd.c */ /* Author: Vu Ha Linh, Automatic Control Deparment */ /* Ha Noi university of technology */ /* */ /****************************************************************************/ /* */ /* Function: This module is a standard LCD (16x2) functions */ /* */ /* Input and Output parameters of those subroutines: */ /* void LCD_Init(void); */ /* void LCD_Position(unsigned char, unsigned char); */ /* void LCD_PutCmd(unsigned char); */ /* void LCD_PutChar(unsigned char); */ /* void LCD_PrString(char*); */ /* void LCD_Clear(void); */ /* void LCD_PrInteger(int); */ /* */ /* Note: Must be call LCD_Init() first at the begining of program */ /* */ /****************************************************************************/ /* */ /* History: */ /* Version: */ /* Date Writer Remark */ /* */ /* 30-07-2006 Vu Ha Linh Creating the first version */ /* */ /* */ /****************************************************************************/ #include <REGX51.H> #include "lcd.h" /***************************************************************************** define Hardware address it can changed by user *****************************************************************************/ #define LCD_PORT P1 sbit LCD_RS = P3^2; sbit LCD_RW = P3^3; sbit LCD_EN = P3^4; sbit LCD_D7 = P1^7; #define ReadCommand {LCD_RS = 0; LCD_RW = 1;} #define WriteCommand {LCD_RS = 0; LCD_RW = 0;} #define WriteData {LCD_RS = 1; LCD_RW = 0;} #define LatchData {LCD_EN = 1; LCD_EN = 0;} /**************************************************************************** WaitReady function Wait while LCD in execution time *****************************************************************************/ void WaitReady(void) { ReadCommand; // Set Read command mode LCD_D7 = 1; while(LCD_D7){ LCD_EN = 0; LCD_EN = 1; // Read bit D7 } } /**************************************************************************** LCD_PutCmd function Write a control byte to LCD Input : control byte *****************************************************************************/ void LCD_PutCmd(unsigned char cmd) { WaitReady(); // Wait for LCD ready WriteCommand; // set LCD to send mode LCD_PORT = cmd; // Prepare to send LatchData; // latch data out } /**************************************************************************** LCD_PutChar function Write a ASCII symbol to LCD Input: ASCII symbol *****************************************************************************/ void LCD_PutChar(unsigned char ch) { WaitReady(); WriteData; LCD_PORT = ch; LatchData; } /***************************************************************************** LCD_PrString function Write a string to LCD Input: string ******************************************************************************/ void LCD_PrString(char *str) { while(*str!='\0') { LCD_PutChar(*str); ++str; } } /***************************************************************************** LCD_Position function Set the position of cursor on LCD Input: row, column ******************************************************************************/ void LCD_Position(unsigned char row, unsigned char col) { LCD_PutCmd( (1<<7)|(row<<6)|col ); } /***************************************************************************** LCD_Clear function Clear LCD ******************************************************************************/ void LCD_Clear() { LCD_PutCmd(LCD_CLEAR); } /***************************************************************************** LCD_Init function Prepare for display content. Must be called at first ******************************************************************************/ void LCD_Init() { LCD_PutCmd(0x30); // Data length setting, 8 bits LCD_PutCmd(0x30); // Data length setting, 8 bits LCD_PutCmd(0x30); // Data length setting, 8bits LCD_PutCmd(LCD_FONT); // Function set: 8 bits, 2 lines, font 5x7 LCD_PutCmd(LCD_OFF); // Display and cursor OFF LCD_PutCmd(LCD_CLEAR); // Clear display LCD_PutCmd(LCD_MOVE_CURSOR); // Entry mode set: Increment mode, not shift LCD_PutCmd(LCD_DISPLAY_ON); // Display ON // LCD_PutCmd(LCD_BLINK_CURSOR); // Blink cursor } /**************************************************************************** LCD_PrInteger function Display a integer decimal number on LCD Input: a integer number *****************************************************************************/ void LCD_PrInteger(int num) { int temp; unsigned char i, c[5]; temp = num; if (temp != 0) { if (temp < 0) { LCD_PutChar('-'); temp = -temp; } i = 0; while(temp){ c[i++] = temp%10; temp /= 10; } while(i) LCD_PutChar(c[--i] + '0'); } else LCD_PutChar('0'); } /************************* END OF FILE *******************************/
Comment