您好,欢迎光临本网站![请登录][注册会员]  
文件名称: IINA219测电流51单片机
  所属分类: 硬件开发
  开发工具:
  文件大小: 165kb
  下载次数: 0
  上传时间: 2018-05-18
  提 供 者: yang*****
 详细说明: 51单片机IINA219 测电流电压和功率。 #include "LCD1602\LCD1602.h" #include "INA219_DRV\INA219_DRV.h" #include "common\common.h" #define TH0_VALUE 0x4B #define TL0_VALUE 0xFF //50ms per cycle. sbit BtnRefreshMode = P3^2; bit RefreshRate = 0; //0: 0.8s, 1: 0.5s bit RefreshFlag = 0; void RefreshData(void) { unsigned short BusVolt, Current, Power; unsigned short OffsetCurrent, OffsetPower; BusVolt = INA219_GetBusVolt(); PrintChar(0, 0, BusVolt/10000+48); PrintChar(1, 0, (BusVolt000)/100 0+48); PrintChar(3, 0, (BusVolt00)/100+48); PrintChar(4, 0, (BusVolt0)/10+48); PrintChar(5, 0, BusVolt+48); OffsetCurrent = (BusVolt >> 9) + 2; //Gather statistics of the measured current under various voltage conditions when no load is connected to the output port. Use Excel to do curve fitting. Current = INA219_GetCurrent(); if(Current > OffsetCurrent) Current -= OffsetCurrent; else Current = 0; PrintChar(10, 0, Current/1000+48); PrintChar(12, 0, (Current00)/100+48); PrintChar(13, 0, (Current0)/10+48); PrintChar(14, 0, Current+48); OffsetPower = ((BusVolt >> 3) * OffsetCurrent)/125 + 6; Power = INA219_GetPower(); if(Power > OffsetPower) Power -= OffsetPower; else Power = 0; PrintChar(0, 1, Power/10000+48); PrintChar(1, 1, (Power000)/1000+48); PrintChar(3, 1, (Power00)/100+48); PrintChar(4, 1, (Power0)/10+48); PrintChar(5, 1, Power+48); } int main(void) { INA219_Init(); LCD_Init(); TMOD &= 0xF0; TMOD |= 0x01; //Timer 0 works in Mode 1 (16-bit Timer). TH0 = TH0_VALUE; TL0 = TL0_VALUE; PrintChar(2, 0, '.'); PrintChar(6, 0, 'V'); PrintChar(11, 0, '.'); PrintChar(15, 0, 'A'); PrintChar(2, 1, '.'); PrintChar(6, 1, 'W'); PrintStr(10, 1, "R:0.8s"); RefreshData(); EA = 1; //Global Interrupt Enable ET0 = 1; //Timer 0 Interrupt Enable TR0 = 1; //Enable Timer 0. while(1) { if(RefreshFlag) { RefreshData(); RefreshFlag = 0; } if(BtnRefreshMode == 0) //If the refreshing-mode button is pressed { Delay_us(5000); if(BtnRefreshMode == 1) { Delay_us(5000); //Debouncing if(BtnRefreshMode == 1) { RefreshRate= !RefreshRate; if(RefreshRate) PrintChar(14, 1, '5'); else PrintChar(14, 1, '8'); } } } } return 0; } void Timer0ISR(void) interrupt 1 using 2 { static unsigned char Counter = 0; TH0 = TH0_VALUE; TL0 = TL0_VALUE; if(Counter < 15-6*RefreshRate) //Approximately 0.8s for slow-refreshing mode and 0.5s for fast-refreshing mode Counter++; else { Counter = 0; RefreshFlag = 1; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: IINA219 单片机
 输入关键字,在本站1000多万海量源码库中尽情搜索: