找回密码
 立即注册

QQ登录

只需一步,快速开始

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

stm32驱动lcd1602秒表显示的电路与源码 打包带走!

  [复制链接]
跳转到指定楼层
楼主
stm32驱动lcd1602秒表显示电路原理图如下:

单片机源程序如下:
  1. /*
  2. **************************************************************************************************
  3. *                                                            深圳新元电子工作室
  4. * 文件名:stm32驱动LCD1602秒表主程序
  5. * 描  述:
  6. * 版本号:V0.0
  7. * 备  注:
  8. * 程序员:贾*
  9. ***************************************************************************************************
  10. */

  11. #include "stm32f10x.h"
  12. #include "stm32f10x_gpio.h"
  13. #include "stm32f10x_rcc.h"
  14. #include "stm32f10x_tim.h"
  15. #include "misc.h"
  16. #include "stm32f10x_exti.h"

  17. #include "lcd1602.h"
  18. #include "pbdata.h"

  19. void RCC_Configuration(void);
  20. void GPIO_Configuration(void);
  21. void NVIC_Configuration(void);
  22. void TIM3_Configuration(void);
  23. void EXTI_Configuration(void);

  24. void LCD1602Display_Hour(void);
  25. void LCD1602Display_Minute(void);
  26. void LCD1602Display_Second(void);
  27. void LCD1602Display_Millisecond(void);

  28. volatile u8 hour =0;
  29. volatile u8 second = 0;
  30. volatile u8 minute = 0;
  31. volatile u8 millisecond =0;

  32. int main(void)
  33. {
  34.           RCC_Configuration(); //系统时钟初始化
  35.           GPIO_Configuration(); //端口初始化
  36.           TIM3_Configuration();
  37.           NVIC_Configuration();
  38.           EXTI_Configuration();
  39.           InitLcd1602();
  40.           LcdShowStr(0,0,"The stopwatch:");
  41.           LcdShowStr(4,1,":  :  :");
  42.          
  43.           while(1)
  44.                 {
  45.       LCD1602Display_Hour();
  46.                         LCD1602Display_Minute();
  47.                         LCD1602Display_Second();
  48.                         LCD1602Display_Millisecond();
  49.                 }
  50.         
  51. }   

  52. void RCC_Configuration(void)
  53. {
  54.    SystemInit();
  55.          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  56.          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  57.          RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
  58.          RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE);
  59.    GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
  60.          //关闭调试 端口重新映射  使用仿真器调试时,不能用此语
  61. }


  62. void GPIO_Configuration(void)
  63. {
  64.     GPIO_InitTypeDef GPIO_InitStructure;
  65.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  66.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  67.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  68.           GPIO_Init(GPIOA, &GPIO_InitStructure);   //初始化GPIOA端口
  69.           GPIO_Init(GPIOB,&GPIO_InitStructure);

  70.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  71.            //所有GPIO为同一类型端口
  72.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;         //开漏输出
  73.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         //输出的最大频率为50HZ
  74.                 GPIO_Init(GPIOB, &GPIO_InitStructure);   //初始化GPIOB端口
  75.         
  76.          // KEY
  77.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
  78.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  79.           GPIO_Init(GPIOA,&GPIO_InitStructure);

  80. }

  81. void TIM3_Configuration(void)
  82. {
  83.    
  84.          TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
  85.         
  86.           TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
  87.         
  88.           TIM_TimeBaseStruct.TIM_Period = 20;
  89.           TIM_TimeBaseStruct.TIM_Prescaler = 35999;
  90.           TIM_TimeBaseStruct.TIM_ClockDivision = 0;
  91.           TIM_TimeBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
  92.         
  93.           TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStruct);
  94.    
  95.     TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
  96.     TIM_Cmd(TIM3,DISABLE);        

  97. }


  98. void EXTI_Configuration(void)
  99. {
  100.     EXTI_InitTypeDef EXTI_InitStructure;
  101.         
  102.     EXTI_ClearITPendingBit(EXTI_Line0);
  103.           GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
  104.           EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  105.           EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  106.           EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  107.           EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  108.           EXTI_Init(&EXTI_InitStructure);
  109.         
  110.           EXTI_ClearITPendingBit(EXTI_Line1);
  111.           GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);
  112.           EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  113.           EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  114.           EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  115.           EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  116.           EXTI_Init(&EXTI_InitStructure);
  117.         
  118.     EXTI_ClearITPendingBit(EXTI_Line2);
  119.           GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2);
  120.           EXTI_InitStructure.EXTI_Line = EXTI_Line2;
  121.           EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  122.           EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  123.           EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  124.           EXTI_Init(&EXTI_InitStructure);
  125.         
  126. }

  127. void NVIC_Configuration(void)
  128. {
  129.    
  130.           NVIC_InitTypeDef NVIC_InitStructure;
  131.         
  132.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  133.           NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  134.           NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  135.           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  136.           NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  137.           NVIC_Init(&NVIC_InitStructure);
  138.         
  139.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);           // 设置NVIC中断分组2,  2位抢占优先级,2位响应优先级
  140.           NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;          // 设置外部中断通道
  141.           NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;        // 抢占优先级为2
  142.           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;        // 响应优先级为2
  143.           NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;           // 使能外部中断通道
  144.           NVIC_Init(&NVIC_InitStructure);                                              // 根据NVIC_InitStruct结构体中指定的参数初始化外设NVIC寄存器

  145.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  146.           NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
  147.           NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  148.           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  149.           NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  150.           NVIC_Init(&NVIC_InitStructure);
  151.                
  152.                 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  153.           NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
  154.           NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  155.           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  156.           NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  157.           NVIC_Init(&NVIC_InitStructure);
  158.                
  159. }

  160. void LCD1602Display_Second(void)
  161. {
  162.    u8 str[3];
  163.          str[0] = second/10 +'0';
  164.          str[1] = second%10 + '0';
  165.          str[2] = '\0';
  166.    LcdShowStr(8,1,str);        
  167. }

  168. void LCD1602Display_Millisecond(void)
  169. {
  170.    u8 str[3];
  171.          str[0] = millisecond/10 +'0';
  172.          str[1] = millisecond%10 + '0';
  173.          str[2] = '\0';
  174.    LcdShowStr(11,1,str);        
  175. }

  176. void LCD1602Display_Minute(void)
  177. {
  178.    u8 str[3];
  179.          str[0] = minute/10 +'0';
  180.          str[1] = minute%10 + '0';
  181.          str[2] = '\0';
  182.    LcdShowStr(5,1,str);        
  183. }

  184. void LCD1602Display_Hour(void)
  185. {
  186.    u8 str[3];
  187.          str[0] = hour/10 +'0';
  188.          str[1] = hour%10 + '0';
  189.          str[2] = '\0';
  190.    LcdShowStr(2,1,str);

  191. }


