实验一Keil软件的使用和定时器的应用

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一Keil软件的使用和定时器的应用
实验一Keil软件的使用和定时器的应用
一、实验原理
1、熟悉Keil软件
2、熟悉C语言编程方法和数据类型和数据结构
3、熟悉单片机的I/O口操作和定时器操作
二、实验内容:
1、熟悉Keil软件,能够查看寄存器,变量,内存单元,外部IO 口等。

2、编写一个求最小值得函数、最大值函数以及正序、逆序排序函数共四个函数,
实现在含有10个整数的元素的数组中找出最小值和最大值,进行正序、逆序排序。

要求能查看数组单元的数据,用Printf函数在Keil 的串口中显示排过序的数组元素以及最小值和最大值,并将最小值和最大值放在指定的内存单元中,通过Keil软件能够在地址中查找到该最小值和最大值。

(参考课本136页和138页的例子)
3、将实验2的四个函数分别放在四个.C文件中,利用C语言进行模块化设计。

4、编写P192的例5的程序。

通过KEIL软件中查看I/O端口变化。

5、编写时钟程序,在KEIL中的内存查看单元中能看到时、分、秒的变化,时、
分、秒采用变量和结构体两种方式实现。

参考代码1:
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
int min(int values[10]) //reentrant
{
int minimum,i;
minimum=values[0];
for(i=1;i<10;i++)
if(values[i]
return (minimum);
}
long array[12];
main()
{
int i,minimum_score;
int scores[10]={6,5,7,9,1,4,2,8,0,3}; for(i=0;i<10;i++) minimum_score=min(scores); while(1);
}
参考代码2:
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
max(int x,int y)
{
int z;
if(x>y) z=x;
else z=y;
return (z);
}
min(int x,int y)
{
int z;
if(x
else z=y;
return (z);
}
add(int x,int y)
{
int z;
z=x+y;
return (z);
}
int process(int x,int y,int (* fun)()) {
int result;
result=fun();
return(result);
}
main()
{
int a=6,b=3;
int result1,result2,result3; result1=process(a,b,max); result2=process(a,b,min); result3=process(a,b,add);
while(1);
}
参考代码3:
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
//#ifdef MONITOR51 /* Debugging with Monitor-51 needs */ //char code reserve [3] _at_ 0x23; /* space for serial interrupt if */
//#endif /* Stop Exection with Serial Intr. */
struct record{
int number;
char name[20];
float score[3];
} note={
3361,"vgk",11.25,15.15,20.05
};
void show(struct record *p)
{
int i;
printf("note.number=%d\n",p->number);
printf("/doc/a417169627.html,=%s\n" ,p->name);
for(i=0;i<3;i++)
printf("note.score[%d]=%f\n",i,p->score[i]);
}
main()
{
/*------------------------------------------------
Setup the serial port for 1200 baud at 16MHz.
------------------------------------------------*/
//#ifndef MONITOR51
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */ TR1 = 1; /* TR1: timer 1 run */ TI = 1; /* TI: set TI to send first char of UART */
//#endif
show(&note);
while(1);
}。

相关文档
最新文档