導航:首頁 > 操作系統 > 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單片機實驗相關的資料

熱點內容
360瀏覽器的代理伺服器如何設置 瀏覽:819
程序員經常出錯 瀏覽:420
linux查看web服務 瀏覽:509
廣東惠普伺服器續保維修雲主機 瀏覽:201
時光相冊升級後加密照片怎麼分類 瀏覽:706
linuxgz格式 瀏覽:649
郵政快遞投放點用什麼app 瀏覽:737
android啟動圖片設置 瀏覽:655
php列印sql 瀏覽:910
壓縮彈簧國標規格型號 瀏覽:631
5p壓縮機多少錢 瀏覽:59
打亂數組順序php 瀏覽:135
壓縮收納袋價格 瀏覽:318
單片機控制電動機 瀏覽:94
linuxapache編譯安裝 瀏覽:580
加密雪紡料是什麼 瀏覽:620
h2so4加密 瀏覽:312
drawpdf 瀏覽:855
創建表空間的命令 瀏覽:871
華為分屏app文件夾 瀏覽:662