您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页单片机硬件实习报告——模拟电梯设计

单片机硬件实习报告——模拟电梯设计

来源:五一七教育网


单片机硬件实习报告

题 目 : 模 拟 电 梯 设 计 学生姓名: 学号: 学院(系: 专业班级: 指导教师:

实习时间: 2011 年 2 月 21 日  2010 年 3 月 4 日

目 录

1.前言 ............................................................ 1

1.1设计背景 .................................................................................................................................... 1 1.2设计内容 .................................................................................................................................... 1 1.3硬件实习的目的 ........................................................................................................................ 1

2.硬件电路描述及设计 .............................................. 1

2.1 电路连线及概述 ....................................................................................................................... 2 2.2 8255扫描键盘及与LED接口电路图 ...................................................................................... 2

3.软件电路描述及设计 .............................................. 3

3.1软件设计流程图 ........................................................................................................................ 3

4.源程序代码 ...................................................... 4 5.设计心得 ....................................................... 10 参考文献 ......................................................... 10

常州大学硬件实习报告

1.前言

1.1设计背景

电梯作为现代高层建筑最常用的垂直运输工具,广泛应用于社会活动的各个角落,如何保证每台电梯都能够可靠运行,已成为提高物业管理水平和电梯技术进步的关键所在。电梯运行质量直接由控制系统的功能决定,而控制系统软件又直接决定着控制系统运行的好坏。上位机监控对电梯安全运行和故障维修具有重要意义,在减少维修管理人员的同时,可及时发现故障,缩短故障候梯时间,实现管理的自动化。面向对象的程序设计更适合对现实生活中的描述,更加体现了软件的工业化的精神。

1.2设计内容

本文根据实验室提供的单片机实验箱,利用键盘、开关、数码管和 LED模拟实现八层电梯的控制。并且设计急停开关和断电维修开关以模拟实物电梯的更多的运行功能。软件利用C语言,通过检测用户请求的按键信息,根据电梯运行到相应楼层送到单片机计数来确定楼层数,并送到数码管进行显示。硬件设计简单可靠,结合软件,基本实现了八层电梯运行的模拟。 1.3硬件实习的目的

(1)利用所学过的知识,初步分析单片机原理及接口技术的能力; (2)进一步掌握硬件电路和软件功能的设计方法;

(3)了解8255可编程并行接口芯片的工作原理,掌握8255的各种模式编程方法;

(4)实验结果调试分析、总结及撰写技术报告的能力。

2.硬件电路设计及描述

2.1 电路连线及概述

第 1 页 共 12 页

常州大学硬件实习报告

P1.0-P1.7接L0-L7八个发光二极管

2.2 8255扫描键盘与LED接口电路图

第 2 页 共 12 页

常州大学硬件实习报告

3.软件设计流程及描述

3.1软件设计流程图

第 3 页 共 12 页

常州大学硬件实习报告

4.源程序代码

#include #include

/*****the address of 8255*****/ #define C8255 XBYTE[0xF22B] #define P8255A XBYTE[0xF228] #define P8255B XBYTE[0xF229] #define P8255C XBYTE[0xF22A] #define P8255 XBYTE[0xF22A] /***** three tables *****/

unsigned char code table[]={ //Segment value for LED 0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f};

unsigned char code table1[]={ 0x7f,0xbf,0xdf,0xef, 0xf7,0xfb,0xfd,0xfe}; unsigned

0x80,0x40,0x20,0x10, 0x08,0x04,0x02,0x01}; void init(); void keyscan();

void currentshow(unsigned char); void delay(); void delayms(); unsigned int move; unsigned int currentfloor; unsigned int direction; unsigned int destination[9]; char times=0;

unsigned int repairs; //0->do not repair; 1->repairing

/**************************************** ***********************************/ void main() {

unsigned char i,j;

init(); /*init the elevator*/ currentshow(currentfloor); while(1)

//2s //20ms

char

//->Extinguish the led on current floor

code

table2[]={ //P1=table1[elevator.currentlevel]|table2[elevator.currentlevel]

//0x7f->Light P1^0 ... //8255command

第 4 页 共 12 页

常州大学硬件实习报告

{

while(repairs<=250) // repairs<=250 need to repair repairs=P3^3; move=P3^1; keyscan();

while(move==254&&destination[0]!=0) //moving key was pressed {

while(repairs<=250) // repairs<=250 need to repair

repairs=P3^3;

//and at least 1 level wanted

keyscan(); move=P3^1; switch(direction) {

case 2:{

if(currentfloor==0) //declining { } else {

{ }

direction=1;

if(destination[j]==0x1)

break;

for(j=currentfloor;j>0;j--)

//weather

move=0; direction=1;

there are destinations downstairs

if(j<=0) else {

if(destination[currentfloor+1]==1) {

move=0;

destination[0]--; direction=0;

destination[currentfloor]=0; P1|=table2[currentfloor];

第 5 页 共 12 页

常州大学硬件实习报告

//Extinguish the corresponding led

}

//rising

if(currentfloor==8) //weather there are destinations { } else {

for(j=currentfloor+1;j<9;j++) { } if(j>8) { }

{

move=0;

destination[0]--; direction=0;

destination[currentfloor+1]=0; P1|=table2[currentfloor]; }

currentshow(currentfloor); currentfloor++; direction=2; else

if(destination[j]==0x1)

break;

move=0; direction=2;

}

// \"|\"->bit or

}

currentfloor--;

currentshow(currentfloor);

} break;

case 1:{

upstairs

if(destination[currentfloor+1]!=0)////////////////

//Extinguish the corresponding led// \"|\"->bit or

第 6 页 共 12 页

常州大学硬件实习报告

{

}

}

}

}

} }

}

