//**********************************main.c********************************************************
#include <
stm32f10x.h
>
#include <
stm32f10x_conf.h
>
#include <
stm32f10x_rcc.h
>
#include <
stm32f10x_gpio.h
>
#include "fonts.h"
#include <
stdio.h
>
#include <
string.h
>
#define PORT GPIOB
#define _WR GPIO_Pin_8
#define RS GPIO_Pin_9
#define B0 0 //DATA PORT
#define REST GPIOC
#define RES GPIO_Pin_0//RST
#define CS GPIO_Pin_1//CS
GPIO_InitTypeDef GPIO_InitStructure;
//************************************************************************
void LCD_InitializePorts(void);
void Write_Cmd_Data (unsigned char x);
void Write_Cmd(unsigned char DL);
void Write_Data(unsigned char DH,unsigned char DL);
void LCD_Initial(void);
void delayms(unsigned int count);
void Print (unsigned int x,unsigned int y,unsigned char *str,unsigned int dcolor,unsigned int bgcolor);
void GotoXY (unsigned int x,unsigned int y,unsigned char value,unsigned int dcolor,unsigned int bgcolor);
static void LCD_SetPos(unsigned char x0,unsigned char x1,unsigned int y0,unsigned int y1);
void delayms(unsigned int count)
{
int i,j;
for(i=0;i<
count
;i++)
{
for(
j
=
0
;j<125;j++);
}
}
void LCD_Initial(void)
{
GPIO_SetBits(REST, GPIO_Pin_1); //
CS
=
1
;
delayms(5);
GPIO_ResetBits(REST, GPIO_Pin_0); //
RES
=
0
;
delayms(10);
GPIO_SetBits(REST, GPIO_Pin_0); //
RES
=
1
;
delayms(120);
Write_Cmd(0xE9);
Write_Cmd_Data(0x20);
Write_Cmd(0x11);// Exit_sleep_mode
delayms(100);
Write_Cmd(0xD1);//Power_Setting
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x71);//59 VCOH
Write_Cmd_Data(0x19);//15 VCOM AP
Write_Cmd(0xD0);//VCOM Control
Write_Cmd_Data(0x07);//07
Write_Cmd_Data(0x01);//01
Write_Cmd_Data(0x08);//04
Write_Cmd(0x36);//Set_address_mode 8
Write_Cmd_Data(0x48);//normal
Write_Cmd(0x3A);//Display_Timing_Setting for Normal/Partial Mode
Write_Cmd_Data(0x05);
Write_Cmd(0xC1);//Display_Timing_Setting for Normal/Partial Mode
Write_Cmd_Data(0x10);
Write_Cmd_Data(0x10);
Write_Cmd_Data(0x02);
Write_Cmd_Data(0x02);
Write_Cmd(0xC0);//Panel Driving Setting
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x35);
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x01);
Write_Cmd_Data(0x02);
Write_Cmd(0xC5);//Frame Rate Control
Write_Cmd_Data(0x04);
Write_Cmd(0xD2);//Power_Setting for Normal Mode
Write_Cmd_Data(0x01);
Write_Cmd_Data(0x44);
Write_Cmd(0xC8);//SET GAMMA
Write_Cmd_Data(0x04);
Write_Cmd_Data(0x67);
Write_Cmd_Data(0x35);
Write_Cmd_Data(0x04);
Write_Cmd_Data(0x08);
Write_Cmd_Data(0x06);
Write_Cmd_Data(0x24);
Write_Cmd_Data(0x01);
Write_Cmd_Data(0x37);
Write_Cmd_Data(0x40);
Write_Cmd_Data(0x03);
Write_Cmd_Data(0x10);
Write_Cmd_Data(0x08);
Write_Cmd_Data(0x80);
Write_Cmd_Data(0x00);
Write_Cmd(0x2A); //Frame rate control
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x00);
Write_Cmd_Data(0xEF);
Write_Cmd(0x2B); //Display function control
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x00);
Write_Cmd_Data(0x01);
Write_Cmd_Data(0x8F);
Write_Cmd(0x29);//DISPLAY ON
delayms(120);
Write_Cmd(0x2C);//Write memory start
}
//=============================================================
static void LCD_SetPos(unsigned char x0,unsigned char x1,unsigned int y0,unsigned int y1)
{
unsigned char YSH,YSL,YEH,YEL;
YSH
=
y0
>>8;
YSL=y0;
YEH=y1>>8;
YEL=y1;
Write_Cmd(0x2A);
Write_Cmd_Data (0x00);
Write_Cmd_Data (x0);
Write_Cmd_Data (0x00);
Write_Cmd_Data (x1);
Write_Cmd(0x2B);
Write_Cmd_Data (YSH);
Write_Cmd_Data (YSL);
Write_Cmd_Data (YEH);
Write_Cmd_Data (YEL);
Write_Cmd(0x2C);//LCD_WriteCMD(GRAMWR);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void GotoXY (unsigned int x,unsigned int y,unsigned char value,unsigned int dcolor,unsigned int bgcolor)
{
unsigned char i,j;
unsigned char *str;
str=font1;
LCD_SetPos(x,x+31,y,y+20);
str+=(value-48)*84;
for(j=0;j<
84
;j++)
{
for(
i
=
0
;i<8;i++)
{
if((*str&(1<<(7-i)))!=0)
{
Write_Data(dcolor>>8,dcolor);
}
else
{
Write_Data(bgcolor>>8,bgcolor);
}
}
str++;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void Print(unsigned int x,unsigned int y,unsigned char *str,unsigned int dcolor,unsigned int bgcolor)
{
unsigned int x1,y1;
y1=y;
x1=x;
while(*str!='\0')
{
GotoXY (x1,y1,*str,dcolor,bgcolor);
y1+=30;
str++;
}
}
void Write_Cmd_Data (unsigned char x)
{
GPIO_SetBits(PORT, GPIO_Pin_9);//RS=1;
GPIO_ResetBits(REST, GPIO_Pin_1);//CS=0;
// =x;
GPIO_ResetBits(PORT, GPIO_Pin_8);//_WR=0;
GPIO_SetBits(PORT, GPIO_Pin_8);//_WR=1;
GPIO_SetBits(REST, GPIO_Pin_1);//CS=1;
}
//=============================================================
void Write_Cmd(unsigned char DL)
{
GPIO_ResetBits(PORT, GPIO_Pin_9);//RS=0;
GPIO_ResetBits(REST, GPIO_Pin_1);//CS=0;
// =DL;
GPIO_ResetBits(PORT, GPIO_Pin_8);//_WR=0;
GPIO_SetBits(PORT, GPIO_Pin_8);//_WR=1;
GPIO_SetBits(REST, GPIO_Pin_1);//CS=1;
}
void Write_Data(unsigned char DH,unsigned char DL)
{
GPIO_SetBits(PORT, GPIO_Pin_9);//RS=1;
GPIO_ResetBits(REST, GPIO_Pin_1);//CS=0;
// =DH;
GPIO_ResetBits(PORT, GPIO_Pin_8);//_WR=0;
GPIO_SetBits(PORT, GPIO_Pin_8);//_WR=1;
// =DL;
GPIO_ResetBits(PORT, GPIO_Pin_8);//_WR=0;
GPIO_SetBits(PORT, GPIO_Pin_8);//_WR=1;
GPIO_SetBits(REST, GPIO_Pin_1);//CS=1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
void LCD_InitializePorts(void)
{
// Configure PB0~PB7 ----------------------------------
// DB0-DB7 lcd data
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1|GPIO_Pin_2 | GPIO_Pin_3|GPIO_Pin_4 | GPIO_Pin_5|GPIO_Pin_6 |
GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//GPIO_Mode_Out_OD;
GPIO_Init(PORT, &GPIO_InitStructure);
//GPIO_Write(PORT, _WR | RS | (0xFF << B0));
// C portu------------------
//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(REST, &GPIO_InitStructure);
}
int main(void)
{
LCD_InitializePorts();
LCD_Initial();
Print(100,90,"0123456789",0xffff,0x0054);
while(1)
{
}
}
//************************************font. h**********************************************************************
#ifndef TM_FONTS_H
#define TM_FONTS_H
unsigned char font1[]={
//32 pisel
0x00, 0x00, 0x00, 0x00, // 0
0x7F, 0xF8, 0x7F, 0xFC, //
0xBF, 0xFC, 0xFF, 0xFA, //
0xDF, 0xFC, 0x7F, 0xF6, //
0xEF, 0xF8, 0x7F, 0xEE, //
0xF3, 0xF0, 0x3F, 0xDE, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF8, 0x00, 0x00, 0x3E, //
0xF3, 0xF0, 0x3F, 0x9E, //
0xE7, 0xF8, 0x7F, 0xCE, //
0xCF, 0xFC, 0x7F, 0xE6, //
0x9F, 0xFC, 0xFF, 0xF2, //
0x3F, 0xF8, 0x7F, 0xFC, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00,// 1
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x07, 0xF0, 0x1F, 0xC0,//
0x0F, 0xF8, 0x3F, 0xE0,//
0x1F, 0xF8, 0x7F, 0xF0,//
0x3F, 0xFC, 0xFF, 0xF8,//
0x7F, 0xF8, 0x7F, 0xFC,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00,//
0x00, 0x00, 0x00, 0x00, // 2
0x7F, 0xFC, 0x00, 0x00, //
0xBF, 0xFE, 0x00, 0x02, //
0xDF, 0xFC, 0x00, 0x06, //
0xEF, 0xFF, 0x80, 0x0E, //
0xF3, 0xFF, 0xC0, 0x1E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF0, 0x03, 0xBF, 0x9E, //
0xE0, 0x01, 0x7F, 0xCE, //
0xC0, 0x00, 0xFF, 0xE6, //
0x80, 0x00, 0xFF, 0xF2, //
0x00, 0x00, 0x7F, 0xFC, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 3
0x80, 0x00, 0x00, 0x02, //
0xC0, 0x00, 0x00, 0x06, //
0xE0, 0x03, 0x80, 0x0E, //
0xF0, 0x07, 0xC0, 0x1E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xFB, 0xF7, 0xFF, 0xBE, //
0xE7, 0xFB, 0xFF, 0xCE, //
0xCF, 0xFD, 0x7F, 0xE6, //
0x9F, 0xFC, 0xFF, 0xF2, //
0x3F, 0xF8, 0x7F, 0xF8, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 4
0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x7F, 0xFC, //
0x00, 0x00, 0xFF, 0xF8, //
0x00, 0x00, 0x7F, 0xF0, //
0x00, 0x03, 0xBF, 0xE0, //
0x00, 0x07, 0xDF, 0xC0, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x00, 0x07, 0xC0, 0x00, //
0x07, 0xF3, 0xBF, 0xC0, //
0x0F, 0xF9, 0x3F, 0xC0, //
0x1F, 0xF8, 0x7F, 0xE0, //
0x3F, 0xFC, 0xFF, 0xF0, //
0x7F, 0xF8, 0x7F, 0xF8, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 5
0x00, 0x00, 0x7F, 0xFC, //
0x80, 0x00, 0xFF, 0xFA, //
0xC0, 0x00, 0xFF, 0xF6, //
0xE0, 0x03, 0xFF, 0xEE, //
0xF0, 0x07, 0xFF, 0xDE, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF3, 0xFB, 0x80, 0x1E, //
0xE7, 0xFD, 0x00, 0x0E, //
0xCF, 0xFE, 0x00, 0x06, //
0x9F, 0xFE, 0x00, 0x02, //
0x3F, 0xFC, 0x00, 0x00, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 6
0x7F, 0xF8, 0x7F, 0xFC, //
0xBF, 0xFC, 0xFF, 0xFA, //
0xDF, 0xFC, 0x7F, 0xF6, //
0xEF, 0xFB, 0xFF, 0xEE, //
0xF3, 0xF7, 0xFF, 0xDE, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF3, 0xF3, 0x80, 0x1E, //
0xE7, 0xF9, 0x00, 0x0E, //
0xCF, 0xFC, 0x00, 0x06, //
0x9F, 0xFC, 0x00, 0x02, //
0x3F, 0xF8, 0x00, 0x00, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 7
0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x02, //
0x00, 0x00, 0x00, 0x06, //
0x00, 0x00, 0x00, 0x0E, //
0x00, 0x00, 0x00, 0x1E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x00, 0x00, 0x00, 0x3E, //
0x07, 0xF0, 0x3F, 0xBE, //
0x0F, 0xF8, 0x7F, 0xCE, //
0x1F, 0xF8, 0x7F, 0xE6, //
0x3F, 0xFC, 0xFF, 0xF2, //
0x7F, 0xF8, 0x7F, 0xF8, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 8
0x7F, 0xF8, 0x7F, 0xFC, //
0xBF, 0xFC, 0xFF, 0xFA, //
0xDF, 0xFC, 0x7F, 0xF6, //
0xEF, 0xFB, 0xFF, 0xEE, //
0xF3, 0xF7, 0xFF, 0xDE, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF3, 0xF3, 0xBF, 0x9E, //
0xE7, 0xF9, 0x7F, 0xCE, //
0xCF, 0xFC, 0x7F, 0xE6, //
0x9F, 0xFC, 0xFF, 0xF2, //
0x3F, 0xF8, 0x7F, 0xFC, //
0x00, 0x00,0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // 9
0x00, 0x00, 0x7F, 0xFC, //
0x80, 0x00, 0xFF, 0xFA, //
0xC0, 0x00, 0x7F, 0xF6, //
0xE0, 0x03, 0xFF, 0xEE, //
0xF0, 0x07, 0xFF, 0xDE, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF8, 0x07, 0xC0, 0x3E, //
0xF3, 0xF3, 0xBF, 0x9E, //
0xE7, 0xF9, 0x7F, 0xCE, //
0xCF, 0xFC, 0x7F, 0xE6, //
0x9F, 0xFC, 0xFF, 0xF2, //
0x3F, 0xF8, 0x7F, 0xFC, //
0x00, 0x00,0x00, 0x00,
};
#endif