標題:
STM32驅(qū)動12864程序 我是時序不對呢,IO不對?
[打印本頁]
作者:
氺魔尊丿
時間:
2018-8-12 23:27
標題:
STM32驅(qū)動12864程序 我是時序不對呢,IO不對?
求助大佬,我是時序不對呢,IO不對呀,怎么驅(qū)動不了12864呢,內(nèi)心極度崩塌。。。。。。。。
#ifndef _H_LCD_12684_H
#define _H_LCD_12684_H
#include "sys.h"
//#define PIN_PSB (1<<3)
//#define PIN_RST (1<<5) //片選信號
//#define PIN_E_CLK (1<<6)
//#define PIN_RW (1<<7)
//#define PIN_RS_CS (1<<8)
//#define PIN_Data0 (1<<9)
//#define PIN_Data1 (1<<10)
//#define PIN_Data2 (1<<11)
//#define PIN_Data3 (1<<12)
//#define PIN_Data4 (1<<13)
//#define PIN_Data5 (1<<14)
//#define PIN_Data6 (1<<15)
//#define PIN_Data7 (1<<0)
//#define PSB(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_PSB) | (x ? PIN_PSB: 0);
//#define RST(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_RST) | (x ? PIN_RST: 0);
//#define E_CLK(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_E_CLK)| (x ? PIN_E_CLK:0);
//#define RW(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_RW) | (x ? PIN_RW : 0);
//#define RS_CS(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_RS_CS)| (x ? PIN_RS_CS:0);
//
//#define Data0(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data0)| (x ? PIN_Data0 : 0);
//#define Data1(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data1)| (x ? PIN_Data1 : 0);
//#define Data2(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data2)| (x ? PIN_Data2 : 0);
//#define Data3(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data3)| (x ? PIN_Data3 : 0);
//#define Data4(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data4)| (x ? PIN_Data4 : 0);
//#define Data5(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data5)| (x ? PIN_Data5 : 0);
//#define Data6(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data6)| (x ? PIN_Data6 : 0);
//#define Data7(x) GPIOB->ODR = (GPIOB->ODR & ~PIN_Data7)| (x ? PIN_Data7 : 0);
#define LCD_PSB PBout(4)
#define LCD_RST PBout(5) //片選信號
#define LCD_E_CLK PBout(6)
#define LCD_RW PBout(7)
#define LCD_RS_CS PBout(8)
#define LCD_Data0 PBout(9)
#define LCD_Data1 PBout(10)
#define LCD_Data2 PBout(11)
#define LCD_Data3 PBout(12)
#define LCD_Data4 PBout(13)
#define LCD_Data5 PBout(14)
#define LCD_Data6 PBout(15)
#define LCD_Data7 PBout(0)
void LCD_12864_Write_Com(uint8_t command);
void LCD_12864_Write_Data(uint8_t Data);
void LCD_12864_Init(void);
void LCD_Display_String(uint8_t x,uint8_t y,uint8_t *s) ;
#endif
#include "LCD_12864.h"
#include "delay.h"
#include "usart.h"
u8 Shit[]="HCXY_智能控制實驗室";
u8 Fuck[]="世界那么大";
u8 Bitch[]="http://www.jianshengdrlab.com/forum.php";
u8 Hangover[]="Perfact The Test!";
/**************************************************************************
函數(shù)名:
屬 性:
參 數(shù):
功 能:寫指令
日 期:
返回值:
描 述:
***************************************************************************/
void LCD_12864_Write_Com(uint8_t command)
{
u8 temp=0x01;
u8 table[8]={0};
u8 count;
LCD_RW=0;
LCD_RS_CS=0;
LCD_E_CLK=0;
delay_us(10);
for(count=0;count<8;count++)
{
if(command&temp)
table[count]=1;
else
table[count]=0;
temp=temp<<1;
}
temp=0x01;
LCD_Data0=table[0];
LCD_Data1=table[1];
LCD_Data2=table[2];
LCD_Data3=table[3];
LCD_Data4=table[4];
LCD_Data5=table[5];
LCD_Data6=table[6];
LCD_Data7=table[7];
delay_us(5);
LCD_E_CLK=1;
delay_us(500);
LCD_E_CLK=0;
delay_us(500);
}
/**************************************************************************
函數(shù)名:
屬 性:
參 數(shù):
功 能:
日 期:
返回值:
描 述:
***************************************************************************/
void LCD_12864_Write_Data(uint8_t Data)
{
u8 temp=0x01;
u8 table[8]={0};
u8 count;
LCD_RW=0;
LCD_RS_CS=1;
LCD_E_CLK=0;
delay_us(10);
for(count=0;count<8;count++)
{
if(Data&temp)
table[count]=1;
else
table[count]=0;
temp=temp<<1;
}
temp=0x01;
LCD_Data0=table[0];
LCD_Data1=table[1];
LCD_Data2=table[2];
LCD_Data3=table[3];
LCD_Data4=table[4];
LCD_Data5=table[5];
LCD_Data6=table[6];
LCD_Data7=table[7];
delay_us(5);
LCD_E_CLK=1;
delay_us(500);
LCD_E_CLK=0;
delay_us(500);
}
/**************************************************************************
函數(shù)名:
屬 性:
參 數(shù):
功 能:
日 期:
返回值:
描 述:
***************************************************************************/
void LCD_Display_String(uint8_t X,uint8_t Y,uint8_t *P)
{
switch(Y)
{
case 0:
LCD_12864_Write_Com(0x80 + X);//第一行
break;
case 1:
LCD_12864_Write_Com(0x90 + X);//第二行
break;
case 2:
LCD_12864_Write_Com(0x88 + X);//第三行
break;
case 3:
LCD_12864_Write_Com(0x98 + X);//第四行
break;
default:break;
}
while(*P!='\0')
{
LCD_12864_Write_Data(*P);
delay_us(100);
P++;
}
}
/**************************************************************************
函數(shù)名:
屬 性:
參 數(shù):
功 能:
日 期:
返回值:
描 述:
***************************************************************************/
void LCD_12864_Init(void)
{
// GPIO_InitTypeDef GPIOA_InitStruct;
GPIO_InitTypeDef GPIOB_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
// GPIOA_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
// GPIOA_InitStruct.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
// GPIOA_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
// GPIO_Init(GPIOA,&GPIOA_InitStruct);
GPIOB_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIOB_InitStruct.GPIO_Pin=GPIO_Pin_All;
GPIOB_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIOB_InitStruct);
GPIO_SetBits(GPIOB,GPIO_Pin_All);
// GPIO_SetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7\
// |GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_13|GPIO_Pin_14\
// |GPIO_Pin_15);
LCD_RST=0; //復(fù)位
delay_ms(10); //延時
LCD_RST=1; //復(fù)位置高
delay_ms(50);
LCD_PSB=1;
LCD_12864_Write_Com(0x30); //Extended Function Set :8BIT設(shè)置,RE=0: basic instruction set, G=0 :graphic display OFF
delay_us(100); //大于100uS的延時程序
LCD_12864_Write_Com(0x30); //Function Set
delay_us(40); //大于37uS的延時
LCD_12864_Write_Com(0x0c); //Display on Control
delay_us(100); //大于100uS的延時
LCD_12864_Write_Com(0x10); //Cursor Display Control光標設(shè)置
delay_us(100); //大于100uS的延時程序
LCD_12864_Write_Com(0x01); //清屏
delay_ms(20); //大于10mS的延時
LCD_12864_Write_Com(0x06); //Enry Mode Set,光標從右向左加1位移動
delay_us(100); //大于100uS的延時
/********************開機畫面***********************/
LCD_Display_String(0,0,Shit); //顯示第1行
LCD_Display_String(0,1,Fuck); //顯示第2行
LCD_Display_String(0,2,Bitch); //顯示第3行
LCD_Display_String(0,3,Hangover); //顯示第4行
printf("12464\n");
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1