break;

default:{ //stationary

for(i=1;i<9;i++) //decide up or down {

move=0;

destination[0]--; direction=0;

destination[currentfloor]=0;//the destination is

//do nothing but extiguish the led

if(destination[i]!=0)

break;

if(idirection=2; direction=1;

else if(i>currentfloor)//should up else

current level,

P1|=table2[currentfloor-1];

}

delay(); //2s/level

void init() //timer,elevator

unsigned char i;

/****timer and external interrupt init*******/ TMOD=0x01;

TH0=(65536-45872)/256; //50ms TL0=(65536-45872)%256; EA=1; ET0=1; EX0=1; EX1=1;

第 7 页 共 12 页

常州大学硬件实习报告

}

IT1=1;

/******elevator init******/ move=0;

/*0->the elevator now will not move,commands comes from p3^0*/

for(i=0;i<9;i++)

destination[i]=0; //no destination

direction=0; //the elevator is stationary at the start currentfloor=0;//the elevator stops at first level at the start /*****8255 init*****/

C8255=0x82; //PB in;PA,PC out repairs=P3^3;

void keyscan()

{ /*save total number of destination to destination[0]*/ /*set destination[1-9] if the correponding level wanted*/ unsigned char temp,key; P8255C=0x2; temp=P8255B;

if(temp!=0xff) //key pressed {

delayms(); temp=P8255B;

if(temp!=0xff) //confirmed {

temp=P8255B; switch(temp) { }

destination[key+1]=1; //set the corresponding level destination[0]++; //total number of destination

case

0xfe:key=0;P1&=table1[key];break;

//P1=table1[key]->light the corresponding led

case 0xfd:key=1;P1&=table1[key];break; case 0xfb:key=2;P1&=table1[key];break; case 0xf7:key=3;P1&=table1[key];break; case 0xef:key=4;P1&=table1[key];break; case 0xdf:key=5;P1&=table1[key];break; case 0xbf:key=6;P1&=table1[key];break; case 0x7f:key=7;P1&=table1[key];break;

第 8 页 共 12 页

常州大学硬件实习报告

}

}

temp=P8255B; while(temp!=0xff) temp=P8255B; }

void currentshow(unsigned char num) { }

void delayms() { }

void delay() { }

void T0_timer() interrupt 1 { }

void extern0() interrupt 0 //wait to repair {

EX1=0; if(repairs==0) { }

repairs=1;

TH0=(65536-45872)/256; //50ms TL0=(65536-45872)%256; times++; TR0=1;

while(times!=40) times=0; TR0=0;

unsigned int i,j; //delay for 20ms for(i=20;i>0;i--)

for(j=110;j>0;j--); P8255C=0x0; //wei xuan P8255A=table[num];

第 9 页 共 12 页

常州大学硬件实习报告

}

else { } EX1=1;

repairs=0;

void extern1() interrupt 3 //emergency { }

direction=0; //stop the elevator move=0;

5.设计心得

本次实习我们选择了模拟日常生活中常见的电梯运行过程。 这次实习让我对程序的设计、调试有了更深刻的认识。尤其是写单片机这类的与硬件相关的程序。在调试的时候会有不少意想不到的结果。这要求除了对程序充分了解,还要对硬件的特性,电路的连接也深刻认识。

关于程序,总结如下:必须养成在写之前仔细分析需求、要求,画出流程图,先明确各个模块的作用。最后分块细化,从底向上设计的习惯。否则很容易出现程序写了一半发现理解出错,功能达不到的情况。还有程序注释必须及时,不能等到写完了再注释,否则可能之后连自己也看不懂程序。及时的修改记录也是必要的。

对于硬件、电路:要熟练掌握如何用c、汇编语言操作芯片。要掌握常用芯片的用法、特性,至少要熟悉其datasheet,需要使用时通过查阅手册,能快速、熟练的使用该芯片。

参考文献

[1].王玉芳 钟旭.微机原理与接口技术实验教程.广东高等教育出版社.2005年5月第2次印刷.

[2]赵德安.单片机原理与应用[M].北京:机械工业出版社,2008年5月 [3]向艳,周天彤.C语言程序设计[M].北京:清华大学出版社,2008年9月.

[4]宁飞,王维华,孔宇.微型计算机原于是与接口实践[M].北京:清华大学出版社,2006.

[5]周炯如,潘操.EAT单片机应用开发系统实验指导书[M].常州:常州大学信息科学与工程学院.2010年7月.

第 10 页 共 12 页

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务