完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
【NUCLEO-F412ZG试用体验】实验二 驱显12864黑白串口LCD
参考GPIO_IOToggle实例,为了保留原代码模块的完整性,自己另设两个.h模块:selfGpio.h和12864.h,放在inc目录下。代码如下: gpioSelf.h #include "STM32f4xx_hal.h" #define LCDn 4 //1=clk,2=dat,3=reg,4=res #define LCD1_PIN GPIO_PIN_4 #define LCD1_GPIO_PORT GPIOD #define LCD1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() #define LCD1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() #define LCD2_PIN GPIO_PIN_5 #define LCD2_GPIO_PORT GPIOD #define LCD2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() #define LCD2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() #define LCD3_PIN GPIO_PIN_6 #define LCD3_GPIO_PORT GPIOD #define LCD3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() #define LCD3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() #define LCD4_PIN GPIO_PIN_7 #define LCD4_GPIO_PORT GPIOD #define LCD4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() #define LCD4_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() #define LCDx_GPIO_CLK_ENABLE(__INDEX__) do {if(( __INDEX__)==0){ __HAL_RCC_GPIOB_CLK_ENABLE();} else { __HAL_RCC_GPIOB_CLK_ENABLE();}}while(0) #define LCDx_GPIO_CLK_DISABLE(__INDEX__) do {if(( __INDEX__)==0){ __HAL_RCC_GPIOB_CLK_DISABLE();} else { __HAL_RCC_GPIOB_CLK_DISABLE();}} while(0) 12864.h如下: //128x64 LCD models const unsigned char asc2[][8]={//8x6 Dots 32 to 127 + caratteri alfa_omega a seguire {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//space {0x00,0x1c,0x22,0x24,0x18,0x16,0x00,0x00},//!-1=32 {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},//" {0x00,0x02,0x04,0x78,0x10,0x0c,0x02,0x00},//# {0x00,0x7e,0x15,0x15,0x15,0x0a,0x00,0x00},//$ {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},//% {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},//& {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},//' {0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00},//( {0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00},//) {0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00},// /-10=42 {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},//+ {0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00},//; {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},//- {0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},//. {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/// {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},//0 {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},//1 {0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00},//2 {0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00},//3 {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},//4-20 {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//5 {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},//6 {0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00},//7 {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8 {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},//9 {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},//: {0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00},//; {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},//< {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},//= {0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00},//>-30 {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},//? {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},//@ {0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00},//A {0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00},//B {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},//C {0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00},//D {0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00},//E {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},//F {0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00},//G {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},//H-40 {0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00},//I {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},//J {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},//K {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},//L {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},//M {0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00},//N {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},//O {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},//P {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},//Q {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},//R-50 {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},//S {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},//T {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},//U {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},//V {0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},//W {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},//X {0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00},//Y {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},//Z {0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00},//[ {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},////-60 {0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00},//] {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},//^ {0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00},//_ {0x00,0x00,0x00,0x07,0x05,0x07,0x00,0x00},//' Insty {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},//a {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},//b {0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00},//c {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},//d {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},//e {0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00},//f-70 {0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00},//g {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},//h {0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00},//i {0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00},//j {0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00},//k {0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00},//l {0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00},//m {0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},//n {0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00},//o {0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00},//p-80 {0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00},//q {0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},//r {0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00},//s {0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},//t {0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00},//u {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},//v {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},//w {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},//x {0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00},//y {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},//z-90 {0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00},//{ {0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00},//| {0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00},//} {0x00,0x08,0x04,0x08,0x10,0x08,0x00,0x00},//~ {0x00,0x5c,0x62,0x02,0x62,0x5c,0x00,0x00},//OM {0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14},//horiz lines-96 }; //Delayer void delay0(int counter){ int i,j; for(i=0;i //Write Plus//1=clk,2=dat,3=reg,4=res void wri(void){ HAL_GPIO_WritePin(LCD1_GPIO_PORT, LCD1_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(LCD1_GPIO_PORT, LCD1_PIN, GPIO_PIN_SET); } //a B Data to LCD,dt:data,com:1-dat/0-com//1=clk,2=dat,3=reg,4=res void b2l(unsigned char dt,unsigned char com){ unsigned char i; if(com)HAL_GPIO_WritePin(LCD3_GPIO_PORT, LCD3_PIN, GPIO_PIN_SET);else HAL_GPIO_WritePin(LCD3_GPIO_PORT, LCD3_PIN, GPIO_PIN_RESET);; for(i=0;i<8;i++){ if(dt&0x80){HAL_GPIO_WritePin(LCD2_GPIO_PORT, LCD2_PIN, GPIO_PIN_SET);}else{HAL_GPIO_WritePin(LCD2_GPIO_PORT, LCD2_PIN, GPIO_PIN_RESET);}; dt=dt<<1; wri(); } } //名称: 设置坐标函数,参数:X:0~8,Y:0~100//目前只用3~0页,8~4未用? void setXY(unsigned char pag,unsigned char col){ b2l(0xB0+pag,0);//page3~0第1~第3行 //col+=4; b2l(0x10+((col&0xF0)>>4),0);//row-H4 b2l(col&0x0F,0);//row-L4 } //名称:显示英文字符,参数:c:显示的字符在font6x8表格中的位置 void c2l(unsigned char pag,unsigned char col,unsigned char c){ unsigned char line; setXY(pag,col*6); for(line=0;line<6;line++) b2l(asc2[c][line],1); } //名称: LCD清屏函数 void lcdClear(void){ unsigned char pag,col; for(pag=0xB8;pag>=0xB0;pag--){ b2l(pag,0); b2l(0x10,0); b2l(0x00,0); for(col=0;col<132;col++){b2l(0x00,1);} } } //12864LCD初始化,参数:X void lcdInit(void){ HAL_GPIO_WritePin(LCD4_GPIO_PORT, LCD4_PIN, GPIO_PIN_RESET); delay0(2000); HAL_GPIO_WritePin(LCD4_GPIO_PORT, LCD4_PIN, GPIO_PIN_SET); delay0(2000); b2l(0xAE,0);//AE=Disp Off/AF=Disp On b2l(0xE2,0);//LCD Initial b2l(0xA0,0);//Refresh Colum:A0=1-->132/A1=132-->1 b2l(0xC8,0);//Refresh COM:C0=1-->64/C8=64-->1||A0+C8:col--X-->4 b2l(0xA3,0);//A2=1/65=1/7__A3=1/65=1/9 delay0(190); b2l(0x2F,0);//Power Mode:28+VC+VR+VF delay0(100); b2l(0x23,0);//20->27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/Bian Vol delay0(100); b2l(0x81,0);//V0 Vol,After:Num b2l(0x14,0);//000000~111111=0~63=8.83~11.17V/30=10V delay0(100); b2l(0xA4,0);//A4-All Off/A5-All On b2l(0x10,0);//Column High 4 start:0x10+0000->1111 b2l(0x00,0);//Column Low 4 start:0x10+0000->1111 b2l(0x40,0);//40+xxxxxx=Disp From 0->63 b2l(0x10,0);//10+xxxx=Disp Column Migh 4 bts b2l(0x00,0);//00+xxxx=Disp Column low bits xxxxxxxx=0->131 b2l(0xAD,0);//AC=Corser Off/AD=Corser On/After Num b2l(0x03,0);//00=OFF/01=1S/02=0.5S/03=All On //b2l(0xE3,0);//NOP mode //b2l(0xE0,0);//LCD Read/Write Edit Mode On //b2l(0xEE,0);//LCD Read/Write Edit Mode Off b2l(0xAF,0);//Start Display //b2l(0xA7,0);// //delay0(20000); //b2l(0xA6,0);//A6=Normal Disp/A7=Invert Disp //delay0(20000); //delay0(1000); } main.c中加入设置io的模块 //GPIO Initial void ioInit(void){ //Enable GPIO Clock (to be able to program the configuration registers) LED1_GPIO_CLK_ENABLE(); LED2_GPIO_CLK_ENABLE(); LED3_GPIO_CLK_ENABLE(); //1=clk,2=dat,3=reg,4=res LCD1_GPIO_CLK_ENABLE(); LCD2_GPIO_CLK_ENABLE(); LCD3_GPIO_CLK_ENABLE(); LCD4_GPIO_CLK_ENABLE(); //Configure IO in output push-pull mode to drive external LEDs GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pin = LED1_PIN; HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = LED2_PIN; HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = LED3_PIN; HAL_GPIO_Init(LED3_GPIO_PORT, &GPIO_InitStruct); //1=clk,2=dat,3=reg,4=res GPIO_InitStruct.Pin = LCD1_PIN; HAL_GPIO_Init(LCD1_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = LCD2_PIN; HAL_GPIO_Init(LCD2_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = LCD3_PIN; HAL_GPIO_Init(LCD3_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = LCD4_PIN; HAL_GPIO_Init(LCD4_GPIO_PORT, &GPIO_InitStruct); } 再加入 ioInit(); lcdInit(); 就可以了,结果如下照片。此后在实验1款黑白和1款串口TFTLCD就完成显示实验了。 目前还没有弄明白8位并口或16位并口的设置和驱动方式。
|
|
相关推荐
3 个讨论
|
|
这是一个系列啊 ,楼主真的很厉害
|
|
|
|
|
|
谢谢楼主的回复 谢谢楼主 |
|
|
|
|
|
你正在撰写讨论
如果你是对讨论或其他讨论精选点评或询问,请使用“评论”功能。
1307 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1234 浏览 3 评论
2313 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1404 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1834 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 02:15 , Processed in 0.690349 second(s), Total 73, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号