找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2410|回复: 1
打印 上一主题 下一主题
收起左侧

STM32单片机LCD12864结构体菜单程序

  [复制链接]
跳转到指定楼层
楼主
   12864结构体菜单


单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include"stm32f10x_conf.h"
  3. extern u8 stm[];  //外部定义nova logo
  4. extern u8 lan[],ya[],cai[],ji1[],zhong[],duan[];
  5. extern u8 qing[],dian[],zi[];
  6. u16        count=0;
  7. u8  func_index=0;
  8. u8  buffer[15]={'
  9. ,'N','O','V','A',0x00};        //发送buffer
  10. u8 BUFFER[8]={0};//接收buffer
  11. u8 bf_number;        //接收字节指示
  12. void (*current_operation_index)(); //执行当前显示函数
  13. typedef struct
  14.    {
  15.         u8 current;        //当前状态号
  16.         u8  up;//向上翻索引号
  17.         u8 down;//向下翻索引号
  18.         u8 enter;//确认索引号
  19.         u8 num_ent;//编码器确认键
  20.         void (*current_operation)(); //要执行的函数
  21.         } key_table;

  22. key_table table[32]=
  23. {
  24.           {0,0,1,3,0,(*fun1)},
  25.          {1,0,2,7,1,(*fun2)}, //菜单元素列表
  26.         {2,1,2,11,2,(*fun3)},
  27.         {3,3,4,0,3,(*fun4)},
  28.         {4,3,5,0,4,(*fun5)},
  29.         {5,4,6,0,5,(*fun6)},
  30.          {6,5,6,0,6,(*fun7)},
  31.         {7,7,8,15,7,(*fun8)},
  32.         {8,7,9,19,8,(*fun9)},
  33.         {9,8,10,23,9,(*fun10)},
  34.         {10,9,10,1,10,(*fun11)},
  35.         {11,11,12,28,11,(*fun12)},
  36.         {12,11,13,31,12,(*fun13)},
  37.         {13,12,14,13,13,(*fun14)},
  38.         {14,13,14,2,14,(*fun15)},
  39.         {15,15,16,15,25,(*fun16)},
  40.         {16,15,17,16,25,(*fun17)},
  41.         {17,16,18,17,25,(*fun18)},
  42.         {18,17,18,7,18,(*fun19)},
  43.         {19,19,20,19,26,(*fun20)},
  44.         {20,19,21,20,26,(*fun21)},
  45.         {21,20,22,21,26,(*fun22)},
  46.         {22,21,22,8,22,(*fun23)},
  47.         {23,23,24,23,27,(*fun24)},
  48.         {24,23,24,9,24,(*fun25)},
  49.         {25,7,7,7,7,(*fun26)},
  50.         {26,8,8,8,8,(*fun27)},
  51.         {27,9,9,9,9,(*fun28)},
  52.         {28,28,29,30,28,(*fun29)},
  53.         {29,28,29,30,29,(*fun30)},
  54.         {30,11,11,11,11,(*fun31)},
  55.         {31,12,12,12,12,(*fun32)}
  56. };


  57.                           
  58. int main(void)
  59. {          u8 num;
  60.   //SystemInit();         //        初始系统时钟,3.5版本库在启动文件里已经把时钟初始为72MHZ ,不需要自己初始化了。
  61.   //LED_Init();        //led 初始化
  62.   key_Init();         //按键初始化
  63.   delay_init(36); //延时初始化
  64.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断分组
  65.   SPI_GPIO_Config();        //SPI端口初始化
  66.   //EXTIX_Init();         //外部中断初始化
  67.   spi_init();          // SPI初始化
  68.   usart_init();
  69.   /* config the led */
  70.   ENC_Init(); //定时器4编码器模式初始化
  71. //Timerx_Init( 0,0);
  72. // WKUP_Init(); // 待机模式初始化 ,不注释掉,得按WAKP来开机
  73.   delay_ms(5);
  74.   initial_lcd();//液晶初始化
  75.   clear_screen();    //clear all dots
  76.   Lcdwritecom(0xb0);   //设置页地址
  77.   //GPIO_ResetBits(GPIOB,GPIO_Pin_1);

  78.   while(1)
  79.   {         
  80.   
  81.             blue_init();
  82.           // BL_PW_OFF ;  //高电平关断蓝牙模块电压
  83.           Lcdwritecom(0xaf);  /*开显示*/
  84.           clear_screen();
  85.     delay_ms(20);
  86.     display_128x64(stm);
  87.           delay_ms(1000);
  88.           delay_ms(1000);
  89.                 delay_ms(1000);
  90.           delay_ms(1000);
  91.           clear_screen();    //clear all dots
  92.                 display_graphic_16x16(4,32,qing);
  93.           display_graphic_16x16(4,48,qing);
  94.           display_graphic_16x16(4,64,dian);
  95.           display_graphic_16x16(4,80,zi);
  96.                 delay_ms(1000);
  97.           delay_ms(1000);
  98.                 delay_ms(1000);
  99.           delay_ms(1000);
  100.                 clear_screen();    //clear all dots
  101.           display_graphic_16x16(4,80,zhong);
  102.           display_graphic_16x16(4,16,lan);
  103.           display_graphic_16x16(4,32,ya);
  104.           display_graphic_16x16(4,48,cai);
  105.           display_graphic_16x16(4,64,ji1);
  106.           display_graphic_16x16(4,80,zhong);
  107.           display_graphic_16x16(4,96,duan);
  108.           delay_ms(1000);
  109.                 delay_ms(1000);
  110.           clear_screen();    //clear all dots

  111.         while(1)
  112.          {
  113.                  num=KEY_Scan();//得到键值
  114.                 if(num)
  115.         
  116.                 {
  117.                 switch(num)
  118.                         {
  119.                                 case 1:

  120.                                 func_index=table[func_index].up;  break;  //向上翻
  121.                         
  122.                         case 2:
  123.                                 func_index=table[func_index].down; break;   //向下翻
  124.                
  125.                                 case 3:
  126.                         
  127.                                 func_index=table[func_index].enter; break;   //确认
  128.                                 case 4:

  129.                                 func_index=table[func_index].num_ent; break;
  130.         
  131.                         }           
  132.          clear_screen();    //clear all dots
  133.                  }                                
  134.                 current_operation_index=table[func_index].current_operation;
  135.                 (*current_operation_index)();//执行当前操作函数
  136.     }
  137.   }
  138. }
复制代码

Keil代码下载(仅供参考): 液晶菜单.7z (647.55 KB, 下载次数: 141)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏10 分享淘帖 顶2 踩
回复

使用道具 举报

沙发
ID:837690 发表于 2022-12-14 21:42 | 只看该作者
谢谢分享,正需要这个屏幕资料,在这个论坛真的能学到很多东西
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表