📄 lcd.c
字号:
// the driver for LCD 128x64
#include "LCD.h"
#include "ffft.h"
#include "uart.h"
// all data to be displayed are written to vram first, then
// the content of vram are sent to LCD by calling lcd_update()
unsigned char vram[SCR_PAGE][SCR_WIDTH];
unsigned char ram_page, ram_y;
volatile unsigned char backlight;
void lcd_delay_us (unsigned int us)
{
unsigned int i, j;
for (i = 0; i < us; i++)
{
j = 16; // 16MHz osc
while(j--);
}
}
void lcd_write_cmd (unsigned char cmd)
{
WRITE_CMD;
DATA_PORT = cmd;
LCD_EN;
LCD_EN;
}
void lcd_write_data (unsigned char data)
{
WRITE_DATA;
DATA_PORT = data;
LCD_EN;
LCD_EN;
}
void lcd_update (void)
{
unsigned char i, j;
for (i = 0; i < SCR_PAGE; i++)
{
LEFT_SCREEN; // writing on the left-half screen
lcd_write_cmd(PAGE_BASE + i);
lcd_write_cmd(Y_BASE);
for (j = 0; j < SCR_HALF_WIDTH; j++)
{
lcd_write_data(vram[i][j]);
}
RIGHT_SCREEN; // writing on the right-half screen
lcd_write_cmd(PAGE_BASE + i);
lcd_write_cmd(Y_BASE);
for (j = SCR_HALF_WIDTH; j < SCR_WIDTH; j++)
{
lcd_write_data(vram[i][j]);
}
}
}
void lcd_cls (void)
{
unsigned char page, y;
for (page = 0; page < SCR_PAGE; page++)
{
for (y = 0; y < SCR_WIDTH; y++)
{
vram[page][y] = 01+page;
}
}
lcd_update();
}
void lcd_initial (void)
{
LCD_RST;
backlight = 1;
BKLIGHT;
CTRL_DDR = 0xFF; // output
DATA_DDR = 0xFF; // output
//*
LEFT_SCREEN;
lcd_write_cmd(DISPLAY_ON);
lcd_write_cmd(LINE_BASE);
RIGHT_SCREEN;
lcd_write_cmd(DISPLAY_ON);
lcd_write_cmd(LINE_BASE);
//*/
lcd_cls();
ram_page = 0;
ram_y = 0;
print("LCD initialized.\r\n");
}
void lcd_print_point (unsigned char y, unsigned int value)//, unsigned char style) // y: 0 ~ 127, value: 0 ~ 1023
{
unsigned char page, index, i;
for (i = T_START_PAGE; i<=T_END_PAGE; i++)
{
vram[i][y] = 0; // clear this column
}
if (value > 1023)
{
value = 1023;
}
page = T_END_PAGE;
while (value > T_PAGE_VALUE)
{
page--;
value-=T_PAGE_VALUE;
}
index = 0x80;
while (value > T_DOT_VALUE)
{
index>>=1;
value-=T_DOT_VALUE;
}
vram[page][y] = index;
lcd_update();
}
void lcd_print_column (unsigned char y, unsigned int value)//, unsigned char style) // y: 0 ~ 127, value: 0 ~ 1023
{
unsigned char page, index, i;
for (i = F_START_PAGE; i<=F_END_PAGE; i++)
{
vram[i][y] = 0; // clear this column
}
if (value > 1023)
{
value = 1023;
}
page = F_END_PAGE;
while (value > F_PAGE_VALUE)
{
vram[page][y] = 0xFF;
page--;
value-=F_PAGE_VALUE;
}
i = 1;
index = 0xFF;
while (value > F_DOT_VALUE)
{
i++;
value-=F_DOT_VALUE;
}
index<<=(8 - i);
vram[page][y] = index;
lcd_update();
}
void lcd_print_signal (unsigned int *wave)
{
unsigned int i;
for (i = 0; i < FFT_N/2; i++) // compress ghe signal wave form to a half for display
{
lcd_print_point(i, *wave);
wave+=2;
}
lcd_update();
}
void lcd_print_spectrum (unsigned int *spectrum)
{
unsigned int i;
for (i = 0; i < FFT_N/2; i++)
{
lcd_print_column(i, *spectrum);
spectrum++;
}
lcd_update();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -