📄 lcd.c
字号:
#include "config.h"
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#define LCD_BUSY_STAT (1<<7)
#define LCD_ONOFF_STAT (1<<5)
/*unsigned char lcd_read_stat(void)
{
unsigned char ret;
clr_LCD_E;
set_LCD_RW;
clr_LCD_DI;
set_LCD_E;
_delay_us(1);
ret = LCD_DATA;
clr_LCD_E;
_delay_us(1);
return ret;
}
*/
void lcd_read_stat(void)
{
LCD_DATA_DDR = 0x00;
clr_LCD_E;
set_LCD_RW;
clr_LCD_DI;
set_LCD_E;
_delay_us(0.5);
while(LCD_DATA_PIN&0X80);
clr_LCD_E;
LCD_DATA_DDR = 0Xff;
}
void lcd_write_cmd(unsigned char cmd)
{
lcd_read_stat();
clr_LCD_E;
clr_LCD_RW;
clr_LCD_DI;
LCD_DATA = cmd;
set_LCD_E;
_delay_us(0.5);
clr_LCD_E;
_delay_us(0.5);
}
void lcd_write_data(unsigned char x, unsigned char y,
unsigned char *buf, unsigned char lenth)
{
lcd_write_cmd(0xb8+(x%8));
lcd_write_cmd(0x40+(y%64));
while (lenth--)
{
lcd_read_stat();
clr_LCD_RW;
set_LCD_DI;
LCD_DATA =*buf++;
set_LCD_E;
_delay_us(0.5);
clr_LCD_E;
_delay_us(0.5);
}
}
uint8_t *read_rom(const prog_uchar *__data, uint16_t __size)
{
uint8_t *__p, *__tmp;
__p = (uint8_t *) malloc(__size);
__tmp = __p;
while (__size--)
*__tmp++ = pgm_read_byte(__data++);
return __p;
}
void write(uint8_t __x, uint8_t __y,
const prog_uchar *__data, uint16_t __size)
{
uint8_t *__p = read_rom(__data, __size);
lcd_write_data(__x, __y, __p, __size);
free(__p);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -