串行12864STM32程序

合集下载

基于STM32的12864串行程序

基于STM32的12864串行程序

/**********12864.c文件*************/#include "stm32f10x.h"#include "Lcd12864.h"#include <stdio.h>#define BIT(Z) (1<<Z)void CS_Set_H() //RS{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_SetBits(GPIOC,GPIO_Pin_0);}void CS_Set_L() //RS{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_ResetBits(GPIOC,GPIO_Pin_0);}void SCLK_Set_H() //E{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_SetBits(GPIOC,GPIO_Pin_2);}void SCLK_Set_L() //E{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_ResetBits(GPIOC,GPIO_Pin_2);}void SID_Set_H() //RW{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_SetBits(GPIOC,GPIO_Pin_13);}void SID_Set_L() //RW{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; /*选中管脚1*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*上拉输出*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_ResetBits(GPIOC,GPIO_Pin_13);}void Write_com_12864(u8 com){u8 i=0;CS_Set_L();SCLK_Set_L();delay_ms(5); //延时等待忙碌状态过去CS_Set_H();for(i=1;i<25;i++){SCLK_Set_H();switch(i){case 1: {SID_Set_H(); break;}case 2: {SID_Set_H(); break;}case 3: {SID_Set_H(); break;}case 4: {SID_Set_H(); break;}case 5: {SID_Set_H(); break;}case 6: {SID_Set_L(); break;}case 7: {SID_Set_L(); break;}case 8: {SID_Set_L(); break;}case 9: {if((com>>7)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 10:{if((com>>6)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 11:{if((com>>5)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 12:{if((com>>4)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 13: {SID_Set_L(); break;} case 14: {SID_Set_L(); break;} case 15: {SID_Set_L(); break;} case 16: {SID_Set_L(); break;}case 17:{if((com>>3)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 18:{if((com>>2)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 19:{if((com>>1)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 20:{if(com&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 21: {SID_Set_L(); break;}case 22: {SID_Set_L(); break;}case 23: {SID_Set_L(); break;}case 24: {SID_Set_L(); break;}default : break;}delay_ms(1);SCLK_Set_L();delay_ms(1);}}void Write_data_12864(u8 data){u8 i=0;CS_Set_L();SCLK_Set_L();delay_ms(1);CS_Set_H();for(i=1;i<25;i++){SCLK_Set_H();switch(i){case 1: {SID_Set_H(); break;}case 2: {SID_Set_H(); break;}case 3: {SID_Set_H(); break;}case 4: {SID_Set_H(); break;}case 5: {SID_Set_H(); break;}case 6: {SID_Set_L(); break;}case 7: {SID_Set_H(); break;}case 8: {SID_Set_L(); break;}case 9: {if((data>>7)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 10:{if((data>>6)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 11:{if((data>>5)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 12:{if((data>>4)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 13: {SID_Set_L(); break;}case 14: {SID_Set_L(); break;}case 15: {SID_Set_L(); break;}case 16: {SID_Set_L(); break;}case 17:{if((data>>3)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 18:{if((data>>2)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 19:{if((data>>1)&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 20:{if(data&BIT(0))SID_Set_H();elseSID_Set_L();break;}case 21: {SID_Set_L(); break;}case 22: {SID_Set_L(); break;}case 23: {SID_Set_L(); break;}case 24: {SID_Set_L(); break;}default : break;}delay_us(1);SCLK_Set_L();delay_us(1);}}void Lcd12864_init(void) //初始化LCD{Write_com_12864(0x30); //初级指令集delay_ms(1);Write_com_12864(0x02); //地址归位delay_ms(1);Write_com_12864(0x0C); //整体显示,游标off,游标位置offdelay_ms(1);Write_com_12864(0x01); //清DDRAMdelay_ms(1);Write_com_12864(0x1C); //整体显示右移delay_ms(1);}/***************************main.c文件*****************************/#include "stm32f10x.h"#include "LCD.h"//#include "USART.h"#include "eval.h"#include "SysTickDelay.h"#include "UART_INTERFACE.h"#include "chinese.h"#include <stdio.h>#include "Lcd12864.h"#define BIT(Z) (1<<Z)//u16 people_num=100,in_out=0;//u16 people_num_In=0,people_num_Out=0;/* Private typedef -----------------------------------------------------------*/typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;/* Private define ------------------------------------------------------------*//* Private macro -------------------------------------------------------------*/#define countof(a) (sizeof(a) / sizeof(*(a)))/* Private variables ---------------------------------------------------------*//* Private function prototypes -----------------------------------------------*/void RCC_Configuration(void);void GPIO_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure;/* Configure USART1 Tx (PA.09) as alternate function push-pull *///GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure USART1 Rx (PA.10) as input floating *///GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOA TING;//GPIO_Init(GPIOA, &GPIO_InitStructure);#ifdef USE_STM3210C_EV AL/* Initialize LEDs and Key Button mounted on STM3210X-EV AL board *///STM_EV AL_LEDInit(LED1);//STM_EV AL_LEDInit(LED2);/*----------------------- Configure all the GPIOA in Input Floating mode ------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; /*选中管脚8*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;/*上拉输出*/GPIO_Init(GPIOA, &GPIO_InitStructure); /*GPIO完成上面三行设置*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; /*选中管脚2*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;/*上拉输出*/GPIO_Init(GPIOD, &GPIO_InitStructure); /*GPIO完成上面三行设置*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; /*选中管脚5*/GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_4; /*选中管脚4*/GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_11;/*选中管脚11*/GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;/*最高输出速率10MHz*/GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; /*上拉输入*/GPIO_Init(GPIOC, &GPIO_InitStructure); /*GPIO完成上面三行设置*/}//系统中断管理void NVIC_Configuration(void){//NVIC_InitTypeDef NVIC_InitStructure;/* Configure the NVIC Preemption Priority Bits */NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //设置优先级分组:先占优先级0位,从优先级4位//设置向量表的位置和偏移#ifdef VECT_TAB_RAM/* Set the V ector Table base location at 0x20000000 */NVIC_SetV ectorTable(NVIC_V ectTab_RAM, 0x0); //向量表位于RAM #else /* VECT_TAB_FLASH *//* Set the V ector Table base location at 0x08000000 */NVIC_SetV ectorTable(NVIC_V ectTab_FLASH, 0x0); //向量表位于FLASH #endif}//配置系统时钟,使能各外设时钟void RCC_Configuration(void){SystemInit();//RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA // |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC// |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE// |RCC_APB2Periph_ADC1 | RCC_APB2Periph_AFIO// |RCC_APB2Periph_SPI1, ENABLE );// RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL ,ENABLE );//RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4// |RCC_APB1Periph_USART3|RCC_APB1Periph_TIM2// , ENABLE );RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */RCC_PLLCmd(ENABLE); /* Enable the PLL */RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* 选择PLL作为系统时钟*/RCC_HCLKConfig(RCC_SYSCLK_Div1); /*设置AHB时钟=72 MHz*/ RCC_PCLK1Config(RCC_HCLK_Div2); /*设置APB1时钟=36 MHz(APB1时钟最大值)*/RCC_PCLK2Config(RCC_HCLK_Div1); /*设置APB2时钟=72 MHz*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOA时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能GPIOB时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能GPIOC时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); //使能GPIOD时钟}//配置所有外设void Init_All_Periph(void){RCC_Configuration();//RCC_chushihua();NVIC_Configuration();GPIO_Configuration();//USART1_Configuration();USART_Configuration(9600);}void Delay(vu32 nCount){for(; nCount != 0; nCount--);}int main(void){//u8 a[40]={"abcdefghijklmnopqretuvwxyzabcdefghijklmn"};u8 a[54]={"山东建筑大学信息与电气工程学院检测技术与自动化装置专业"};u8 j=0;Init_All_Periph();SysTick_Initaize();Lcd12864_init();GPIO_SetBits(GPIOD,BIT(2));GPIO_SetBits(GPIOA,BIT(8));while(1){Write_com_12864(0X80);for(j=0;j<16;j++){Write_data_12864(a[j]);delay_ms(100);}Write_com_12864(0X90);for(j=16;j<32;j++){Write_data_12864(a[j]);delay_ms(100);}Write_com_12864(0X88);for(j=32;j<48;j++){Write_data_12864(a[j]);delay_ms(100);}Write_com_12864(0X98);for(j=48;j<54;j++){Write_data_12864(a[j]);delay_ms(100);}//Write_com_12864(0x01); //初级指令集//delay_ms(1000);}}#ifdef USE_FULL_ASSERT/*** @brief Reports the name of the source file and the source line number * where the assert_param error has occurred.* @param file: pointer to the source file name* @param line: assert_param error line source number* @retval None*/void assert_failed(uint8_t* file, uint32_t line){/* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* Infinite loop */while (1){}}#endif。

