LCD.c文件呢
时间: 2023-12-20 14:03:18 浏览: 23
好的,这里提供一个LCD.c文件的示例代码,其中包含了与LCD相关的函数实现:
```
#include<lcd.h>
void delay_ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<125;j++);
}
}
void lcd_init()
{
delay_ms(15);
lcd_command(0x38); //设置16x2显示,5x7点阵,8位数据接口
lcd_command(0x0c); //开启显示,无光标
lcd_command(0x06); //文字从左到右滚动
lcd_command(0x01); //清屏
}
void lcd_command(unsigned char command)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_DATA = command;
LCD_EN = 1;
delay_ms(2);
LCD_EN = 0;
}
void lcd_putc(unsigned char c)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = c;
LCD_EN = 1;
delay_ms(2);
LCD_EN = 0;
}
void lcd_puts(unsigned char *s)
{
while(*s)
{
lcd_putc(*s++);
}
}
void lcd_clear()
{
lcd_command(0x01); //清屏
}
void lcd_gotoxy(unsigned char x, unsigned char y)
{
unsigned char address;
if(y==0)
{
address = x;
}
else
{
address = x + 0x40;
}
lcd_command(address | 0x80);
}
void lcd_bcd(unsigned char num)
{
lcd_putc(num/10+'0');
lcd_putc(num%10+'0');
}
```
这个文件实现了与LCD相关的函数。它包括了一些延时函数,以及初始化LCD、发送命令、发送字符、清除屏幕、设置光标位置等函数。你需要根据你的硬件设置,修改LCD_RS、LCD_RW、LCD_EN、LCD_DATA的引脚定义。将这个文件与lcd.h一起添加到你的项目中,并确保在你的代码中包含它们。