當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀] /*****************************************************************簡易正弦波\\三角波\\方波發(fā)生器使用keilC51,12MHz晶振,AT89C2051**************************************************************

/*****************************************************************
簡易正弦波三角波方波發(fā)生器
使用keilC51,12MHz晶振,AT89C2051

******************************************************************/
#include"reg51.h"
#defineucharunsignedchar
#defineuintunsignedint
#definekeyP3//鍵盤口
#definedataoutP1//正弦波等數(shù)據(jù)輸出口
//
/*************************正弦波數(shù)據(jù)表*****************************/
ucharcodesin_tab[256]=
{0x80,0x83,0x85,0x88,0x8A,0x8D,0x8F,0x92,
0x94,0x97,0x99,0x9B,0x9E,0xA0,0xA3,0xA5,
0xA7,0xAA,0xAC,0xAE,0xB1,0xB3,0xB5,0xB7,
0xB9,0xBB,0xBD,0xBF,0xC1,0xC3,0xC5,0xC7,
0xC9,0xCB,0xCC,0xCE,0xD0,0xD1,0xD3,0xD4,
0xD6,0xD7,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE,
0xDF,0xE0,0xE1,0xE2,0xE3,0xE3,0xE4,0xE4,
0xE5,0xE5,0xE6,0xE6,0xE7,0xE7,0xE7,0xE7,
0xE7,0xE7,0xE7,0xE7,0xE6,0xE6,0xE5,0xE5,
0xE4,0xE4,0xE3,0xE3,0xE2,0xE1,0xE0,0xDF,
0xDE,0xDD,0xDC,0xDB,0xDA,0xD8,0xD7,0xD6,
0xD4,0xD3,0xD1,0xD0,0xCE,0xCC,0xCB,0xC9,
0xC7,0xC5,0xC3,0xC1,0xBF,0xBD,0xBB,0xB9,
0xB7,0xB5,0xB3,0xB1,0xAE,0xAC,0xAA,0xA7,
0xA5,0xA3,0xA0,0x9E,0x9B,0x99,0x97,0x94,
0x92,0x8F,0x8D,0x8A,0x88,0x85,0x83,0x80,
0x7D,0x7B,0x78,0x76,0x73,0x71,0x6E,0x6C,
0x69,0x67,0x65,0x62,0x60,0x5D,0x5B,0x59,
0x56,0x54,0x52,0x4F,0x4D,0x4B,0x49,0x47,
0x45,0x43,0x41,0x3F,0x3D,0x3B,0x39,0x37,
0x35,0x34,0x32,0x30,0x2F,0x2D,0x2C,0x2A,
0x29,0x28,0x26,0x25,0x24,0x23,0x22,0x21,
0x20,0x1F,0x1E,0x1D,0x1D,0x1C,0x1C,0x1B,
0x1B,0x1A,0x1A,0x1A,0x19,0x19,0x19,0x19,
0x19,0x19,0x19,0x19,0x1A,0x1A,0x1A,0x1B,
0x1B,0x1C,0x1C,0x1D,0x1D,0x1E,0x1F,0x20,
0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,
0x2A,0x2C,0x2D,0x2F,0x30,0x32,0x34,0x35,
0x37,0x39,0x3B,0x3D,0x3F,0x41,0x43,0x45,
0x47,0x49,0x4B,0x4D,0x4F,0x52,0x54,0x56,
0x59,0x5B,0x5D,0x60,0x62,0x65,0x67,0x69,
0x6C,0x6E,0x71,0x73,0x76,0x78,0x7B,0x7D};
//
/***************************三角波數(shù)據(jù)表**************************/
ucharcodethr_tab[256]=
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,
0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,
0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
0xBF,0xBE,0xBD,0xBC,0xBB,0xBA,0xB9,0xB8,
0xB7,0xB6,0xB5,0xB4,0xB3,0xB2,0xB1,0xB0,
0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,
0xA7,0xA6,0xA5,0xA4,0xA3,0xA2,0xA1,0xA0,
0x9F,0x9E,0x9D,0x9C,0x9B,0x9A,0x99,0x98,
0x97,0x96,0x95,0x94,0x93,0x92,0x91,0x90,
0x8F,0x8E,0x8D,0x8C,0x8B,0x8A,0x89,0x88,
0x87,0x86,0x85,0x84,0x83,0x82,0x81,0x80,
0x7F,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,
0x77,0x76,0x75,0x74,0x73,0x72,0x71,0x70,
0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,
0x66,0x66,0x65,0x64,0x63,0x62,0x61,0x60,
0x5F,0x5E,0x5D,0x5C,0x5B,0x5A,0x59,0x58,
0x55,0x55,0x55,0x54,0x53,0x52,0x51,0x50,
0x4F,0x4E,0x4D,0x4C,0x4B,0x4A,0x49,0x48,
0x44,0x44,0x45,0x44,0x43,0x42,0x41,0x40,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
0x50,0x51,0x52,0x53,0x55,0x55,0x56,0x57,
0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
0x60,0x61,0x62,0x63,0x66,0x65,0x66,0x67,
0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
0x70,0x71,0x72,0x73,0x77,0x75,0x76,0x77,
0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F};
//
/******************************************************************************/
uintdataTHHL=65535;//T1的16位定時器初值
uchardatakeyword,n=0;//鍵值存放,查表指針
bdatasinthr;
sbitsin_thr=sinthr^0;//正弦波三角波標(biāo)志(1為正弦波)
sbitww=key^7;//方波輸出口
//
/*******************************鍵掃描子函數(shù)***********************************/
keysCAN()
{
keyword=key&0x07;
if(keyword!=0x07)
{
while((key&0x07)!=0x07);//等待鍵釋放
switch(keyword)
{
case6:{if(THHL>=65235)THHL=65535;else{THHL=THHL+255;}break;}//
case5:{if(THHL<=500)THHL=0;else{THHL=THHL-255;}break;}//
case3:{sin_thr=~sin_thr;break;}//
default:{break;}//
}
}
}
//
/***************************初始化函數(shù)****************************************/
clearmen()
{
key=0xff,dataout=0x00;THHL=65535;//按鍵輸入狀態(tài),波形輸出為0
TH1=THHL/256;TL1=THHL%256;//裝定時初值(T1用)
TMOD=0X11;ET1=1;TR1=1;EA=1;//16位定時模式,T1中斷允許,開定時器,開總中斷
}
//
/*********************************主函數(shù)***************************************/
main()
{
clearmen();
while(1)
{
keyscan();
}
}
//
/***********************************T1中斷函數(shù)**********************************/
voidtime_intt1(void)interrupt3
{
EA=0;TR1=0;TH1=THHL/256;TL1=THHL%256;TR1=1;
if(sin_thr){dataout=sin_tab[n];}
else{dataout=thr_tab[n];}
if(n>=255){n=0;}else{n++;}
ww=~ww;
EA=1;
}
//
//***********************************結(jié)束****************************************//


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險,如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學(xué)會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