结合考虑到程序的升级及修改等要求,采用WINBOND的 W78B516,使的系统具有在线维护功能。
使用”超级终端“即可轻松调试.
/*使用微机的超级中断口控制,波特率为19200*/
//
#include <reg52.h> //52单片机定义文件
#include <stdio.h> //基本输入输出函数
#include <string.h> //字符串处理函数
#include <ctype.h> //字符处理函数
sbit ekp0 =P2^0; //模拟控制设备口,共6个
sbit ekp1 =P2^1;
sbit ekp2 =P2^2;
sbit ekp3 =P2^3;
sbit ekp4 =P2^4;
sbit ekp5 =P2^5;
/*--------------------------------------
void main(void)
---------------------------------------*/
void main(void)
{
unsigned char i,ch;
char chs[9]="\0"; //定义9个字符接收单元
SCON = 0x50; //串口方式1
T2CON = 0x30; //T2作波特率发生器,16位自动重装模式
RCAP2L= 0xec; //波特率为19200时初值
TL2 = 0xec; //
RCAP2H= 0xff; //
TH2 = 0xff; //
TI = 1; //
TR2 = 1; //开波特率发生器
printf("\n"); //换行
while (1)
{
printf("%s","\n\t On-line operating system V1.0\n"); //系统开机显示字符
printf("%s","\tBuild by Gavin Hu, all right reserved.\n");
while (1)
{
printf("%s","\nPlease input password:"); //提示输入口令
scanf("%s",chs); // 接收状态
if (strcmp(chs,"12345678")) //与系统密码比较
printf("%s","Password error\n"); //口令错提示,等待重新输入口令
else break; // 口令正确,进入操作控制状态
}
while (1)
{
printf("%s","\nOn-line operating system>"); //在线控制提示符
scanf("%s",chs); //接收字符串
for (i=0; i<4; i++) //将字符转换为大写
chs[i]=toupper(chs[i]);
if (!strcmp(chs,"EXIT")) break; //如为退出命令,退出在线控制
i=strlen(chs); //取字符串长度
ch=chs[2]; //取最后一个字符
chs[2]='\0'; //最后一个字符单元为00
if (i>3||strcmp(chs,"OP")||ch<'0'||ch>'5') //如字符串长度大于3或前二个不等于"OP"或最后一个数小于0或大于5//
{printf("%s","Bad command\n"); continue;} //提示命令错,重新开始接收字符
printf("%s%c ","Equipment No:",ch); //命令正确,显示设备号
switch (ch)
{
case '0': if (ekp0) {ekp0=0; printf("%s","on\n"); break;}//按最后一位数对端口操作并显示"on"或"off"
else {ekp0=1; printf("%s","off\n"); break;}
case '1': if (ekp1) {ekp1=0; printf("%s","on\n"); break;}
else {ekp1=1; printf("%s","off\n"); break;}
case '2': if (ekp2) {ekp2=0; printf("%s","on\n"); break;}
else {ekp2=1; printf("%s","off\n"); break;}
case '3': if (ekp3) {ekp3=0; printf("%s","on\n"); break;}
else {ekp3=1; printf("%s","off\n"); break;}
case '4': if (ekp4) {ekp4=0; printf("%s","on\n"); break;}
else {ekp4=1; printf("%s","off\n"); break;}
case '5': if (ekp5) {ekp5=0; printf("%s","on\n"); break;}
else {ekp5=1; printf("%s","off\n"); break;}
default: break;
}
}
}
}