/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "lcd.h"
/* Private typedef -----------------------------------------------------------私有类型定义*/
/* Private define ------------------------------------------------------------私有define*/
/* Private macro -------------------------------------------------------------私有宏*/
/* Private variables ---------------------------------------------------------私有变量*/
u16 frame[4]; /* LCD frame buffer LCD帧缓存器*/
u16 digit[4]; /* Digit frame buffer 数字帧缓冲器*/
char text[2]; //由两个数字转换成为的相应的字符
/*the varitronix LCD digit is:以下是digit数组中的存储方式
A
-- ----------
X \/ |\ |I /|
F| H | J |B
| \ | / |
--G-- --K--
| /| \ |
E | L | N |C
| / |M \| _
----------- | |DP
D -
PE0 PE1 PE2 PE3 ...................................................... PE15
----------------------------------------------------------------------------------------
| | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | S8 | S9 | S10| S11| S12| S13| S14| S15|
----------------------------------------------------------------------------------------
| COM1 | 1X | 1I | 1A | 1DP| 2X | 2I | 2A | 2DP| 3X | 3I | 3A | 3DP| 4X | 4I | 4A | 4DP|
----------------------------------------------------------------------------------------
| COM2 | 1F | 1H | 1J | 1B | 2F | 2H | 2J | 2B | 3F | 3H | 3J | 3B | 4F | 4H | 4J | 4B |
----------------------------------------------------------------------------------------
| COM3 | 1E | 1G | 1K | 1C | 2E | 2G | 2K | 2C | 3E | 3G | 3K | 3C | 4E | 4G | 4K | 4C |
----------------------------------------------------------------------------------------
| COM4 | 1L | 1M | 1N | 1D | 2L | 2M | 2N | 2D | 3L | 3M | 3N | 3D | 4L | 4M | 4N | 4D |
----------------------------------------------------------------------------------------
A LCD character coding is based on the following matrix:一个LCD的字符吗是基于以下矩阵
{ X , F , E , L }
{ I , H , G , M }
{ A , J , K , N }
{ DP, B , C , D }
The characher A for example is:
{ 0 , 1 , 1 , 0 }
{ 0 , 0 , 1 , 0 }
{ 1 , 0 , 1 , 0 }
{ 0 , 1 , 1 , 0 }
-------------------
= 4 9 F 0 hex
=> 'A' = 0x4E70 笔误吧*/
const u16 letter[26]={0x49F0,0x01F8,0x4118,0x08F8,0x4178,0x4170,0x41D8,0x09F0,0x600A,
0x0888,0x0534,0x0118,0x0F90,0x0B94,0x4998,0x4970,0x499C,0x4974,
0x41E8,0x6002,0x0998,0x0511,0x299A,0x0605,0x0601,0x4409};
const u16 number[10]={0x4998,0x0880,0x4878,0x48E8,0x09E0,0x41E8,0x41F8,0x4880,0x49F8,0x49E8};
const u16 arrow[2]={0x0005,0x0600}; // {Upstair,Downstair上三角 下三角}
/* Private function prototypes -----------------------------------------------私有函数原型*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : convert 转换函数
* Description : converts an ascii char to the a LCD digit (previous coding)将一个ASCII字符
转换成为一个LCD数符 预译码
* Input1 : char
* Input2 : point : flag indicating if a point has to be add in front of
* displayed character (0: no, 1: yes)如果有一个点要被添加到要显示字符前
就在此作出标记 0表示不显示 1表示显示
* Output : None
* Return : None
*******************************************************************************/
void convert (char* c,u8 point)
{
u16 car="0",tmp;
u8 i;
const u16 mask[4]={0xF000,0x0F00,0x00F0,0x000F};//mask 掩码
const u8 shift[3]={0xC,0x8,0x4};//移位用码
if ((*c<0x5B)&(*c>0x40)) // 'A' --- 'F'判断字符是否在A~F范围内
car = letter[*c-0x41]; //如果在范围内 则减去40H 使其在0~25内并在数组中找出其值存入car
else if ((*c<0x3A)&(*c>0x2F)) // '0' --- '9'若不是A到F则判断是不是0到9
car = number[*c-0x30];//若是减去30H使其在0到9并在数组中找出其值存入car
else if (*c==0x20) car =0; // 'space'否则判断是否为空格并在数组中找出其值存入car
else if (*c=='+') car = arrow[0]; // upstair 还是上三角/加号并在数组中找出其值存入car
else if (*c=='-') car = arrow[1]; // downstair 还是下三角/减号并在数组中找出其值存入car
if (point==1) car|=0x8000; //有没有小数点 如果有 则最高DP位置一
for (i=0;i<3;i++)
{
tmp = car&mask;//从高到低 用掩码取出4个位的内容 放在tmp中
digit = tmp>>shift;//然后分别对应的 从高到底的存放到digit数组中
}
digit[3] = (car&mask[3]); //重新装入最低四位 这步为什么要这样写啊
}
/*******************************************************************************
* Function Name : write char 写字符程序
* Description : This function writes a char in the LCD frame buffer 这个程序向
帧缓冲器送入一个字符
* Input1 : char ascii value 输入为ascii码
* Input2 : point 0: no point to add, 1 a point to add in front of char 是否有小数点
* Input2 : pos: position of the caracter to write [0:3]字符的位置
* Output : None
* Return : None
*******************************************************************************/
void write_char(char* car,u8 point,u8 pos)
{
int i;
const u16 mask[4]={0x0F,0xF0,0xF00,0xF000};
convert(car,point);//将输入字符先作转换 存储到digit[]中
if (pos == 1) for (i=0;i<4;i++) digit=(digit<<4);//要是选择了1位那么将每一个对应的数组
//元素左移4位 移位的目的是问了下面 清空对应位置时(frame&~mask[pos])装入新的值|digit
if (pos == 2) for (i=0;i<4;i++) digit=(digit<<8); //要是选择了2位那么就对每一个对应
//数组元素左移8位
if (pos == 3) for (i=0;i<4;i++) digit=(digit<<12); //要是选择了3位那么就左移12位
for (i=0;i<4;i++) frame= (frame&~mask[pos])|digit;//清了以前缓冲区对应位置的值
//然后重新装入了值
}
/*******************************************************************************
* Function Name : write_string写字符串函数
* Description : This function writes a string in the LCD
* Input : string
* Output : None
* Return : None
*******************************************************************************/
void write_string(char* str)
{
int i;
for (i=0;i<4;i++) write_char(str+i,0,i);
}
/*******************************************************************************
* Function Name : int2char
* Description : This function convertes a 2 digit int to a char这个函数将两个数字转换
成为一个字符
* Input : u8 value
* Output : None
* Return : None
*******************************************************************************/
char* int2char(u8 value)
{
text[0] = 0x30 + (value/10);
text[1] = 0x30 + (value%10);
return(text);
}
文章评论(0条评论)
登录后参与讨论