標(biāo)題:
雙端輸入萬(wàn)用表Proteus仿真設(shè)計(jì)+單片機(jī)代碼
[打印本頁(yè)]
作者:
qweeewq
時(shí)間:
2018-12-16 11:59
標(biāo)題:
雙端輸入萬(wàn)用表Proteus仿真設(shè)計(jì)+單片機(jī)代碼
注釋是亂碼,源碼不是,下載看一下
雙端輸入萬(wàn)用表仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png
(18.78 KB, 下載次數(shù): 72)
下載附件
2018-12-17 04:12 上傳
0.png
(9.52 KB, 下載次數(shù): 42)
下載附件
2018-12-17 04:12 上傳
單片機(jī)源程序如下:
#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
typedef unsigned int u16; //對(duì)數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
unsigned char receiveData[8];
#define uchar unsigned char
#define uint unsigned int
unsigned char dav[15]="v=0 . 000 V ";
unsigned char dat[16];
unsigned char dad[15]="I=00. 000 mA ";
unsigned char dab[10]="R= 000 ";//0.1
unsigned char daz[2]="Ω";
//unsigned char daw[7]="萬(wàn)用表";
unsigned char d[4]="1. ";
//unsigned char f[8]="00000";
unsigned long tmp;
float sum1,sum2,sum;
sbit CS = P2^7;//第4根線 RS
sbit SID = P2^6;//第5根線 RW
sbit SCK = P2^5;//第6根線 E
// adc0809模塊接線
sbit STR=P3^0; //單片機(jī)P1.0接模塊STR引腳, 啟動(dòng)轉(zhuǎn)換信號(hào)
sbit EOC=P3^1; //單片機(jī)P1.1接模塊EOC, 轉(zhuǎn)換結(jié)束信號(hào),高電平有效
sbit OE=P3^6; //單片機(jī)P1.2接模塊OE,輸出允許信號(hào),高電平有效
sbit CLK=P3^7;//單片機(jī)P1.3接CLK ,ADC0809時(shí)鐘,輸入50-800KHZ的頻率一般選用500K
sbit ADDA=P2^4;
sbit ADDB=P2^3;
sbit ADDC=P2^2; //單片機(jī)通道地址選擇,選in0--in7一 b 個(gè)
sbit KEY1=P0^1;//電阻
sbit KEY2=P0^2;//電壓5
sbit KEY3=P0^3;//電壓12
sbit KEY4=P0^4;//電流
uchar ad_data,adc,s,dianliu;
uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行漢字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行漢字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行漢字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行漢字位置
};
/********************************
名稱:SendByte
功能:串口發(fā)送一個(gè)字節(jié)
*********************************/
void SendByte(uchar Dbyte)
{
uchar i;
for(i=0;i<8;i++)
{
SCK = 0;
Dbyte=Dbyte<<1;
SID = CY;
SCK = 1;
SCK = 0;
}
}
/**********接收一個(gè)字節(jié)****/
uchar ReceiveByte(void)
{
uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
void CheckBusy( void )
{
do SendByte(0xfc);
while(0x80&ReceiveByte());
}
void WriteCommand(uchar Cbyte )
{
CS = 1;
CheckBusy();
SendByte(0xf8);
SendByte(0xf0&Cbyte);
SendByte(0xf0&Cbyte<<4);
CS = 0;
}
void WriteData(uchar Dbyte )
{
CS = 1;
CheckBusy();
SendByte(0xfa);
SendByte(0xf0&Dbyte);
SendByte(0xf0&Dbyte<<4);
CS = 0;
}
uchar ReadData( void )
{
CheckBusy();
SendByte(0xfe);
return ReceiveByte();
}
void Delay(uint MS)
{
uchar us,usn;
while(MS!=0)
{
usn = 2;
while(usn!=0)
{
us = 0xf5;
while (us!=0)
{
us--;
};
usn--;
}
MS--;
}
}
void LcmInit( void )
{
WriteCommand(0x30);
WriteCommand(0x03);
WriteCommand(0x0C);
WriteCommand(0x01);
WriteCommand(0x06);
}
void LcmClearTXT( void )
{
uchar i;
WriteCommand(0x30);
WriteCommand(0x80);
for(i=0;i<64;i++)
WriteData(0x20);
}
void write_str(uchar row,uchar col,uchar *puts)
{
WriteCommand(0x30);
WriteCommand(AC_TABLE[8*row+col]);
while(*puts != '\0')
{
if(col==8)
{
col='0';
row++;
}
if(row==4) row='0';
WriteCommand(AC_TABLE[8*row+col]);
WriteData(*puts);
puts++;
WriteData(*puts);
puts++;
col++;
}
}
void DisplayDots(uchar DotByte)
{
uchar i,j;
WriteCommand(0x34);
WriteCommand(0x36);
for(i=0;i<32;i++)
{
WriteCommand(0x80|i);
WriteCommand(0x80);
for(j=0;j<32;j++)
{
WriteData(DotByte);
}
DotByte=~DotByte;
}
}
unsigned long int pow(uchar a,uchar b)
{
unsigned long int result=1;// 初始化為 1
for(;b>0;b--)
{
result*=a;
}
return result;
}
void write_num(uchar x,uchar y,unsigned long int num)
{
uchar i=10;
switch (x)
{
case 0: WriteCommand(0x80+y);break;
case 1: WriteCommand(0x90+y);break;
case 2: WriteCommand(0x88+y);break;
case 3: WriteCommand(0x98+y);break;
default: ;
}
while(i>=1)
{
if((uchar)(num/pow(10,i-1))!=0)
break;
i--;
}
while(i)
{
WriteData(num/(unsigned long int)(pow(10,i-1))+'0');
num=num%(unsigned long int)(pow(10,i-1));
i--;
}
}
/********************************
名稱:delayms
功能:延時(shí)函數(shù)
*********************************/
void delayms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delayus(uint w)
{
uint x,y;
for(x=w;x>0;x--)
for(y=10;y>0;y--);
}
/*void T0init()
{
}
*/
void AD()
{
STR = 0;
OE = 0; //ad初始化
STR = 1;
STR = 0; //啟動(dòng)ad轉(zhuǎn)?
//ALE=1;
while(!EOC);
OE=1;
ad_data=P1;
delayms(20);
OE = 0;
}
void ADC_change()
{
double v;
uchar val_integer;
uint val_decimal;
v=ad_data*0.0196078;
val_integer=(uchar)v;
val_decimal=(uint)((v-val_integer)*1000);
ad_data=val_decimal;
}
void Lcd_Write(unsigned char *dat)//*********************<LCD寫(xiě)數(shù)組>
{
do{
CS = 1;
SID = 0;
SCK = 0;
s= *dat;
delayms(5);
SCK = 1;
delayms(5);
SCK = 0;
}while(*(dat++) != '\0');
}
void main( void )
{
LcmInit(); //液晶初始化
LcmClearTXT(); //清屏
TMOD = 0x02; //設(shè)置定時(shí)器T0工作方式
TH0 = 254; //
TL0 = 254; //
EA = 1; //中斷總開(kāi)關(guān)打開(kāi)
ET0 =1; // 定時(shí)器分開(kāi)關(guān)打開(kāi)
TR0 =1; //啟動(dòng)定時(shí)器
//T0init();
ADDA = 1;
ADDB = 0;
ADDC = 0;
Lcd_Write(dat);
// write_str(3,0,dav);
// write_str(0,0,dav);
// write_str(3,2,d);
//write_str(2,0,dad);
// write_str(1,0,dab);
// write_str(1,5,daz);
// write_str(0,2,daw);
while(1)
{
AD();
adc=ad_data;
delayms(10);
write_num(1,3,521);
write_num(2,3,adc);
/*tmp=adc*196.3125*5;
dat[0]=tmp/10000;
dat[2]=tmp/1000%10;
dat[3]=tmp/100%10 ;
dat[4]=tmp/10%10 ;
//電壓
sum2=(dat[2]*10+dat[3]);//電壓小數(shù)
// sprintf((char*)s,"%f",sum2);
//電阻
sum1=(dat[0]+dat[2]*0.1+dat[3]*0.01+dat[4]*0.01);
sum=120*sum1/(5-sum1);
//電流
dianliu=sum1*10;
//電阻
//#include <REGX51.H>
if(KEY1==1)
{ write_str(1,3,d);
//if(dat[0]<5){
write_num(1,3,sum);
// }
}
if(KEY1==0){
write_str(1,3,d);
}
///電壓
if(KEY2==0){
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
萬(wàn)用表.rar
(97.73 KB, 下載次數(shù): 18)
2018-12-16 11:58 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
萬(wàn)用表2.doc
(87 KB, 下載次數(shù): 9)
2018-12-16 11:58 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
lzk8023
時(shí)間:
2019-9-2 12:21
這個(gè)能夠?qū)崿F(xiàn)電流電壓和電阻的檢測(cè)嗎
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1