标题: 单片机霍尔计数源程序 [打印本页]

作者: 123456888    时间: 2018-12-18 10:46
标题: 单片机霍尔计数源程序
单片机源程序如下:
  1. //开发板+ 44E霍尔开关元件 实现
  2. //功能: 实现利用STC89单片机P33引脚上的霍尔开关引发P33引脚的中断,
  3. //实现计数功能,所计数据显示在LCD显示屏上
  4. //实验时间第12-13周

  5. //预编译
  6. #include <reg52.h>
  7. #include "LCD.h"
  8. #include "hall.h"
  9. #define NUM_LEN 5        //定义显示长度,共5位,即最大值99999=100000-1,与hall.c文件中对应

  10. //变量声明
  11. unsigned int countN = 0;
  12. unsigned int oriCountN = -1;


  13. //主函数
  14. void main()
  15. {
  16.         unsigned char str1[] = "  Hall Counter  ";
  17.         unsigned char str2[] = "                ";
  18.         unsigned char i;
  19.         unsigned int temp;         
  20.         EA=1;        //开启总中断         
  21.         hallInit();           //霍尔初始化

  22.         InitLcd1602();
  23.         LcdShowStr(0, 0, str1);
  24.         LcdShowStr(0, 1, str2);
  25.         while(1)
  26.         {
  27.                
  28.                 if(oriCountN != countN)
  29.                 {
  30.                         temp = countN ;
  31.                         oriCountN = countN;
  32.                         //以下用于刷新显示

  33.                         //将各位上的数字转化为相应字符串
  34.                         i = 1;       
  35.                         do
  36.                         {
  37.                                 str2[NUM_LEN-i] = 0x30 + temp % 10;
  38.                                 temp /= 10;
  39.                                 i++;
  40.                         }while(i<=NUM_LEN);

  41.                         //如果有前置的零,则改为空格
  42.                         i=0;       
  43.                         while(i<NUM_LEN)
  44.                         {
  45.                                 if(str2[i] == '0')
  46.                                         str2[i] = ' ';
  47.                                 else
  48.                                         break;
  49.                                 i++;
  50.                         }

  51.                        
  52.                         LcdShowStr(0, 1, str2);
  53.                 }
  54.         }
  55. }
复制代码

所有资料51hei提供下载:
霍尔计数1下发.7z (21.73 KB, 下载次数: 13)



作者: admin    时间: 2018-12-18 17:40
补全原理图或者详细说明一下电路连接即可获得100+黑币




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1