* 基于STM32F107VCT6
*****************************************************************************/
#include "main.h"
void Delay(__IO uint32_t nCount);
int main(void)
{
SystemInit();
Key_Init();
LCD_GPIO_Configuration();
LCD6800_Init();
LED_Init();//灯不亮
Display_String(1,0,0,BMPecdav_start);
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
LCD6800.c文件
void LCD_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//¸′λòy½Å
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_12;//ƬѡÏß
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &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;//êy¾YÏß
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//íÆíìêä3ö
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4;//¿ØÖÆÏß
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//íÆíìêä3ö
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void LCD6800_Init(void)
{
LCD_RST_0;
Delay(7200);
LCD_RST_1;
//Delay(7200);
Select_Screen(0)
Write_Cmd(LCD_OFF);
Write_Cmd(LCD_ON);
Write_Cmd(LCD_StartLine)
LCD_Clear()
LED_Init();
}
void Display_Screen1(void)//开显示屏1
{
LCD_CSC_0;
LCD_CSB_0;
LCD_CSA_0;
}
void Display_Screen2(void)
{
LCD_CSC_0;
LCD_CSB_0;
LCD_CSA_1;
}
void Display_Screen3(void)
{
LCD_CSC_0;
LCD_CSB_1;
LCD_CSA_0;
}
void Display_Screen4(void)/
{
LCD_CSC_0;
LCD_CSB_1;
LCD_CSA_1;
}
void Select_Screen(uint8_t screen)
{
switch(screen)
{
case 0
Display_Screen1();
Display_Screen2();
Display_Screen3();
Display_Screen4();
break;
case 1:
Display_Screen1();
break;
case 2:
Display_Screen2();
break;
case 3:
Display_Screen3();
break;
case 4:
Display_Screen4();
break;
default:
break;
}
}
uint8_t LCD_busy(void)
{
uint8_t x;
LCD_RS_0;
LCD_RW_1;
LCD_E_1;
Delay(1000);
x=Text_Busy;
LCD_E_0;
return x;
}
void Write_Cmd(uint8_t cmd)
{
while(LCD_busy());
LCD_RS_0
LCD_RW_0
Data_Out(cmd)
Delay(1000)
LCD_E_1
Delay(1000);
LCD_E_0
}
void Write_Data(uint8_t data)
{
while(LCD_busy());
LCD_RS_1
LCD_RW_0
Data_Out(data);
Delay(1000)
LCD_E_1
Delay(1000)
LCD_E_0
}
void Display_String(uint8_t screen,uint8_t x,uint8_t y,const uint8_t *dat)
{
Select_Screen(screen);
if(y>=64)
{
y=y-1;
}
Write_Cmd(0x40|y);
Delay(1000);
Write_Cmd(0xb8|x);
Write_Data(*dat++);
}
void LCD_Clear(void)
{
uint16_t i,j;
Select_Screen(1)
for(i=0;i<8;i++)
{
Write_Cmd(LCD_Page+i);
Write_Cmd(LCD_column);
for(j=0;j<64;j++)
{
Write_Data(0x00);
}
}
Select_Screen(2);
for(i=0;i<8;i++)
{
Write_Cmd(LCD_Page+i);
Write_Cmd(LCD_column);
for(j=0;j<64;j++)
{
Write_Data(0x00);
}
}
Select_Screen(3)
for(i=0;i<8;i++)
{
Write_Cmd(LCD_Page+i);
Write_Cmd(LCD_column);
for(j=0;j<64;j++)
{
Write_Data(0x00);
}
}
Select_Screen(4)
for(i=0;i<8;i++)
{
Write_Cmd(LCD_Page+i);
Write_Cmd(LCD_column);
for(j=0;j<64;j++)
{
Write_Data(0x00);
}
}
}
LCD6800.h文件
#ifndef _LCD6800_H_
#define _LCD6800_H_
#include "stm32f10x.h"
#include "LED.h"
#define uchar unsigned char
#define uint unsigned int
#define RST GPIOB,GPIO_Pin_5
#define RW GPIOE,GPIO_Pin_4
#define RS GPIOE,GPIO_Pin_3
#define E GPIOE,GPIO_Pin_2
#define CSA GPIOC,GPIO_Pin_12
#define CSB GPIOC,GPIO_Pin_9
#define CSC GPIOC,GPIO_Pin_8
#define D0 GPIOD,GPIO_Pin_7
#define D1 GPIOD,GPIO_Pin_6
#define D2 GPIOD,GPIO_Pin_5
#define D3 GPIOD,GPIO_Pin_4
#define D4 GPIOD,GPIO_Pin_3
#define D5 GPIOD,GPIO_Pin_2
#define D6 GPIOD,GPIO_Pin_1
#define D7 GPIOD,GPIO_Pin_0
#define LCD_DataPort GPIOD
//#define ReadData LCD_DataPort->IDR
#define Data_Out(x) LCD_DataPort->ODR=(LCD_DataPort->ODR&0xff00)|(x&0x00ff)
#define Text_Busy GPIO_ReadInputDataBit(GPIOD ,GPIO_Pin_0)
#define LCD_column 0x40
#define LCD_Page 0xb8
#define LCD_ON 0x3f
#define LCD_OFF 0x3e
#define LCD_StartLine 0xc0
#define LCD_Busy 0x80
//#define LCD_Clear 0x01
#define LCD_RST_1 GPIO_SetBits(GPIOB,GPIO_Pin_5); //RST = 1
#define LCD_RST_0 GPIO_ResetBits(GPIOB,GPIO_Pin_5); //RST = 0
#define LCD_RS_1 GPIO_SetBits(GPIOE,GPIO_Pin_3); //RS=1
#define LCD_RS_0 GPIO_ResetBits(GPIOE,GPIO_Pin_3); //RS=0
#define LCD_RW_1 GPIO_SetBits(GPIOE,GPIO_Pin_4); //R/W=1
#define LCD_RW_0 GPIO_ResetBits(GPIOE,GPIO_Pin_4); //R/W = 0
#define LCD_E_1 GPIO_SetBits(GPIOE,GPIO_Pin_2); //E = 1
#define LCD_E_0 GPIO_ResetBits(GPIOE,GPIO_Pin_2); //E = 0
#define LCD_CSC_1 GPIO_SetBits(GPIOC,GPIO_Pin_8); //CSC = 1
#define LCD_CSC_0 GPIO_ResetBits(GPIOC,GPIO_Pin_8); //CSC = 0
#define LCD_CSB_1 GPIO_SetBits(GPIOC,GPIO_Pin_9); //CSB = 1
#define LCD_CSB_0 GPIO_ResetBits(GPIOC,GPIO_Pin_9); //CSB = 0
#define LCD_CSA_1 GPIO_SetBits(GPIOC,GPIO_Pin_12); //CSA = 1
#define LCD_CSA_0 GPIO_ResetBits(GPIOC,GPIO_Pin_12); //CSA = 0
void LCD6800_Init(void);
void LCD_GPIO_Configuration(void);
void Display_Screen1(void);
void Display_Screen2(void);
void Display_Screen3(void);
void Display_Screen4(void);
void Select_Screen(uint8_t screen);
uint8_t LCD_busy(void);
void Write_Cmd(uint8_t cmd);
void Write_Data(uint8_t data);
void Display_String(uint8_t screen,uint8_t x,uint8_t y,const uint8_t *dat);
void LCD_Clear(void);
#endif
|