本設計:
基于51單片機的交流電流檢測系統(tǒng)設計(程序+原理圖+PCB)
原理圖:Altium Designer
程序編譯器:keil 5
編程語言:C語言
編號C0024
完整鏈接:
【騰訊文檔】C0024 網(wǎng)盤鏈接
https://docs.qq.com/doc/DS29rd2Rmdk5CT3Jz
本設計由51單片機電路+數(shù)碼管顯示電路+交流電壓檢測電路+交流電流檢測電路+電源電路組成。數(shù)碼管實時顯示交流電流值和交流電壓值。
原理圖(提供源文件):
PCB(提供源文件):
源程序(提供源文件):
#include<reg51.h>
#include "intrins.h"
#include "delay.h"
#include "display_seg.h"
#include<timer.h>
sfr P1M1 = 0x91; //PxM1.n,PxM0.n =00--->Standard, 01--->push-pull
sfr P1M0 = 0x92; // =10--->pure input, 11--->open drain
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xB1;
sfr P3M0 = 0xB2;
sfr P4M1 = 0xB3;
sfr P4M0 = 0xB4;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;
sfr ADC_CONTR = 0xBC; //ADC控制寄存器
sfr ADC_RES = 0xBD; //ADC高8位結果
sfr ADC_LOW2 = 0xBE; //ADC低2位結果
sfr P1ASF = 0x9D; //P1口第2功能控制寄存器
#define ADC_POWER 0x80 //ADC電源控制位
#define ADC_FLAG 0x10 //ADC完成標志
#define ADC_START 0x08 //ADC起始控制位
#define ADC_SPEEDLL 0x00 //540個時鐘
#define ADC_SPEEDL 0x20 //360個時鐘
#define ADC_SPEEDH 0x40 //180個時鐘
#define ADC_SPEEDHH 0x60 //90個時鐘
void InitADC();
unsigned char adVtab[5];
unsigned char adAtab[5];
unsigned char count = 0;
unsigned char GetADCResult(unsigned char ch);
void main (void)
{
unsigned int result_voltage = 0;
unsigned int result_current = 0;
unsigned int acV= 0;
unsigned int acA= 0; //擴大100倍
Init_Timer0();
//初始化端口
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P6M0 = 0x00;
P6M1 = 0x00;
P7M0 = 0x00;
P7M1 = 0x00;
InitADC(); //初始化ADC
while (1) { /* endless loop */
result_voltage = GetADCResult(7);//采集電壓值
result_current = GetADCResult(6);//采集電流值
//顯示電壓值
adVtab[count] = result_voltage;
adAtab[count] = result_current;
count++;
if(count >= 5)
{
acV = ((adVtab[0] +adVtab[1] +adVtab[2] +adVtab[3] +adVtab[4] )/5 )*220/125; // ad值為127實時 1.57v ad電壓220
acA = ((adAtab[0] +adAtab[1] +adAtab[2] +adAtab[3] +adAtab[4] )/5 )*72/100; // ad為 時 電流為0.72A 1.24V 擴大100倍電流
count = 0;
}
// acV = result_voltage * 220 / 125 ;
// if(acV < 20 ) acV = 0;
displayDat[0] = SEG_DATA[acV/100];
displayDat[1] = SEG_DATA[(acV%100)/10];
displayDat[2] = SEG_DATA[acV%10];
//高位為0時的消除處理
if(displayDat[0]==SEG_DATA[0]){
displayDat[0] = 0xff;
if(displayDat[1]==SEG_DATA[0]){
displayDat[1]=0xff;
}
}
// }
DelayMs(100);
}
}
/*----------------------------
讀取ADC結果
----------------------------*/
unsigned char GetADCResult(unsigned char ch)
{
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
_nop_(); //等待4個NOP
_nop_();
_nop_();
_nop_();
while (!(ADC_CONTR & ADC_FLAG));//等待ADC轉換完成
ADC_CONTR &= ~ADC_FLAG; //Close ADC
return ADC_RES; //返回ADC結果
}
/*----------------------------
初始化ADC
----------------------------*/
void InitADC()
{
P1ASF = 0xc0; //設置P1口為AD口
ADC_RES = 0; //清除結果寄存器
ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
DelayMs(2); //ADC上電并延時
}
資料清單如下:
閱讀全文