st7565p驱动12864显示问题
lcd.c文件如下
#include "lcd.h"
#include "stm32f10x.h"
#include "delay.h"
#include "led.h"
/****************************LCD_RESet IC for start****************************/
void LCD_RESet(void)
{
// IE = 0x00;
LCD_RES=0;
delay_ms(50);
LCD_RES=1;
delay_ms(50);
}
/*******************************write Data to IC**************************/
void w_dat(unsigned char dat)
{
GPIOD->ODR&=0X00FF;
GPIOD->ODR|=(dat<<8);
__NOP();
__NOP();
__NOP();
__NOP();
LCD_RS=1;
LCD_RW=0;
LCD_Read=1;
__NOP();
__NOP();
__NOP();
__NOP();
LCD_CS=1;
__NOP();
__NOP();
__NOP();
__NOP();
LCD_CS=0;
}
/******************************write Command to IC***********************/
void w_cmd(unsigned char cmd)
{
GPIOD->ODR&=0X00FF;
GPIOD->ODR|=(cmd <<8);
__NOP();
__NOP();
__NOP();
__NOP();
LCD_RS=0;
LCD_RW=0;
LCD_Read=1;
__NOP();
__NOP();
__NOP();
__NOP();
LCD_CS=1;
__NOP();
LCD_CS=0;
}
/***************************display picture *****************************/
void Display(unsigned char *p)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page); //set page addLCD_RESs
w_cmd(0x10); //set Column addLCD_RESs MSB
w_cmd(0x00); //set column addLCD_RESs LSB
for(column=0;column<128;column++)
{
w_dat(*p++);
}
}
}
void Display_fill(unsigned char fill)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page); //set page addLCD_RESs
w_cmd(0x10); //set Column addLCD_RESs MSB
w_cmd(0x00); //set column addLCD_RESs LSB
for(column=0;column<131;column++)
{
w_dat(fill);
}
}
}
void Grid_white(void)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<65;column++)
{
w_dat(0xFF);
w_dat(0x00);
}
}
}
void Grid_Black(void)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<65;column++)
{
w_dat(0x00);
w_dat(0xFF);
}
}
}
void Grid_Line1(void)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<131;column++)
{
w_dat(0xAA);
}
}
}
void Grid_Line2(void)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<131;column++)
{
w_dat(0x55);
}
}
}
void Lcd_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ê1?üPA???úê±?ó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); //ê1?üPD???úê±?ó
GPIO_InitStructure.GPIO_Pin = Data;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
LCD_CS = 0;
// GPIOD->ODR&=0X00FF;
// GPIOD->ODR|=(0XFF<<8);
LCD_RESet();
// w_cmd(0xA2); //LCD Bias selection(1/65 Duty,1/9Bias)
// w_cmd(0xA0); //ADC selection(SEG0->SEG128) áDé¨?è ′ó×óμ?óò
// w_cmd(0xC0); //SHL selection(COM0->COM64) ò3é¨?è ′ó??μ?é?
// w_cmd(0x26); //Regulator LCD_RESistor Selection
// delay_ms(5);
// w_cmd(0x81); //Electronic Volume μ?á?
// w_cmd(0x8); //Reference Register selection Vo=(1+Rb/Ra)(1+a)*2.1=10
// w_cmd(VC_ON); //Power Control(Vc=1;Vr=0;Vf=0)
// delay_ms(10);
// w_cmd(VC_ON|VR_ON);
// delay_ms(10);
// w_cmd(VC_ON|VR_ON|VF_ON);
// delay_ms(10);
// w_cmd(0xF8);
// w_cmd(0x00);
// delay_ms(5);
// w_cmd(0xAF); //Display on
w_cmd(0xE2);
delay_ms(5);
w_cmd(0x2c); /*éy?12???1*/
delay_ms(5);
w_cmd(0x2e); /*éy?12???2*/
delay_ms(5);
w_cmd(0x2f); /*éy?12???3*/
delay_ms(5);
w_cmd(0x24); /*′?μ÷??±è?è£??ééè??·??§20??27*/
w_cmd(0x81); /*?¢μ÷??±è?è*/
w_cmd(0x1a); /*?¢μ÷??±è?èμ??μ£??ééè??·??§0??63 1f*/
w_cmd(0xa2); /*1/9???1±è£¨bias£?*/
w_cmd(0xc0); /*DDé¨?è?3Dò£o′óé?μ???*/
w_cmd(0xa0); /*áDé¨?è?3Dò£o′ó×óμ?óò*/
w_cmd(0x40); /*?eê?DD£o′óμúò?DD?aê?*/
Clear_Screen();
w_cmd(0xaf); /*?a??ê?*/
}
/**********************Clear*******************************/
void Clear_Screen(void)
{
unsigned char i,j;
for(i=0;i<9;i++)
{
LCD_CS=0;
w_cmd(0xb0+i);
w_cmd(0x10);
w_cmd(0x00);
for(j=0;j<132;j++)
{
w_dat(0);
}
}
}
lcd头文件如下
#ifndef _LCD_H_
#define _LCD_H_
#include "delay.h"
//#include "intrins.h"
//#include <absacc.h>
//#define extern deep[]
#define VC_ON 0x2C //1010
#define VR_ON 0x2A
#define VF_ON 0x29 //1001
#define Data GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15
#define LCD_Read PAout(4)
#define LCD_RW PAout(3)
#define LCD_RS PAout(2)
#define LCD_RES PAout(1)
#define LCD_CS PAout(0)
//#define LCD_Read GPIO_Pin_4
//#define LCD_RW GPIO_Pin_3
//#define LCD_RS GPIO_Pin_2
//#define LCD_RES GPIO_Pin_1
//#define LCD_CS GPIO_Pin_0
void LCD_Reset(void);
void w_dat(unsigned char dat); //D′êy?Y
void w_cmd(unsigned char cmd); //D′??????á?
void Display(unsigned char *p);
void Display_fill(unsigned char fill);
void Grid_white(void);
void Grid_Black(void);
void Grid_Line1(void);
void Grid_Line2(void);
void Lcd_Init(void);
void Clear_Screen(void);
#endif