📄 lcd_33102.h
字号:
#include <avr/io.h>
#include <avr/delay.h>
#define LCD_DC 0x08 // LCD第4脚, Mega16:PB3 第4脚
#define LCD_CE 0x10 // LCD第5脚, Mega16:PB4 第5脚
#define SPI_MOSI 0x20 // LCD第3脚, Mega16:PB5(MOSI) 第6脚
#define LCD_RST 0x40 // LCD第8脚, Mega16:PB6(MISO) 第7脚
#define SPI_CLK 0x80 // LCD第2脚, Mega16:PB7(SCK) 第8脚
void LCD_init(void);
void LCD_clear(void);
void LCD_OUT_FFT_DATA(int16_t *out_data) ;
void LCD_write_char(unsigned char c);
void LCD_write_byte(unsigned char data, unsigned char dc);
/*-----------------------------------------------------------------------
LCD_init : 3310LCD初始化
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_init(void)
{
PORTB &= ~LCD_RST; // 产生一个让LCD复位的低电平脉冲
_delay_us(2);
PORTB |= LCD_RST;
PORTB &= ~LCD_CE ; // 关闭LCD
_delay_us(2);
PORTB |= LCD_CE; // 使能LCD
_delay_us(2);
LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式
LCD_write_byte(0xc8, 0); // 设置偏置电压
LCD_write_byte(0x06, 0); // 温度校正
LCD_write_byte(0x12, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示
PORTB &= ~LCD_CE ; // 关闭LCD
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函数
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
/*-----------------------------------------------------------------------
LCD_set_XY : 设置LCD坐标函数
输入参数:X :0-83
Y :0-5
编写日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
编写日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char data, unsigned char command)
{
PORTB &= ~LCD_CE ; // 使能LCD
if (command == 0)
PORTB &= ~LCD_DC ; // 传送命令
else
PORTB |= LCD_DC ; // 传送数据
SPDR = data; // 传送数据到SPI寄存器
while ((SPSR & 0x80) == 0); // 等待数据传送完毕
PORTB |= LCD_CE ; // 关闭LCD
}
void LCD_OUT_FFT_DATA(int16_t *out_data) //显示频谱
{
unsigned char x,data_y,data_z;
unsigned int data;
LCD_clear(); // LCD清屏
LCD_clear(); // LCD清屏
out_data=out_data+20;
for(x=0;x<84;x++)
{
data=*out_data++;
data/=20;
data_y=data%8;
data_z=data/8;
data_z=5-data_z;
data_y=0xff<<(7-data_y);
if(data_z<=5)
{
LCD_set_XY(x,data_z);
LCD_write_byte(data_y,1);
while(data_z<6)
{
++data_z;
LCD_set_XY(x,data_z);
LCD_write_byte(0xff,1);
}
}
}
}
/*-----------------------------------------------------------------------
LCD_draw_map : 位图绘制函数
输入参数:X、Y :位图绘制的起始X、Y坐标;
*map :位图点阵数据;
Pix_x :位图像素(长)
Pix_y :位图像素(宽)
编写日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8; //计算位图所占行数
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //换行
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -