導航:首頁 > 操作系統 > 51單片機實驗

51單片機實驗

發布時間:2022-01-27 06:03:08

⑴ 51單片機應該做哪些實驗

如果是剛開始學習的話,那就買一塊開發板,比如篤行之家的,一般的開發板都會配套好多實驗,你可以先學習基本的實驗,如流水燈,數碼管,點陣,lcd顯示,紅外,AD/DA,繼電器,蜂鳴器等,學完了之後就可以拔高練習。

⑵ 51單片機實驗,急

#include<reg52.h>


sbit Start = P3^0; //引腳聲明

sbit Pause = P3^1;

sbit Clear = P3^2;


unsigned char code Ledchar[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};//共陽極 0 - 9

unsigned char Ledbuf[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};//顯示緩沖區


unsigned char hour = 0;

unsigned char min = 0;

unsigned int sec = 0;

unsigned char Bms = 0;


unsigned char XH = 12; //學號 後兩位 , 你可以更改

unsigned char num = 18; //計數


char cnt = 0; //數碼管點亮位置


unsigned char index = 0;


void ConfigTimer0()

{

TMOD = 0x01;

TL0 = 0x18; //設置定時初值

TH0 = 0xFC; //設置定時重載值

ET0 = 1; //打開定時器0 中斷允許

TR0 = 1; //啟動定時器0

EA = 1; //打開總中斷

}

void main()

{

ConfigTimer0();


while(1)

{

Ledbuf[0] = 0xFF; //轉換成BCD碼 放入顯示緩沖區

Ledbuf[1] = Ledchar[num%10];

Ledbuf[2] = Ledchar[num/10%10];; // "-"

Ledbuf[3] = Ledchar[num/100];


Ledbuf[4] = 0xBF; // "-"


Ledbuf[5] = Ledchar[XH%10]; //學號

Ledbuf[6] = Ledchar[XH/10];

Ledbuf[7] = 0xFF;

}

}

void StartScan()

{

static unsigned char t = 0;

static bit Lock = 0;


if(Start == 1)

{

t = 0;

Lock = 0;

}

else if(Lock == 0)

{

t++;

if(t >= 10)

{

if(index == 0)

{

num += 2;

if(num >= 22)

{

num = 22;

}

}

else if(index == 2)

{

cnt++;

if(cnt >= 8)

{

cnt = 0;

}

}

Lock = 1;

}

}

}

void PauseScan()

{

static unsigned char t = 0;

static bit Lock = 0;


if(Pause == 1)

{

t = 0;

Lock = 0;

}

else if(Lock == 0)

{

t++;

if(t >= 10)

{

if(index == 0)

{

num -= 2;

if(num <= 14)

{

num = 14;

}

}

else if(index == 2)

{

cnt--;

if(cnt <= 0)

{

cnt = 7;

}

}

Lock = 1;

}

}

}

void ClearScan()

{

static unsigned char t = 0;

static bit Lock = 0;


if(Clear == 1)

{

t = 0;

Lock = 0;

}

else if(Lock == 0)

{

t++;

if(t >= 10)

{

index++;

if(index >= 3)

{

index = 0;

}

Lock = 1;

}

}

}

void KeyScan()

{

ClearScan();

PauseScan();

StartScan();

}

void LedScan()

{

static unsigned char i = 0;


P0 = 0xFF;


if(index == 0)

{

switch(i)

{

case 0: P2 = 0x01; P0 = Ledbuf[7]; i++; break;

case 1: P2 = 0x02; P0 = Ledbuf[6]; i++; break;

case 2: P2 = 0x04; P0 = Ledbuf[5]; i++; break;

case 3: P2 = 0x08; P0 = Ledbuf[4]; i++; break;

case 4: P2 = 0x10; P0 = Ledbuf[3]; i++; break;

case 5: P2 = 0x20; P0 = Ledbuf[2]; i++; break;

case 6: P2 = 0x40; P0 = Ledbuf[1]; i++; break;

case 7: P2 = 0x80; P0 = Ledbuf[0]; i=0; break;

default : break;

}

}

else

{

switch(cnt)

{

case 0: P2 = 0x01; P0 = Ledbuf[7]; break;

case 1: P2 = 0x02; P0 = Ledbuf[6]; break;

case 2: P2 = 0x04; P0 = Ledbuf[5]; break;

case 3: P2 = 0x08; P0 = Ledbuf[4]; break;

case 4: P2 = 0x10; P0 = Ledbuf[3]; break;

case 5: P2 = 0x20; P0 = Ledbuf[2]; break;

case 6: P2 = 0x40; P0 = Ledbuf[1]; break;

case 7: P2 = 0x80; P0 = Ledbuf[0]; break;

default : break;

}

}

}

void interruptTimer0() interrupt 1

{

static unsigned int tt = 0;


TL0 = 0x18; //設置定時初值

TH0 = 0xFC; //設置定時重載值


KeyScan();

LedScan();


if(index == 1)

{

tt++;

if(tt >= 500)

{

tt = 0;

cnt++;

if(cnt >= 8)

{

cnt = 0;

}

}

}

}


用的共陽極數碼管,, 滿足要求, 最下面的按鍵按一下 進行 數碼管切換點亮, 再按一下, 可以通過上面兩個按鍵選擇顯示那個數碼管

再按最下面的 就會回到剛開始顯示頁面,就是學號什麼的,全部顯示, 此時 上面兩個按鍵 就是對計數值進行加減2 ,

