新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > stm32驅(qū)動12864液晶顯示程序

stm32驅(qū)動12864液晶顯示程序

作者: 時間:2016-11-17 來源:網(wǎng)絡(luò) 收藏
注意:stm32的3.3v工作電壓,需要使用3.3v工作電壓的12864液晶

#include "stm32f10x_lib.h"
#define uint unsigned int
#define uchar unsigned char
#define RSH GPIO_SetBits(GPIOA,GPIO_Pin_0)
#define RSL GPIO_ResetBits(GPIOA,GPIO_Pin_0)
#define RWH GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define RWL GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define ENH GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define ENL GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define CS1H GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define CS1L GPIO_ResetBits(GPIOA,GPIO_Pin_3)
#define CS2H GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define CS2L GPIO_ResetBits(GPIOA,GPIO_Pin_4)

本文引用地址:http://m.butianyuan.cn/article/201611/315425.htm

void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);

void Delay();

uchar table[][16]={
/*-- 文字: 我 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00,
0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00,/*-- 文字: 爸 --*/

/*-- 文字: 一 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*-- 文字: 天 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,
0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00,

/*-- 文字: 的 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,
0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00,

/*-- 文字: 成 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00,
0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00,

/*-- 文字: 果 --*/
/*-- 宋體12; 此字體下對應(yīng)的點陣為:寬x高=16x16 --*/
0x00,0x00,0x00,0x3E,0x2A,0x2A,0x2A,0xFE,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x09,0x11,0x31,0x11,0x00,

};

void Write_cmd_left(uchar cmd)
{
RSL;
RWL;
CS1H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS1L;
}
void Write_cmd_right(uchar cmd)
{
RSL;
RWL;
CS2H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS2L;
}
void Write_data_left(uchar data)
{
RSH;
RWL;
CS2L;
CS1H;
GPIO_Write(GPIOF,data);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS1L;
}
void Write_data_right(uchar data)
{
RSH;
RWL;
CS1L;
CS2H;
GPIO_Write(GPIOF,data);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS2L;
}

void led_disp(uchar *p,uchar lr)
{
uchar i,cl,cr;
if(lr==L)
{
for(i=0;i<16;i++)
{
cl=*p;
p++;
Write_data_left(cl);
}
}
if(lr==R)
{
for(i=0;i<16;i++)
{
cr=*p;
p++;
Write_data_right(cr);
}
}

}

void clear()
{
uchar i,j,disp_page;
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_left(disp_page);
Write_cmd_left(0x40);
for(j=0;j<64;j++)
Write_data_left(0x00);
}
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_right(disp_page);
Write_cmd_right(0x40);
for(j=0;j<64;j++)
Write_data_right(0x00);
}
}

void init()
{
Write_cmd_left(0x30);
Delay(10);
Write_cmd_right(0x30);
Delay(10);
Write_cmd_left(0x3f);
Delay(10);
Write_cmd_right(0x3f);
Delay(10);
Write_cmd_left(0xc0);
Delay(10);
Write_cmd_right(0xc0);
}

int main(void)
{


/* Infinite loop */

RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
clear();
Delay(10);
init();
Delay(10);
uchar i;
while(1)
{



Write_cmd_left(0xb8);
Write_cmd_left(0x40);
for(i=0;i<4;i++)
led_disp(table[2*i],L);
Write_cmd_left(0xb8+1);
Write_cmd_left(0x40);
for(i=0;i<4;i++)
led_disp(table[2*i+1],L);


Write_cmd_right(0xb8);
Write_cmd_right(0x40);
for(i=0;i<2;i++)
led_disp(table[2*i+8],R);
Write_cmd_right(0xb8+1);
Write_cmd_right(0x40);
for(i=0;i<2;i++)
led_disp(table[2*i+9],R);

}


}

/******************************************************************************
*Function Name :RCC_Configuration.
*Descriprion :configures the different system clocks.
*Input :None
*Output :None
*Return :None
*******************************************************************************/

void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/*RCC system reset(for debug purpose)*/
RCC_DeInit();
/*Enable HSE 打開外部時鐘*/
RCC_HSEConfig(RCC_HSE_ON);
/*Wait till HSE is read */
HSEStartUpStatus = RCC_WaitForHSEStartUp();

if(HSEStartUpStatus==SUCCESS)//起振成功
{
/*Enable PrefetchBuffer 打開flash的預(yù)存儲功能*/
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

FLASH_SetLatency(FLASH_Latency_2);//設(shè)置代碼延時值

/*HCLK=syclk*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);

/*PCLK2=HCLK*/
RCC_PCLK2Config(RCC_HCLK_Div1);

/*RCLK1=HCLK*/
RCC_PCLK1Config(RCC_HCLK_Div2);

/*PLLCLK=8MHZ*9=72MHZ*/
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

/*Enable PLL*/
RCC_PLLCmd(ENABLE);

/*Wait till PLL is ready*/
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{

}

/*Select PLL as system clock source*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

/*Wait till pll used as system clock source*/
while(RCC_GetSYSCLKSource() !=0x80)
{

}
/*打開相應(yīng)的外部時鐘:GPIOF*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}

else
{

}
}


/******************************************************************************
*Function Name :NVIC_Configuration.
*Descriprion :configures Vector Table base location.
*Input :None
*Output :None
*Return :None
*******************************************************************************/

void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/*Set the vector table base location at 0x20000000*/
NVIC_SetVectorTable(NVIC_VectTab_RAM,0X0);

#else
/*Set the vector table base location at 0x20000000*/
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
}

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //設(shè)置GPIO的工作狀態(tài)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //設(shè)置GPIO的速度
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
}

/******************************************************************************
延時函數(shù)
******************************************************************************/
void Delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}



關(guān)鍵詞: stm3212864液晶顯示程

評論


技術(shù)專區(qū)

關(guān)閉