stm32-12864并行驱动程序

stm32-12864并行驱动程序

//////////////////////////////////////////////////////////////////////////////////stm32-12864并行驱动程序////////////////////////////////////////////////////#include "delay.h" //必须配合delay.c 和delay.h 文件使用,所以要包含delay.h。

#include "display12864.h"f/********** 以下是相关引脚定义。

**************/// A 口的#define DisIO GPIOE //定义12864 要使用的I/O 端口。

#define DisClk RCC_APB2Periph_GPIOE //定义12864 要使用的I/O 端口的时钟。

#define DataGPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7//定义12864 使用的数据引脚。

#define EN GPIO_Pin_10 //定义使能端使用的引脚/*********************************************/#define DisIOIO GPIOE //定义12864 要使用的I/O 端口。

#define DisClkIO RCC_APB2Periph_GPIOE //定义12864 要使用的I/O 端口的时钟。

#define RS #define RW GPIO_Pin_9GPIO_Pin_8/*光标定位函数定义结束。

*/#define x1 0x80#define x2 0x88#define y 0x80GPIO_InitTypeDef GPIOStru; //定义用于定义所以引脚为输出的变量。

STM32串行驱动12864液晶

STM32串行驱动12864液晶

STM32串⾏驱动12864液晶⾃⼰参考⼤神们的程序改写的液晶驱动,希望对有需要的⼈能有帮助#include "stm32f10x.h"static __IO uint32_t TimingDelay;void RCC_Configuration(void);void Delay(__IO uint32_t nTime);#define Line1 0x80//液晶第⼀⾏#define Line2 0x90//液晶第⼆⾏#define Line3 0x88//液晶第三⾏#define Line4 0x98//液晶第四⾏#define LCD_IO GPIOE //我⽤的是E.2 E.3 E.4 E.5 E.6#define CS GPIO_Pin_2#define RW GPIO_Pin_3#define CLK GPIO_Pin_4#define PSB GPIO_Pin_5#define RST GPIO_Pin_6#define SET(n) GPIO_SetBits(GPIOE,n) //将对应管脚输出⾼电平#define RESET(n) GPIO_ResetBits(GPIOE,n)//输出低电平#define CMD (uint32_t)0xf8000000 //串⾏写⼊的是命令要先写⼊0xf8 #define DATE (uint32_t)0xfa000000 // 串⾏写⼊数据要先写⼊0xfavoid LCD_IOinit_OUT() //推挽输出模式,管脚配置,不多解释,库函数有{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin =CS|RW|CLK|PSB|RST;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(LCD_IO, &GPIO_InitStructure);}void LCD_Write(uint32_t cmd,uint8_t ddata)//LCD 写函数{uint32_t temp=cmd;uint32_t i;RESET(CS); //⽚选拉低temp|=((uint32_t)(ddata&(uint8_t)0xf0)<<16)+((uint32_t)(ddata&(uint8_t)0x0f)<<12);SET(CS); //⽚选拉⾼,开始传输数据for(i=0;i<24;i++){if(temp&0x80000000)SET(RW); //取出最⾼位,如果是1,那么RW就写1 else RESET(RW); //如果是0 RW就写0SET(CLK);//向液晶写数据是在下降沿写⼊的Delay(2);//稍作延时RESET(CLK);//拉低产⽣下降沿,写⼊数据temp=temp<<1;//左移⼀位,写⼊下⼀位}RESET(CS); //拉低⽚选,写⼊数据完毕}void Display(uint8_t addr,uint8_t *hz){LCD_Write(CMD,addr);Delay(3);while(*hz!='\0'){LCD_Write(DA TE,*hz);hz++;Delay(3);}}void LCD_init()//液晶初始化{RESET(CS); //拉低⽚选RESET(PSB);//PSB拉低,表⽰是串⾏,拉⾼则是并⾏RESET(RST);//拉低RSTDelay(100);SET(RST);Delay(40);LCD_Write(CMD,0x30);//8位数据传输Delay(40);LCD_Write(CMD,0x0c);//显⽰开,游标开Delay(40);LCD_Write(CMD,0x01);//清屏Delay(40);LCD_Write(CMD,0x06);//进⼊点设定AC+1Delay(40);}int main(){RCC_Configuration();SysTick_Config(72000); //配置SYSTICK时钟节拍为1ms⼀次LCD_IOinit_OUT();LCD_init();while(1){Display(Line1,"你妹");Display(Line2,"你妹");Display(Line3,"你妹妹");Display(Line4,"完事了,哈哈哈哈哈");}}void RCC_Configuration(void){SystemInit();RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE , ENABLE); }void Delay(__IO uint32_t nTime){TimingDelay = nTime;while(TimingDelay != 0);}void TimingDelay_Decrement(void){if (TimingDelay != 0x00){TimingDelay--;}}/*temp|=((uint32_t)(ddata&(uint8_t)0xf0)<<16)+((uint32_t)(ddata&(uint8_t)0x0f)<<12);重点解释⼀下这⾥,从串⾏时序图中可以看出,发送⼀个指令需要三个字节,第⼀个是0xf8或者0xfa这个根据你要发送的是命令还是数据⽽定,然后发送下⼀个数据的⾼四位和第四位,但是数据都是在⾼四位上⾯,⽤51的话我们要分三次发送,但是32的话⼀个字节可以是32位的/所以我们⼀次就能完成,这也是为什么下⾯的i<24的原因因为最后的8位没有⽤,例如:我们发送指令0x35,则应该是这样0xf8然后0x30然后0x50,这个应该很好理解所以看⼀下上⾯的语句⾸先我们cmd的值应该为0xf8000000,这个宏定义有的,这是发送命令然后我们让cmd=temp;在把temp和后⾯的计算结果做按位或运算.⾸先看这个(uint32_t)(ddata&(uint8_t)0xf0)<<16)我们的ddtate是0x35他和0xf0按位与之后/变为0x30然后左移16位变成0x30 0000;再强制转换为32位,就把⾼位补零变为0x00 30 0000再看这句话(uint32_t) (ddata&(uint8_t)0x0f)<<12)我们的ddtate是0x35他和0x0f按位与/之后变为0x05,左移12位0x05 000 强制转换为32位⾼位补零0x000 05 000 /在和前⾯的相加就是0x00 30 0000+0x000 05 000=0x0030 5000然后在和前⾯的0xf8000000按位或变为0xf830 5000 液晶读这个数据的时候是⼋位⼋位的读取所以在液晶看来是分四次的0xf8 0x30 0x50 0x00显然后⼋位没⽤所以我们只取前⾯的24位//应该能看懂了把结合时序图还有延时⼀定要精确⼤家有看不懂的可以给我留⾔*/。

stm32驱动lcd12864程序

stm32驱动lcd12864程序

stm32驱动lcd12864程序预览说明:预览图片所展示的格式为文档的源格式展示,下载源文件没有水印,内容可编辑和复制#include "12864.h"#include "sys.h"#include "delay.h"#include "usart.h"void p_out(void) //把PB命令端口配置成输出{rs();wr();en();psb();}void wr_outite_cmd(u8 cmd) //写命令{p_out();data_out(); //把PB数据端口配置成输出rs_out=0;wr_out=0;en_out=0;GPIOB->ODR=((GPIOB->ODR&0X00FF)|(cmd<<8));delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void wr_outite_data(u8 dat) //写数据{p_out();data_out();rs_out=1;wr_out=0;en_out=0;GPIOB->ODR=((GPIOB->ODR&0X00FF)|(dat<<8)); //把dat 给PB高八位delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void LCDClear(void){wr_outite_cmd(0x01); //显示清屏delay_ms(5);wr_outite_cmd(0x34); // 显示光标移动设置delay_ms(5);wr_outite_cmd(0x30); // 显示开及光标设置delay_ms(5);}void locate_x_y(u8 x,u8 y)//指定显示坐标{u8 x2=0;x2=x;if(y<1) y=1;if(y>4) y=4;x&=0x0f;switch(y){case 1:x2|=0x80;break;case 2:x2|=0x90;break;case 3:x2|=0x88;break;case 4:x2|=0x98;break;}wr_outite_cmd(x2);delay_ms(10);}void lcd_init(void){wr_outite_cmd(0x30);delay_ms(10);wr_outite_cmd(0x01);delay_ms(10);wr_outite_cmd(0x06);delay_ms(10);wr_outite_cmd(0x0c);delay_ms(10);}void DisInt(u8 x,u8 y,int fnum) //显示整型变量的函数,最多显示16位的整数。