复制代码

所有资料51hei提供下载:
lcd1602秒表2.rar (309.01 KB, 下载次数: 284)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶2 踩
回复

使用道具 举报

沙发
ID:344852 发表于 2018-6-4 17:55 | 只看该作者
好好借鉴学习一下,谢谢大佬
回复

使用道具 举报

板凳
ID:345288 发表于 2018-6-5 11:33 | 只看该作者
谢谢大佬,很给力
回复

使用道具 举报

地板
ID:262075 发表于 2018-6-19 20:00 | 只看该作者
非常给力,感谢分享
回复

使用道具 举报

5#
ID:434132 发表于 2018-11-27 14:01 | 只看该作者
谢谢大佬
回复

使用道具 举报

6#
ID:436231 发表于 2018-11-30 00:56 | 只看该作者
感谢大佬
回复

使用道具 举报

7#
ID:428195 发表于 2018-12-19 10:09 | 只看该作者
学习一下
回复

使用道具 举报

8#
ID:428195 发表于 2018-12-19 15:09 | 只看该作者
nice,顶一个
回复

使用道具 举报

9#
ID:472917 发表于 2019-1-25 17:52 | 只看该作者
谢谢大佬
回复

使用道具 举报

10#
ID:555069 发表于 2019-6-4 21:05 来自手机 | 只看该作者
在吗?
回复

使用道具 举报

11#
ID:568794 发表于 2019-6-22 20:18 | 只看该作者
这里有pcb图吗
回复

使用道具 举报

12#
ID:467970 发表于 2019-6-23 10:52 | 只看该作者
好东西!学习!
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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