代码:/************************************************************************** * 文件名:main.c * 开发板:STM32F107VCT6*****************************************************************************/ (1)#include "main.h"int main(void){ SystemInit(); Key_Init(); LED_Init(); LCD_GPIO_Configuration(); LCD6800_Init(); Display_String(name1); while(1) { }; }(2)#ifndef _LCD6800_H_#define _LCD6800_H_ #include "stm32f10x.h"#include "LED.h" #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 //数据口LCD的D0-D7接到了PD7-PD0#define LCDDB0 GPIOD,GPIO_Pin_7#define LCDDB1 GPIOD,GPIO_Pin_6#define LCDDB2 GPIOD,GPIO_Pin_5#define LCDDB3 GPIOD,GPIO_Pin_4#define LCDDB4 GPIOD,GPIO_Pin_3#define LCDDB5 GPIOD,GPIO_Pin_2#define LCDDB6 GPIOD,GPIO_Pin_1#define LCDDB7 GPIOD,GPIO_Pin_0 #define Data_Out(x) GPIOD->ODR=(GPIOD->ODR&0xff00)|(x&0x00ff);#define LCD_column 0x40 #define LCD_Page 0xb8 #define LCD_ON 0x3f #define LCD_OFF 0x3e #define LCD_StartLine 0xc0 #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 Write_Cmd(uint8_t Chipselect,uint8_t cmd);void Write_Data(uint8_t Chipselect,uint8_t data);void Display_String(const uint8_t *DisplayData);void delay_ms(uint16_t nms);void delay_us(uint32_t nus); #endif (3)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; 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; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 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_ms(10); LCD_RST_1; Write_Cmd(1,0x3f); // display ON; Write_Cmd(2,0x3f); // for all chips Write_Cmd(3,0x3f); Write_Cmd(4,0x3f); Write_Cmd(1,0xc0); // start line =0; Write_Cmd(2,0xc0); // for all chips Write_Cmd(3,0xc0); Write_Cmd(4,0xc0); }// write command void Write_Cmd(uint8_t Chipselect,uint8_t cmd){ cmd=((cmd&0x01)<<7)|((cmd&0x02)<<5)|((cmd&0x04)<<3)|((cmd&0x08)<<1)|((cmd&0x10)>>1)|((cmd&0x20)>>3)|((cmd&0x40)>>5)|((cmd&0x80)>>7); LCD_RS_0; LCD_RW_0; Data_Out(cmd); switch(Chipselect) { case 1: LCD_CSC_0; LCD_CSB_0; LCD_CSA_0; break;// write into 1st driver case 2: LCD_CSC_0; LCD_CSB_0; LCD_CSA_1; break;// write into 2st driver case 3: LCD_CSC_0; LCD_CSB_1; LCD_CSA_0; break;// write into 3st driver case 4: LCD_CSC_0; LCD_CSB_1; LCD_CSA_1; break;// write into 4st driver } LCD_E_1; delay_ms(1); LCD_E_0; LCD_CSC_1; LCD_CSB_0; LCD_CSA_0;// disable all drivers } //==================== // write data //==================== void Write_Data(uint8_t Chipselect,uint8_t data){ data=((data&0x01)<<7)|((data&0x02)<<5)|((data&0x04)<<3)|((data&0x08)<<1)|((data&0x10)>>1)|((data&0x20)>>3)|((data&0x40)>>5)|((data&0x80)>>7); LCD_RS_1; LCD_RW_0; Data_Out(data); switch(Chipselect) { case 1: LCD_CSC_0; LCD_CSB_0; LCD_CSA_0; break;// write into 1st driver case 2: LCD_CSC_0; LCD_CSB_0; LCD_CSA_1; break;// write into 2st driver case 3: LCD_CSC_0; LCD_CSB_1; LCD_CSA_0; break;// write into 3st driver case 4: LCD_CSC_0; LCD_CSB_1; LCD_CSA_1; break;// write into 4st driver } LCD_E_1; delay_ms(1); LCD_E_0; LCD_CSC_1; LCD_CSB_0; LCD_CSA_0;// disable all drivers } void Display_String(const uint8_t *DisplayData) // DisplayData should be 256x64/8 = 2048 bytes { uint8_t TempData; uint8_t i; uint32_t j; for(i=0;i<8;i++) { Write_Cmd(1,0xb8 | i); // select page no to all driver Write_Cmd(2,0xb8 | i); Write_Cmd(3,0xb8 | i); Write_Cmd(4,0xb8 | i); Write_Cmd(1,0x40); // set column 00h to all driver Write_Cmd(2,0x40); Write_Cmd(3,0x40); Write_Cmd(4,0x40); for(j=0;j<=255;j++) { TempData=(*(DisplayData+(i*256)+j)); if ((j>=0) & (j<=63)) { Write_Data(1,TempData); // 0~63 column goto driver 1 } if ((j>=64) & (j<=127)) { Write_Data(2,TempData); // 64~127 column goto driver 2 } if ((j>=128) & (j<=191)) { Write_Data(3,TempData); // 128~191 column goto driver 3 } if ((j>=192) & (j<=255)) { Write_Data(4,TempData); // 192-255 column goto driver 4 } } } }(4)const uint8_t name1[]={0x00,0x10,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC,0x04,0x04,0x00,0x00,0x00,0x01,0x19,0x19,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC,0x04,0x04,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0xF8,0x04,0x04,0x04,0x08,0xFC,0x04,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x04,0x8C,0x74,0x70,0x8C,0x04,0x00,0x00,0x01,0x19,0x19,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC,0x04,0x04,0x00,0x00 };
一周热门 更多>