|
左邊的模擬稱重傳感器電位一變,數(shù)碼管就顯示重量了中間有個(gè)數(shù)模模數(shù)轉(zhuǎn)換仿真均真實(shí)有效
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.gif (123.93 KB, 下載次數(shù): 34)
下載附件
2022-1-14 05:20 上傳
91L7IGQ8]E`MJ19YF@XNH4Y.png (53.7 KB, 下載次數(shù): 30)
下載附件
2022-1-13 21:17 上傳
單片機(jī)源程序如下:
- #include <REG52.H>
- #include <intrins.h>
- #define uchar unsigned char //宏定義方便以后用
- #define uint unsigned int
- #define ulong unsigned long
- //數(shù)碼管位選
- sbit S1=P2^0;
- sbit S2=P2^1;
- sbit S3=P2^2;
- sbit S4=P2^3;
- //定義ADC的引腳
- sbit AD_CS=P1^3;
- sbit AD_CLK=P1^0;
- sbit AD_IN=P1^1;
- sbit AD_OUT=P1^2;
- uchar Disdatabuf[5]={0}; //數(shù)碼管顯示數(shù)據(jù)
- char code SEGtable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //共陽數(shù)碼管碼表
- void delay()
- {
- uint i=5;
- while(i--);
- }
- //讀取adc數(shù)值
- uint ReadADC_TLC2543(uint CH)
- {
- uint ad=0,i;
- AD_CLK=0;
- AD_CS=0;
- CH<<=4;
- for(i=0;i<12;i++)
- {
- if(AD_OUT) ad|=0x01;
- AD_IN=(bit)(CH&0x80);
- AD_CLK=1;
- delay();
- AD_CLK=0;
- delay();
- CH<<=1;
- ad<<=1;
- }
- AD_CS=1;
- ad>>=1;
- return(ad);
-
- }
- void Delay(uint i)//1ms延時(shí)
- {
- uchar x,j;
- for(j=0;j<i;j++)
- for(x=0;x<=148;x++);
- }
- //數(shù)碼管動(dòng)態(tài)掃描
- void Show_data()
- {
- static uchar i=0;
- P0=0xff; //關(guān)閉顯示
- switch(i)
- {
- case 0: //顯示模式
- S1=1;S2=0;S3=0;S4=0;
- P0=SEGtable[Disdatabuf[3]];
- i++;
- break;
- case 1: //正反轉(zhuǎn)
- S1=0;S2=1;S3=0;S4=0;
- P0=SEGtable[Disdatabuf[2]];
- i++;
- break;
- case 2:
- S1=0;S2=0;S3=1;S4=0;
- P0=SEGtable[Disdatabuf[1]];
- i++;
- break;
- case 3:
- S1=0;S2=0;S3=0;S4=1;
- P0=SEGtable[Disdatabuf[0]];
- i=0;
- break;
-
- }
- }
- //主函數(shù)
- void main()
- {
- ulong temp=0;
- ulong AD_Data=0; //ADC數(shù)值
- while(1)
- {
- AD_Data=ReadADC_TLC2543(0); //讀取ADC
- temp= AD_Data*1000/4094;//轉(zhuǎn)化數(shù)據(jù)
- //顯示占空比
- Disdatabuf[3]= temp/1000;
- Disdatabuf[2]= temp%1000/100;
- Disdatabuf[1]= temp%100/10;
- Disdatabuf[0]=temp%10;
- Show_data(); //顯示數(shù)據(jù)
- Delay(10); //延時(shí)
- }
- }
復(fù)制代碼
Keil代碼與Proteus仿真下載:
T88稱重仿真.zip
(595.27 KB, 下載次數(shù): 35)
2022-1-13 21:16 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|