STM32驱动12864液晶屏

STM32驱动12864液晶屏

STM32驱动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)void RCC_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void);void Delay();uchar table[][16]={/*-- 文字: 我 --*//*-- 宋体12; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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的预存储功能*/FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);FLASH_SetLatency(FLASH_Latency_2);//设置代码延时值/*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){}/*打开相应的外部时钟: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;//设置GPIO的工作状态GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz; / /设置GPIO的速度GPIO_Init(GPIOF,&GPIO_InitStructure);GPIO_Init(GPIOA, &GPIO_InitStructure);}/******************************************************************************延时函数******************************************************************************/void Delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=100;y>0;y--);}以上是鑫洪泰的小编为你带来的液晶屏ST7565R IC驱动程序演示代码介绍,如果你想有更进一步的了解,请您关注我们微信,或者点击我们官网了解我们,也可以在线咨询或者拨打我们的热线电话与我们联系!我们会有专业的工作人员为你实时解答。

12864串行输入

12864串行输入

#include "stm32f10x_lib.h"//#include "stm32f10x_it.h"GPIO_InitTypeDef GPIO_InitStructure;ErrorStatus HSEStartUpStatus;/* 函数申明-----------------------------------------------*/void RCC_Configuration(void);void GPIO_Configuration(void);void WWDG_Configuration(void);void Delay(u32 nTime);void Delayms(vu32 m);/* 变量定义----------------------------------------------*//********************************************************************************* ** 函数名称:main(void)** 函数功能:主函数** 输入:无** 输出:无** 返回:无******************************************************************************** */#define uchar unsigned char#define uint unsigned intvoid write_com(uchar com);void write_data(uchar data);void LCD_init(void);uint com,num,i;uchar data;/* 变量定义----------------------------------------------*//*矩阵键盘PC口好用,PB口不好用,因为PB4复位后功能特定*///数据uchar ss1[]={"0123456789"};u8 ss2[]={"jizhundianya"};/********************************************************************************* ** 函数名称:main(void)** 函数功能:主函数** 输入:无** 输出:无** 返回:无******************************************************************************** */int main(void){RCC_Configuration();GPIO_Configuration();LCD_init();Delayms(100); //初始化LCDwrite_com(0x80); //显示位置第一行for(num=0;num<10;num++){write_data(ss1[num]);Delayms(1);}write_com(0x90);for(num=0;num<12;num++){write_data(ss2[num]);Delayms(1);} //显示位置第二行}void write_com(uchar com) //命令语句{uchar i;uchar i_com;i_com=0xf8;//写命令GPIO_SetBits(GPIOA, GPIO_Pin_5); // CS选通。

