标题: 霍尔计数器单片机程序(基于金沙滩开发板+ 44E霍尔开关元件 实现) [打印本页]

作者: 伊娃    时间: 2018-11-29 10:20
标题: 霍尔计数器单片机程序(基于金沙滩开发板+ 44E霍尔开关元件 实现)
  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. }
复制代码
原理图在http://www.51hei.com/bbs/dpj-108286-1.html

霍尔计数1.7z

21.73 KB, 下载次数: 36, 下载积分: 黑币 -5

基于金沙滩开发板+ 44E霍尔开关元件 实现


作者: 45454545x    时间: 2018-12-17 09:37
hallInit();       //霍尔初始化
这个的初始化要怎么做呢??
作者: wa51单片机    时间: 2018-12-18 10:58
没有.c文件哇,脑壳痛
作者: tttt15    时间: 2018-12-18 14:24
.c文件呢
作者: axzka    时间: 2019-1-6 22:13
hall.c呢




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