c#實(shí)現(xiàn)51單片機(jī)頻率計(jì)的代碼分享(數(shù)字頻率計(jì)設(shè)計(jì))
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
//按鍵
sbit button=P1^7;
//LED
sbit led2=P3^5;
sbit led3=P3^7;
//數(shù)碼管位選
sbit c0 = P3^0;
sbit c1 = P3^1;
sbit c2 = P3^2;
sbit c3 = P3^3;
//數(shù)碼管段碼
uchar code dm[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar wm[]={0,0,0,0};
ulong pl;
uchar mode;
void delay3ms(void) //誤差 0us
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=176;b>0;b--)
for(a=7;a>0;a--);
}
void smg()
{
static uchar i=0;
c0=1;c1=1;c2=1;c3=1;
P1 = 0XFF;
switch(i)
{
case 0: c0=0;
break;
case 1: c1=0;
break;
case 2: c2=0;
break;
case 3: c3=0;
break;
}
P1 = dm[wm[i]];
i++;
if(i>3)
{
i=0;
}
}
void ledmode()
{
switch(mode)
{
case 0:led2=led3=0;
break;
case 1:led2=1;led3=0;
break;
case 2:led2=0;led3=1;
break;
case 3:led2=led3=1;
break;
}
}
void key()
{
static uchar num;
delay3ms();
button=1;
switch(num)
{
case 0: if(!button)
{
num=1;
}
break;
case 1: if(!button)
{
if(mode<3)
{
mode++;
}
else
{
mode=0;
}
num=2;
}
else
{
num=0;
}
break;
case 2: if(button)num=3;
break;
case 3: if(button)num=0;
break;
}
}
void timeinit()
{
TMOD=0x15; //設(shè)置T0T1控制字
TH0=0x00;
TL0=0x00;
TH1=0xfC;
TL1=0x18;
ET0=1; //定時(shí)器0中斷允許
ET1=1;
TR0=1; //啟動(dòng)T0計(jì)數(shù)
TR1=1; //并啟動(dòng)T1計(jì)數(shù)
EA=1; //CPU開中斷
}
void main()
{
timeinit();
while(1)
{
smg();
ledmode();
key();
}
}
void t1()interrupt 3
{
static uint time;
TR0=0;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
time++;
if(time>99)
{
time=0;
pl=TH0*256+TL0;
wm[0]=(pl/1000)%10;
wm[1]=(pl/100)%10;
wm[2]=(pl/10)%10;
wm[3]=pl%10;
TH0=TL0=0;
}
TR0=1;
}
- C語言宏定義結(jié)合全局變量的方法實(shí)現(xiàn)單片機(jī)串口透傳模式
- android實(shí)現(xiàn)手機(jī)與單片機(jī)藍(lán)牙模塊通信
- Android Socket 線程連接openwrt與arduino單片機(jī)串口雙向通信的實(shí)例解析
- Android與單片機(jī)通信常用數(shù)據(jù)轉(zhuǎn)換方法總結(jié)
- Android單片機(jī)與藍(lán)牙模塊通信實(shí)例代碼
- 使用UART與PC通信實(shí)現(xiàn)msp430g2553單片機(jī)超聲波測距示例
- 關(guān)于單片機(jī)按鍵問題性能提升總結(jié)
相關(guān)文章
C#學(xué)習(xí)筆記整理_變量等基礎(chǔ)語法(必看篇)
下面小編就為大家?guī)硪黄狢#學(xué)習(xí)筆記整理_變量等基礎(chǔ)語法(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09
C# Lambda表達(dá)式select()和where()的區(qū)別及用法
這篇文章主要介紹了C# Lambda表達(dá)式select()和where()的區(qū)別及用法,select在linq中一般會(huì)用來提取最后篩選的元素集合,在lambda表達(dá)式中通常用where得到元素集合,需要的朋友可以參考下2023-07-07
C#將PDF文檔轉(zhuǎn)換為Markdown文檔的代碼實(shí)現(xiàn)
將PDF文件轉(zhuǎn)換為Markdown格式是一個(gè)非常實(shí)用的需求,尤其是在需要將內(nèi)容從固定布局的PDF文件中提取出來,并轉(zhuǎn)換為更易于編輯和處理的文本格式時(shí),本文將介紹如何通過C#代碼將PDF文檔轉(zhuǎn)換Markdown(MD)文檔,需要的朋友可以參考下2024-10-10
C#實(shí)現(xiàn)Ruby的負(fù)數(shù)索引器
這篇文章主要介紹了C#實(shí)現(xiàn)Ruby的負(fù)數(shù)索引器的相關(guān)代碼和使用方法,非常簡單實(shí)用,需要的朋友可以參考下2016-07-07
在C#中如何使用正式表達(dá)式獲取匹配所需數(shù)據(jù)
本文給大家分享C#中如何使用正式表達(dá)式獲取匹配所需數(shù)據(jù) ,非常實(shí)用,對(duì)正則表達(dá)式獲取匹配相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-03-03