基于STM32的12864的串行程序

基于STM32的12864的串行程序
#include"stm32f10x_gpio.h"
#include"stm32f10x_rcc.h"
#include"12864header.h"
GPIO_InitTypeDef GPIO_InitStructure;
#define DELAY_2N 0
void Init_lcd(void)
{
//***************液晶接口初始化***********//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
void SendEData(unsigned char Data)
{
unsigned char q,w,i;
w=Data;
q=2;
set_cs() ;
while(q--)
{
for(i=0;i<4;i++)
{
w="Data"&0x80;
set_clk();
set_sid();
clr_clk();
set_clk();
clr_sid();
clr_clk();
set_clk();
SendEData(*h);
}
}//send hanzi
/*--------------------------------------------------
函数说明:写字符

JLX12864G-086P-STM32程序

JLX12864G-086P-STM32程序

LCD12864G_086P.c/*液晶程序JLX12864G-086,串行接口驱动IC是:UC1701X或兼容的IC,比如ST7565R*/#include "LCD12864G_086P.h"#include "ASCII.h"/*******************************************************列页0 1 2 3 4 5 6 7 8 9 10 11 16 13 14 15。

1271234567*******************************************************/#define CS_HighGPIO_SetBits(GPIOF, GPIO_Pin_0 )#define CS_LowGPIO_ResetBits(GPIOF, GPIO_Pin_0 )#define RST_HighGPIO_SetBits(GPIOF, GPIO_Pin_1 )#define RST_LowGPIO_ResetBits(GPIOF, GPIO_Pin_1 )#define RS_High GPIO_SetBits(GPIOF, GPIO_Pin_2 )#define RS_LowGPIO_ResetBits(GPIOF, GPIO_Pin_2 )#define SDA_HighGPIO_SetBits(GPIOF, GPIO_Pin_3 )#define SDA_LowGPIO_ResetBits(GPIOF, GPIO_Pin_3 )#define SCK_HighGPIO_SetBits(GPIOF, GPIO_Pin_4 )#define SCK_LowGPIO_ResetBits(GPIOF, GPIO_Pin_4 )/***************************************************函数功能:LCD12864G-086P I/O口配置****************************************************/void LCD12864_GPIO_Config(void){GPIO_InitTypeDefGPIO_InitStructure;RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOF, ENABLE); //使能pc端口时钟GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4; //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //工作速率GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出GPIO_Init(GPIOF,&GPIO_InitStructure);//端口结构}/*延时*/void delay(inti){intj,k;for(j=0;j<i;j++)for(k=0;k<1000;k++);}voiddelay_us(inti){while(--i);}/***************************************************函数功能:写指令到LCD模块****************************************************/voidtransfer_command(int data1){chari;CS_Low;// cs1=0;RS_Low;// rs=0;for(i=0;i<8;i++){SCK_Low;//sclk=0;if(data1&0x80){SDA_High;//sid=1;}else{SDA_Low;//sid=0;}SCK_High;//sclk=1;data1=data1<<=1;}}/*************************************************** 函数功能:写数据到LCD模块****************************************************/ voidtransfer_data(int data1){chari;CS_Low;// cs1=0;RS_High;// rs=1;for(i=0;i<8;i++){SCK_Low;//sclk=0;if(data1&0x80){SDA_High;//sid=1;}else{SDA_Low;//sid=0;}SCK_High;//sclk=1;data1=data1<<=1;}}/*************************************************** 函数功能:LCD模块初始化****************************************************/ void LCD12864G_086P_Init(void){CS_Low;// cs1=0;RST_Low;//reset=0; /*低电平复位*/SysTick_delay_ms(80);//delay(100);RST_High;//reset=1; /*复位完毕*/SysTick_delay_ms(15);//delay(20);transfer_command(0xe2); /*软复位*/SysTick_delay_ms(5);//delay(5);transfer_command(0x2c); /*升压步聚1*/SysTick_delay_ms(5);//delay(5);transfer_command(0x2e); /*升压步聚2*/SysTick_delay_ms(5);//delay(5);transfer_command(0x2f); /*升压步聚3*/SysTick_delay_ms(5);//delay(5);transfer_command(0x23); /*粗调对比度,可设置范围0x20~0x27*/transfer_command(0x81); /*微调对比度*/transfer_command(0x28); /*0x1a,微调对比度的值,可设置范围0x00~0x3f*/transfer_command(0xa2); /*1/9偏压比(bias)*/transfer_command(0xc8); /*行扫描顺序:从上到下*/transfer_command(0xa0); /*列扫描顺序:从左到右*/transfer_command(0x40); /*起始行:第一行开始*/transfer_command(0xaf); /*打开显示*/CS_High;//cs1=1;}/***************************************************函数功能:LCD发送地址****************************************************/voidlcd_address(u8 page,u8 column){CS_Low;//cs1=0;column=column-1; //我们平常所说的第1列,在LCD驱动IC里是第0列。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档