📄 main.c
字号:
// Khai bao cac file header
#include <AT89X52.H>
#include <Kit8051.h>
// Khai bao cac bien toan cuc
unsigned char code string1[] = "Truong CDSP HN";
unsigned char code string2[] = "8051 Starter Kit";
// Khai bao cac ham
void InitSystem(void);
void Delay(unsigned int n);
void InitLCD(void);
void WriteCommand(unsigned char command);
void WriteCharacter(unsigned char character);
void WriteLCD(unsigned char x);
void SendString2LCD(unsigned char code *p);
void DisplayText(void);
// Dinh nghia cac ham
void InitSystem(void)
{
// Cam LCD
LCD_E = 0;
// Sang den backlight
LCD_BL = 0;
// Tre de LCD tu khoi tao ben trong (it nhat 15ms)
Delay(100);
// Tat den backlight
LCD_BL = 1;
InitLCD();
}
void Delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}
void InitLCD(void)
{
WriteCommand(0x30);
WriteCommand(0x30);
WriteCommand(0x30);
// 8 bit, 2 lines, font 5x7
WriteCommand(0x38);
// Display on, hide cursor
WriteCommand(0x0C);
// Xoa man hinh
WriteCommand(0x01);
}
void DisplayText(void)
{
// Dich con tro den vi tri thu 2, dong thu nhat
WriteCommand(0x81);
SendString2LCD(string1);
// Dich con tro den dau dong thu hai
WriteCommand(0xC0);
SendString2LCD(string2);
}
void WriteLCD(unsigned char x)
{
LCD_RW = 0;
LCD_DATA = x;
LCD_E = 1;
LCD_E = 0;
Delay(5);
}
void WriteCommand(unsigned char command)
{
LCD_RS = 0;
WriteLCD(command);
}
void WriteCharacter(unsigned char character)
{
LCD_RS = 1;
WriteLCD(character);
}
void SendString2LCD(unsigned char code *p)
{
unsigned char i=0;
while(p[i]!=0)
{
WriteCharacter(p[i]);
i++;
Delay(200);
}
}
// Chuong trinh chinh
void main(void)
{
// Khoi tao he thong
InitSystem();
DisplayText();
// Vong lap vo tan
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -