导航:首页 > 操作系统 > 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单片机实验相关的资料

热点内容
tomcat如何设置服务器 浏览:675
php编译支持mysql 浏览:815
mir4手游安卓版怎么玩国际服 浏览:21
服务器程序怎么删除 浏览:655
阿里年薪70万程序员名单照片 浏览:573
android定制输入法 浏览:758
linux下编译android 浏览:311
电影重建文件夹 浏览:981
第五人格香香解压 浏览:626
我的世界手机版推荐什么服务器 浏览:706
安卓怎么下载空战 浏览:586
程序员卖房入市 浏览:117
android视频播放窗口 浏览:288
17元特效的app名字叫什么 浏览:838
小米手机什么时候配置安卓 浏览:262
三种命令方块 浏览:565
hp服务器怎么重新做系统 浏览:480
电脑与单片机无线 浏览:611
云服务器钱怎么提现 浏览:878
华为运动app怎么退出登录 浏览:796