📄 glcd.c
字号:
/*! \file glcd.c \brief Graphic LCD API functions. */
//*****************************************************************************
//
// File Name : 'glcd.c'
// Title : Graphic LCD API functions
// Author : Pascal Stang - Copyright (C) 2002
// Date : 5/30/2002
// Revised : 5/30/2002
// Version : 0.5
// Target MCU : Atmel AVR
// Editor Tabs : 4
//
// NOTE: This code is currently below version 1.0, and therefore is considered
// to be lacking in some functionality or documentation, or may not be fully
// tested. Nonetheless, you can expect most functions to work.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "glcd.h"
// include hardware support
#include "st7565p.h"
// include fonts
#include "font5x7.h"
#include "fontgr.h"
// draw line
void glcdLine(u08 x, u08 val)
{
u08 temp = 8;
if (val > 64) val = 64;
while (val > 8)
{
glcdSetAddress(x, temp - 1);
glcdDataWrite(0xFF);
temp--;
val -= 8;
}
glcdSetAddress(x, temp - 1);
switch (val)
{
case 0 : glcdDataWrite(0x00); break;
case 1 : glcdDataWrite(0x80); break;
case 2 : glcdDataWrite(0xC0); break;
case 3 : glcdDataWrite(0xE0); break;
case 4 : glcdDataWrite(0xF0); break;
case 5 : glcdDataWrite(0xF8); break;
case 6 : glcdDataWrite(0xFC); break;
case 7 : glcdDataWrite(0xFE); break;
case 8 : glcdDataWrite(0xFF); break;
}
temp--;
while (temp > 0)
{
glcdSetAddress(x, temp -1);
glcdDataWrite(0x00);
temp--;
}
}
// text routines
// write a character at the current position
void glcdWriteChar(unsigned char c)
{
u08 i = 0;
for(i=0; i<5; i++)
{
glcdDataWrite(pgm_read_byte(&Font5x7[((c - 0x20) * 5) + i]));
}
// write a spacer line
glcdDataWrite(0x00);
// unless we're at the end of the display
//if(xx == 128)
// xx = 0;
//else
// glcdWriteData(0x00);
//cbi(GLCD_Control, GLCD_CS1);
//cbi(GLCD_Control, GLCD_CS2);
glcdStartLine(0);
}
void glcdWriteCharGr(u08 grCharIdx)
{
u08 idx;
u08 grLength;
u08 grStartIdx = 0;
// get starting index of graphic bitmap
for(idx=0; idx<grCharIdx; idx++)
{
// add this graphic's length to the startIdx
// to get the startIdx of the next one
grStartIdx += pgm_read_byte(FontGr+grStartIdx);
}
grLength = pgm_read_byte(FontGr+grStartIdx);
// write the lines of the desired graphic to the display
for(idx=0; idx<grLength; idx++)
{
// write the line
glcdDataWrite(pgm_read_byte(FontGr+(grStartIdx+1)+idx));
}
}
void glcdPutStr(unsigned char *data)
{
while (*data) {
glcdWriteChar(*data);
data++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -