由于各前一段时间比较忙,POS的PCB早来了,一直没有调,这个星期开始调了,准备用模块化设计,大家看看怎么样?
LCD已经完成
/*
模块打开关闭, 如果模块使用设置成 FP_CONFIG_YES
如果模块不使用设置成 FP_CONFIG_NO
*/
#define FP_CONFIG_USE_RTC FP_CONFIG_YES
#define FP_CONFIG_USE_LCD FP_CONFIG_YES
#define FP_CONFIG_USE_LCD_BACKLIGHT FP_CONFIG_NO
#define FP_CONFIG_USE_KEYPAD FP_CONFIG_NO
#define FP_CONFIG_USE_MCR FP_CONFIG_NO
#define FP_CONFIG_USE_ICCARD FP_CONFIG_NO
#define FP_CONFIG_USE_RFID FP_CONFIG_NO
#define FP_CONFIG_USE_GPRS FP_CONFIG_NO
#define FP_CONFIG_USE_FLASH FP_CONFIG_NO
#define FP_CONFIG_USE_HZ FP_CONFIG_NO //BIOS 不使用汉字库
#define FP_CONFIG_USE_PRINTER FP_CONFIG_NO
#define FP_CONFIG_USE_USB FP_CONFIG_NO //暂时不支持
//--------------------------------------------------------------------------------------------------
// LCD
//--------------------------------------------------------------------------------------------------
#if defined(FP_CONFIG_USE_LCD) && (FP_CONFIG_USE_LCD == FP_CONFIG_YES)
#define LCD_Module UC1701X
#if defined(LCD_Module) && (LCD_Module == UC1701X)
#define LCD_Resolution (128*64) //屏幕分辨率
#define LCD_CS_PORT GPIOD
//#define LCD_CS_GPIO_CLK RCC_APB2Periph_GPIOD
#define LCD_CS_PIN GPIO_Pin_8
#define LCD_RS_PORT GPIOD
//#define LCD_RS_GPIO_CLK RCC_APB2Periph_GPIOD
#define LCD_RS_PIN GPIO_Pin_7
#define LCD_SCK_PORT GPIOD
//#define LCD_SCK_GPIO_CLK RCC_APB2Periph_GPIOD
#define LCD_SCK_PIN GPIO_Pin_6
#define LCD_SDA_PORT GPIOD
//#define LCD_SDA_GPIO_CLK RCC_APB2Periph_GPIOD
#define LCD_SDA_PIN GPIO_Pin_5
typedef enum {
LCD_ALL_LINE = -1, //所有行
LCD_LINE1, //行1
LCD_LINE2, //行2
LCD_LINE3, //行3
LCD_LINE4, //行4
LCD_LINE5, //行5
LCD_LINE6, //行6
LCD_LINE7, //行7
LCD_LINE8 //行8
} LCD_RowValue;
#define IS_LCD_RowValue(LINE) (((LINE) == LCD_ALL_LINE) || ((LINE) == LCD_LINE1) || \
((LINE) == LCD_LINE2) || ((LINE) == LCD_LINE3) || \
((LINE) == LCD_LINE4) || ((LINE) == LCD_LINE5) || \
((LINE) == LCD_LINE6) || ((LINE) == LCD_LINE7) || \
((LINE) == LCD_LINE8))
//#elif /
#endif
#endif // LCD
/********************************************************************************
文件名: Lcd.c
作者: rxes
email: fpos@foxmail.com
版本: V0.0.1 2012-9-9
描述: Lcd驱动程序.
*******************************************************************************/
/*******************************************************************************
V0.0.1 Lcd驱动芯片为UC1701X
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "fpos_board.h"
#include "Lcd.h"
#include "ASCII.h"
#include
#include
#if defined(LCD_Resolution) && (LCD_Resolution==(128*64))
static uint8_t LCD_BUFFER[1024],Lcd_Inverse_Flag;
//#elif
#endif
#if defined(FP_CONFIG_USE_LCD) && (FP_CONFIG_USE_LCD == FP_CONFIG_YES)
#if defined(LCD_Module) && (LCD_Module == UC1701X)
/******************************************************************************
初始化Lcd端口.
输入: None
输出: None
******************************************************************************/
void Lcd_PORT_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
//RCC_APB2PeriphClockCmd(LCD_CS_GPIO_CLK | LCD_RS_GPIO_CLK | LCD_SCK_GPIO_CLK | LCD_SDA_GPIO_CLK | RCC_APB2Periph_AFIO , ENABLE);
/* Configure Lcd CS as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LCD_CS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_CS_PORT, &GPIO_InitStructure);
/* Configure Lcd RS as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LCD_RS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_RS_PORT, &GPIO_InitStructure);
/* Configure Lcd SCK as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LCD_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_SCK_PORT, &GPIO_InitStructure);
/* Configure Lcd SDA as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LCD_SDA_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_SDA_PORT, &GPIO_InitStructure);
GPIO_SetBits(LCD_CS_PORT,LCD_CS_PIN);
GPIO_SetBits(LCD_RS_PORT,LCD_RS_PIN);
GPIO_SetBits(LCD_SCK_PORT,LCD_SCK_PIN);
GPIO_SetBits(LCD_SDA_PORT,LCD_SDA_PIN);
}
/*****************************************************************************
写命令
输入:
输出: None
*****************************************************************************/
void Lcd_WR_COMMAND(uint8_t value)
{
uint8_t mask;
GPIO_ResetBits(LCD_CS_PORT,LCD_CS_PIN);
GPIO_ResetBits(LCD_RS_PORT,LCD_RS_PIN);
for (mask = 0x80; mask; mask >>= 1)
{
if( value & mask)
GPIO_SetBits(LCD_SDA_PORT,LCD_SDA_PIN);
else
GPIO_ResetBits(LCD_SDA_PORT,LCD_SDA_PIN);
GPIO_ResetBits(LCD_SCK_PORT,LCD_SCK_PIN);
GPIO_SetBits(LCD_SCK_PORT,LCD_SCK_PIN);
}
GPIO_SetBits(LCD_CS_PORT,LCD_CS_PIN);
GPIO_SetBits(LCD_SCK_PORT,LCD_SCK_PIN);
GPIO_SetBits(LCD_SDA_PORT,LCD_SDA_PIN);
}
/*****************************************************************************
写命令
输入:
输出: None
*****************************************************************************/
void Lcd_WR_DAT(uint8_t value)
{
uint8_t mask;
GPIO_ResetBits(LCD_CS_PORT,LCD_CS_PIN);
GPIO_SetBits(LCD_RS_PORT,LCD_RS_PIN);
for (mask = 0x80; mask; mask >>= 1)
{
if( value & mask)
GPIO_SetBits(LCD_SDA_PORT,LCD_SDA_PIN);
else
GPIO_ResetBits(LCD_SDA_PORT,LCD_SDA_PIN);
GPIO_ResetBits(LCD_SCK_PORT,LCD_SCK_PIN);
GPIO_SetBits(LCD_SCK_PORT,LCD_SCK_PIN);
}
GPIO_SetBits(LCD_CS_PORT,LCD_CS_PIN);
GPIO_SetBits(LCD_SCK_PORT,LCD_SCK_PIN);
GPIO_SetBits(LCD_SDA_PORT,LCD_SDA_PIN);
}
/*****************************************************************************
初始化Lcd
输入: None
输出: None
*****************************************************************************/
void Lcd_Init(void)
{
Lcd_PORT_Init();
Lcd_WR_COMMAND(0xa2); //DUTY=1/65,BIAS=1/9
Lcd_WR_COMMAND(0xa0); //SEG Direction normal
Lcd_WR_COMMAND(0xc8); //COM Direction normal
Lcd_WR_COMMAND(0x25); //V0 voltage regulator internal resistor ratio set 20H-27H
Lcd_WR_COMMAND(0x81);
Lcd_WR_COMMAND(0x1b); //Vadj
Lcd_WR_COMMAND(0x2f); //POWER CONTROL
Lcd_WR_COMMAND(0xaf); //DISPLAY ENABLE
}
void Lcd_Test(void)
{
uint8_t i,j;
for(i=0;i<8;i++)
{
Lcd_WR_COMMAND(0xb0|i);
Lcd_WR_COMMAND(0x00);
Lcd_WR_COMMAND(0x10);
for(j=0;j<128;j++)
Lcd_WR_DAT(0x55);
}
Lcd_WR_COMMAND(0xb0|i);
Lcd_WR_COMMAND(0x00);
Lcd_WR_COMMAND(0x10);
for(j=0;j<128;j++)
Lcd_WR_DAT(0xff);
}
/*****************************************************************************
Lcd_Updata
输入:None
输出:None
*****************************************************************************/
void Lcd_Updata(void)
{
uint8_t i,j;
for(i=0;i<8;i++)
{
Lcd_WR_COMMAND(0xb0|i);
Lcd_WR_COMMAND(0x00);
Lcd_WR_COMMAND(0x10);
for(j=0;j<128;j++)
Lcd_WR_DAT(LCD_BUFFER[i*128+j]);
}
}
/*****************************************************************************
Lcd_cls
输入:char line=0,1,2,3,4,5,6,7,8
All: 清全屏(不包括icon)
LINE1:清第一行
LINE2:清第二行
LINE3:清第三行
LINE4:清第四行
LINE5:清第五行
LINE6:清第六行
LINE7:清第七行
LINE8:清第八行
输出:None
*****************************************************************************/
void Lcd_cls(LCD_RowValue line)
{
uint16_t i;
assert_param(IS_Lcd_RowValue(line));
switch(line)
{
case LCD_ALL_LINE:
for(i=0;i<(128*8);i++)
LCD_BUFFER=0;
break;
case LCD_LINE1:
case LCD_LINE2:
case LCD_LINE3:
case LCD_LINE4:
case LCD_LINE5:
case LCD_LINE6:
case LCD_LINE7:
case LCD_LINE8:
for(i=0;i<128;i++)
LCD_BUFFER[LCD_LINE1*128+i]=0;
break;
}
Lcd_Updata();
}
/*****************************************************************************
Lcd_showlines
功能:5*7的ASCII字符行显示动作(从列首开始)
输入:dln=要显示的行
dcl=起始列
p=指向要显示的缓冲
输出:NULL
*****************************************************************************/
void Lcd_showlines(char dln,char dcl,uint8_t *p,uint32_t num)
{
uint32_t i,j;
i=dcl-1;
while((i<21)&(i {
for(j=0;j<6;j++)
LCD_BUFFER[(dln-1)*128+6*i+j]=(Lcd_Inverse_Flag==1)
?~(ASCII_SMALL[((*(p+i))-32)*6+j])
:ASCII_SMALL[((*(p+i))-32)*6+j];
i++;
}
}
/*****************************************************************************
displays
功能:行显示(从任意列开始,以5*7点阵)
输入:dln 要显示的行
dcl 起始列
data 指向要显示数据的指针
输出:NULL
*****************************************************************************/
void displays(char dln,char dcl,char *data,...)
{
va_list a;
uint8_t* fmt;
uint8_t ch;
uint8_t print_rc[42],i;
uint8_t temp_rc[21];
for(i=0;i<42;i++)
print_rc=0x20;
fmt=(uint8_t*)data;
i=dcl-1;
va_start(a,data);
while(((ch=*fmt++)!=0)&(i<21))
{
if(ch!='%')
print_rc[i++]=ch;
else
{
switch(ch=*fmt++)
{
case 'd':
{
uint16_t t;
uint32_t j,k,m,n;
for(j=0;j<21;j++)
temp_rc[j]=0x0;
t=va_arg(a, int);
j=1;
k=1;
while(1)
{
if(t<(k*10))
break;
k=k*10;
j++;
}
m=0;
while(1)
{
for(;t>=k;t=t-k)
{
temp_rc[m]=temp_rc[m]+1;
}
m++;
j--;
for(k=1,n=1;n k=k*10;
if(j==0)
break;
}
for(n=0;n print_rc[i++]=temp_rc[n]+0x30;
break;
}
case 'l':
{
uint32_t t;
uint32_t j,k,m,n;
for(j=0;j<21;j++)
temp_rc[j]=0x0;
t=va_arg(a, long);
j=1;
k=1;
while(1)
{
if(t<(k*10))
break;
k=k*10;
j++;
}
m=0;
while(1)
{
for(;t>=k;t=t-k)
{
temp_rc[m]=temp_rc[m]+1;
}
m++;
j--;
for(k=1,n=1;n k=k*10;
if(j==0)
break;
}
for(n=0;n print_rc[i++]=temp_rc[n]+0x30;
break;
}
case 'c':
{
print_rc[i++]=va_arg(a, int);;
break;
}
case 's':
{
char * t;
t=va_arg(a, char *);
while(((*t)!=0)&(i<21))
{
print_rc[i++]=*t++;
}
break;
}
default:
{
print_rc[i++]=ch;
continue;
}
}
}
}
va_end(a);
Lcd_showlines(dln,dcl,print_rc,i-dcl+1);
Lcd_Updata();
}
//#elif
#endif
#endif //Lcd
/******************* (C) COPYRIGHT 2012 RXES *****END OF FILE****/
用户377235 2012-10-11 14:56
用户1696414 2012-9-29 11:15