调试单片机AT89S51

画了一个关于按次序提供不同电压的PCB板子。上电次序由单片机AT89S51控制。下面就是制作流程了。

开始的时候,完全不懂怎么写单片机的程序及把程序写入单片机,就开始了摸索过程。

首先是写程序,从图书馆借到《完全手册--51单片机C语言开发详解》张天凡写的一本书,借鉴跑马灯的程序,比较快速的写完了程序,总共32行,我就知道自己没有什么技术含量的,哈哈。

#include <reg51.h>
#define Ticks 10000

void DelayTimeByTick(unsigned int ticks)
{
// we assume that the frequency is 12MHz
// so we get one operation time=12*(1/12MHz)=10^-6s=1us
// the tick time =120*1us*10=1200us;because of "while" need more time.
// all the delay time=ticks*1200us.
// if ticks=10000, the delay time=12s  
	unsigned  int  t=0;
	while(ticks--)
	{
		t=120;
		while(t--);
	}
}

void main()
{
	// low voltage enable.
	// P2 76543210 pins=>pin 0:5v,pin 1:12v,pin 2:18v,pin 3:27v
	P2=~0x11; // 5v start;

	DelayTimeByTick(Ticks);
	P2=~0x77; // then 12v,18v start;

	DelayTimeByTick(Ticks);
	P2=~0xff; // then 27v start;

	while(1);// main program;
}

当时首先使用的是 Keil uVision4里面却没有AT89S51这个东西,只得卸载重新安装Keil uVision3,但是问题很多,无法生成.obj文件,更不能生成.hex文件。网上提供的意见是1、缺少相应的库,2、软件破解不成功。在中国不想提软件破解的事情,最后在这里下载了 http://115.com/file/a6ngra1相应的破解软件,最终成功生成了.hex文件。

生成.hex的方法,从help里面搜到的。下面英文为摘抄的。

Build Project and Create a HEX File

Typical, the tool settings under Options – Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, µVision will display errors and warning messages in the Output Window – Build page. A double click on a message line opens the source file on the correct location in a µVision editor window.


Once you have successfully generated your application you can start debugging as described under Testing Programs with the µVision Debugger.

Now you may modify existing source code or add new source files to the project. The Build Target toolbar button translates only modified or new source files and generates the executable file. µVision maintains a file dependency list and knows all include files used within a source file. Even the tool options are saved in the file dependency list, so that µVision rebuilds files only when needed. With the Rebuild Target command, all source files are translated, regardless of modifications.

After you have tested your application, it might be required to create an Intel HEX file and to download the application software into the physical device using a Flash programming utility. µVision creates HEX files with each build process when Create HEX file under Options for Target – Output is enabled. The Merge32K Hexfile option is available for Code Banking Applications when you have selected the Extended Linker LX51. You may start your Flash programming utility after the make process when you specify the program under the option Run User Program #1.


至此程序方面的问题解决,下面是写入AT89S51的问题了。

由于完全不知道怎么下载数据到单片机,就在实验室里面随便找了一个JTAG跟USB接头的东西,连接无效,最后参考视频:http://v.youku.com/v_show/id_XMjIzNDMwOTA0.html 知道该使用什么线了。在另外一个实验室借到相应的线(见视频中提示),然后下载了ISPlay.exe 在这里http://ishare.iask.sina.com.cn/f/13827560.html。由于原来PCB板子的问题,ISPlay一直检测不到AT89S51,还在调试中,得到解决方案再说。在其他板子中发现这个是可以解决的。期待快点解决。

最后的解决方案是,从SJTU科创实验室借到一个报废的51单片机的开发板(可以往里面烧录程序的),把程序烧录进AT89S51,然后AT89S51换到自己的那个板子上面,可以实现控制了。后面就没有再去解决这个问题,认为可能的原因是没有reset按键。不想再去深究。

你可能感兴趣的:(解决问题,keil,ISPlay,AT89S51)