⑶ mcs-51單片機輸入輸出實驗的問題

1,上電不執行程序應該是復位階段,p1.0電平是高狀態,
2,無法計算,時鍾頻率未知
3,你的延時程序無法退出循環

⑷ 51單片機實驗(關於定時器計數器)

6mz的晶振 可算出一個時鍾周期為2微秒,200毫秒去除一下2微秒就是10000,然後吧10000取16進制為 27A0 ,用 FFFF減27A0再加1 得 C860,用定時方式一,TL0 ,#60H
TH0, #C8H

⑸ 51單片機485通訊實驗

void send(unsigned char dat)
{
DE=1; //485發送程序多了個DE控制,其他不變
SBUF=dat;
while(TI==0);
TI=0;
DE=0;
}

⑹ 51單片機流水燈實驗(我用的是手把手教你學單片機的教程)

呵呵,這個延時有點長哦,有10S,你耐心再看看,有沒有變化,如果再沒變化,你可以軟體模擬一下那個i變數。看他是不是能加到10000,。還有,學51單片機的話建議你去學 郭天祥十天學會51單片機 那個很不錯。希望採納

⑺ 51單片機AD轉換實驗,電路和程序

#include <reg51.h>
#include <INTRINS.H>
#include <STDIO.H>

// define P1.0 to check STATUS.
sbit STATUS = P1^0;

unsigned char xdata CTRL _at_ 0x2FFF;
unsigned char xdata ADSEL _at_ 0x4FFF;
unsigned char hByte;
unsigned char lByte;

void adc_Convert (void)
{ // Start a conversion with A0 and A/$C$ low.
// The convesion takes place on rising CE edge.
CTRL = 0x00;
ADSEL = 0x00;
// Wait until we have completed a conversion .
while(STATUS==1);
// Set R/$C$ with A0 low and read the low byte.
CTRL = 0x02;
hByte = ADSEL;
// Set R/$C$ with A0 high and read the high.
CTRL = 0x03;
lByte = ADSEL;
}

void main(void)
{ unsigned int delay, MSB , LSB, adc_Res;
// Initialize serial interface
SCON = 0xDA; // SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; // TH1: reload value for 1200 baud @ 12MHz */
TR1 = 1; // TR1: timer 1 run */
TI = 1; // TI: set TI to send first char of UART */

while(1)
{ adc_Convert();
MSB=(unsigned int)(hByte << 4);
LSB=(unsigned int)(lByte >> 4);
// adc_Res now has the converted data with 12-bit resolution.
adc_Res = MSB + LSB;
// Send adc results to the serial interface
printf("ADC READINGS: %03Xh\n", adc_Res);
// simple delay - it is mcu clock dependent !
for (delay=0; delay<10000; delay++)
;
}
}

⑻ 51單片機小燈實驗

給你第一用匯編第二用C吧,另一半自己搞定。

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
MOV A,#0FEH
MOV R2,#8
LOOP:
MOV P0,A
LCALL DELAY
CLR C
RLC A
DJNZ R2,LOOP
SJMP $
DEALY:
MOV R3,#200
DELAY1:
MOV R4,#250
DJNZ R4,$
DJNZ R3,DELAY1
RET
END

#include<reg51.h>
#define uchar unsigned char
uchar num;
sbit LED=P1^0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num>=200)
{
num=0;
LED=~LED;
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
LED=0;
while(1);
}

⑼ 51單片機實驗程序

#include "REG52.H"

unsigned char Extep_Time ;

/*
* T0定時器初始化 //
*/
void SystemInit(void)
{
TMOD = 0x01;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
ET0 = 1;
TR0 = 1;
EA = 1;
}

int main(void)
{
// IO初始化
P0 = 0xFF;
P1 = 0xFF;
P0 = 0xFF;
P1 = 0xFF;
// T0定時器初始化
SystemInit();
while(1);
}

/*
* T0定時器中斷服務程序
*/
void Timero_IRQ(void) interrupt 1
{
Extep_Time++;
if(Extep_Time == 20)
{
Extep_Time = 0;
P0 = ~P0;
}
}

⑽ 51單片機的實驗一般都有哪些

12864液晶顯示器,AD(電壓表),LED漸亮漸滅(PWM),遙控解碼,溫度感測器采樣,單片機播放音樂。。。。。。

閱讀全文

與51單片機實驗相關的資料

熱點內容
java如何將自己電腦設置成伺服器 瀏覽:856
域名怎麼制定伺服器8080埠 瀏覽:665
伺服器的主機如何使用 瀏覽:814
廣訊通伺服器地址怎麼填 瀏覽:665
山東交管伺服器繁忙雲空間 瀏覽:52
51單片機熱敏電阻壞了 瀏覽:547
遠程電腦是雲伺服器嗎 瀏覽:194
壓縮包解壓出來是音頻 瀏覽:946
明源雲erp伺服器故障 瀏覽:158
安卓主頁英文怎麼寫 瀏覽:844
2002伺服器系統怎麼設置分屏 瀏覽:72
什麼情況空調壓縮機電容壞 瀏覽:991
pagerank演算法圖解 瀏覽:318
部落決斗命令 瀏覽:404
單片機神經網路 瀏覽:323
加密的視頻不小心刪除怎麼恢復 瀏覽:466
安卓游戲充錢充錯帳號怎麼辦 瀏覽:206
有什麼是綁定手機號的app 瀏覽:499
phpredis事務 瀏覽:937
陰陽師pad怎麼登錄安卓賬號 瀏覽:735