标题:
新人求问 串口密码锁 我写的单片机程序有问题
[打印本页]
作者:
身向榆关那畔行
时间:
2017-5-8 21:20
标题:
新人求问 串口密码锁 我写的单片机程序有问题
题目 串口密码锁
基本要求:串口发送正确密码,单片机会返回ok,并打开锁(用led亮灭代替),发送错误密码返回error
我照猫画虎的写了一串可是不知道哪里有问题
#include "reg52.h"
#include <string.h>
typedef unsigned int u16;
typedef unsigned char u8;
unsigned char mima[]="123456\r",a[10];
unsigned char tab2[]=" the password is corret";
unsigned char tab3[]=" the password is incorret ,please re-enter your password!";
void UsartInit()
{
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TH1=0XF3;
TL1=0XF3;
ES=1;
EA=1;
TR1=1;
}
void delay(u16 i)
{
while(i--);
}
void main()
{
UsartInit();
while(1);
}
void send_char(unsigned char c)
{ SBUF=c;
while(TI==0);
TI=0;
}
void Usart() interrupt 4
{
u16 i;
for(i=0;a[i]!='\r';i++)
{
if(RI==1)
{
a[i]=SBUF;
}
}
if(strcmp(a,mima)==0)
{
send_char(tab2);
}
else
send_char(tab3);
RI=0;
}
复制代码
作者:
HUANGHFS
时间:
2017-5-8 22:09
应该是参数传递错误。
作者:
HUANGHFS
时间:
2017-5-8 22:10
应该是参数传递错误。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1