版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、STC89C51單片機(jī)產(chǎn)生正弦波、方波、三角波LED顯示頻率源程序#include <stdio.h>#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit LATCH1=P26;/定義鎖存使能端口 段鎖存sbit LATCH2=P27;/ 位鎖存unsigned char TempData8; /存儲(chǔ)顯示值的全局變量unsigned char code DuanMa10=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;/ 顯示
2、段碼值09unsigned char code DuanMa210=0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef;/ 顯示段碼值09unsigned char code DuanMa13=0x77,0x7c,0x39;unsigned char code WeiMa=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f;/分別對應(yīng)相應(yīng)的數(shù)碼管點(diǎn)亮,即位碼#define DataPort P0sbit keyA=P33;sbit keyB=P34;sbit keyC=P35;sbit wc=P10;sbit scl=
3、P11;sbit sda=P12;sbit scl1=P13;sbit sda1=P14;sbit p5=P15;sbit p6=P16;sbit p7=P17;uint sign,ad;uchar temp10, temp13;/定義顯示區(qū)域臨時(shí)存儲(chǔ)數(shù)組uchar voltage; /定義浮點(diǎn)變量uchar l=0,m=100,n=0;uchar code sin200 = 52,53,55,56,58,59,61,62,64,65,67,68,70,71,73,74,75,77,78,79,81,82,83,84,85,86,88, 89,90,90,91,92,93,94,95,95,9
4、6,96,97,97,98,98,98,99,99,99,99,100,100,100,100,100,99, 99,99,99,98,98,98,97,97,96,96,95,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,79,78, 77,75,74,73,71,70,68,67,65,64,62,61,59,58,56,55,53,52,50,48,47,45,44,42,41,39,38,36, 34,33,32,30,29,27,26,24,23,22,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,5
5、,4,4,3,2,2, 2,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,2,2,2,3,4,4,5,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,22,23,24,26,27,29,30,32,33,35,36,38,39,41,42,44,45,47,48,50;void DelayUs2x(unsigned char t) while(-t);void DelayMs(unsigned char t) while(t-) /大致延時(shí)1mS DelayUs2x(245); DelayUs2x(245); void delay() ;
6、void delay1(uchar x) uchar a,b;for(a=x;a>0;a-) for(b=110;b>0;b-);void Delay2(unsigned int t) while(-t);void Display() uchar i; for(i=0;i<4;i+) DataPort=WeiMai; /取位碼 LATCH2=1; /位鎖存 LATCH2=0; if(i=0) DataPort=DuanMa1sign-1; else if(i=1) DataPort=DuanMa2temp1i; else DataPort=DuanMatemp1i; /取顯示
7、數(shù)據(jù),段碼 LATCH1=1; /段鎖存 LATCH1=0; Delay2(500); / 掃描間隙延時(shí),時(shí)間太長會(huì)閃爍,太短會(huì)造成重影 /pcf8591void init1()sda1=1;delay();scl1=1;delay();void start1() /開始信號sda1=1;delay();scl1=1;delay();sda1=0;delay();void stop1() /停止sda1=0;delay();scl1=1;delay();sda1=1;delay();void respons1() /應(yīng)答uchar i;scl1=1;delay();while(sda1=1)&
8、amp;&(i<250)i+;scl1=0;delay();void write_byte1(uchar date)uchar i,temp;temp=date;for(i=0;i<8;i+)temp=temp<<1;scl1=0; delay();sda1=CY;delay();scl1=1;delay();scl1=0;delay();sda1=1;delay();uchar read_byte1()uchar i,k;scl1=0;delay();sda1=1;delay();for(i=0;i<8;i+)scl1=1;delay();k=(k<
9、;<1)|sda1;scl1=0;delay();return k;void write_add1(uchar date) /寫入DAstart1();write_byte1(0x90);respons1();write_byte1(0x40);respons1();write_byte1(date);respons1(); / delay1(100);stop1();uchar read_add1( uchar address ) /讀AD值uchar date;start1();write_byte1(0x90);respons1();write_byte1(0x40|address
10、);respons1();start1();write_byte1(0x91);respons1();date=read_byte1();stop1();return date;/鍵盤void keyscan()if(keyA=0)delay1(10);if(keyA=0)sign=1;while(!keyA); if(keyB=0)delay1(10);if(keyB=0)sign=2;while(!keyB);if(keyC=0)delay1(10);if(keyC=0)sign=3;while(!keyC);/eepromvoid start() /開始信號sda=1;delay();s
11、cl=1;delay();sda=0;delay();void stop() /停止sda=0;delay();scl=1;delay();sda=1;delay();void respons() /應(yīng)答uchar i;scl=1;delay();while(sda=1)&&(i<250)i+;scl=0;delay();void init()sda=1;delay();scl=1;delay();void write_byte(uchar date)uchar i,temp;temp=date;for(i=0;i<8;i+)temp=temp<<1;s
12、cl=0; delay();sda=CY;delay();scl=1;delay();scl=0;delay();sda=1;delay();uchar read_byte()uchar i,k;scl=0;delay();sda=1;delay();for(i=0;i<8;i+)scl=1;delay();k=(k<<1)|sda;scl=0;delay();return k;void write_add(uchar date,uchar address )uchar i,*pdate;pdate=date;for(i=0;i<2;i+)start();write_b
13、yte(0xae);respons();write_byte(address+i);respons();write_byte(*(pdate+i);respons();stop();void read_add(uchar date ,uchar address )uchar i,*pdate; pdate=date;for(i=0;i<2;i+)start();write_byte(0xae);respons();write_byte(address+i);respons();start();write_byte(0xaf);respons();*(pdate+i)=read_byte(
14、);stop();void sj() if(l<100)write_add1(l);l+;if(l>=100&m>0)write_add1(m);m-;if(l>=100&m<=0)l=0;m=100;p5=0;p6=1;p7=1;void zx()if(l<200)write_add1(sinl);l+;if(l>=200) l=0;p6=0;p7=1;p5=1;void fb()if(l<100)write_add1(255);l+;if(l>=100&n<100)write_add1(0);n+;if(l
15、>=100&n>=100)l=0;n=0;p7=0;p5=1;p6=1;void main() uchar i,num,tab2;/定義顯示區(qū)域臨時(shí)存儲(chǔ)數(shù)組 wc=0; num=0;tab0=0;tab1=0;TMOD=0x21;/設(shè)置定時(shí)器1為工作方式2定時(shí)器0為工作方式1TH1=0xfd;TL1=0xfd;TR1=1;REN=1;SM0=0;SM1=1;EA=1;ES=1;init();init1();for(i=0;i<5;i+)num=read_add1(0);read_add(tab,1);sign=tab0; ad=(uint)num*100;TH0=(65536-ad)/256; TL0=(65536-ad)%256; ET0=1; /定時(shí)器中斷打開TR0=1; while(1) keyscan(); for(i=0;i<5;i+) num=read_add1(0); voltage=500/num; ad=(uint)num*100;tab0=sign;tab1=ad;write_add(tab,1);num=read_add1(0); voltage=500/num; temp
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度企業(yè)職工工傷保險(xiǎn)補(bǔ)貼專項(xiàng)資金使用協(xié)議3篇
- 二零二五年度個(gè)人出租公寓合同(含社區(qū)文化活動(dòng)參與)3篇
- 二零二五年度水產(chǎn)養(yǎng)殖產(chǎn)品出口代理合同樣本
- 二零二五版商場物業(yè)管理合同范本(綠色能源利用規(guī)劃)3篇
- 二零二五年度個(gè)人工業(yè)房產(chǎn)買賣合同樣本(含配套設(shè)施移交清單)4篇
- 二零二五年度商業(yè)廣場物業(yè)合作項(xiàng)目保密協(xié)議示范文本3篇
- 二零二五版收養(yǎng)協(xié)議書范本:收養(yǎng)人與被收養(yǎng)人監(jiān)護(hù)責(zé)任3篇
- 二零二五年度鋼房租賃及節(jié)能改造與租賃服務(wù)合同
- 2025年度個(gè)人房產(chǎn)租賃貸款擔(dān)保合同匯編3篇
- 煙道防腐施工方案
- 七年級歷史下冊第2課唐朝建立與貞觀之治
- 8.3+區(qū)域性國際組織+課件高中政治統(tǒng)編版選擇性必修一當(dāng)代國際政治與經(jīng)濟(jì)
- 2025年國網(wǎng)陜西省電力限公司高校畢業(yè)生招聘1100人(第二批)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 《深度學(xué)習(xí)的7種有力策略》
- 藥店員工培訓(xùn)
- 李四光《看看我們的地球》原文閱讀
- 抖音火花合同電子版獲取教程
- 隱患排查治理資金使用專項(xiàng)制度
- 家具定做加工合同
- 中國心胸外科的歷史和現(xiàn)狀
- 人教版9年級全一冊英語單詞表
評論
0/150
提交評論