cac dai ka xem ho em cai code nay fat.
em viet thi no bao ko loi.
nhung khi ep vao ic thi lai ko chay
em viet thi no bao ko loi.
nhung khi ep vao ic thi lai ko chay
- Code:
#include <REGX51.H>
sbit SR = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
sbit IN1 = P1^0;
sbit IN2 = P1^1;
sbit IN3 = P1^2;
sbit OUT1 = P1^3;
sbit OUT2 = P1^4;
sbit OUT3 = P1^5;
sbit OUT4 = P1^6;
//============= HAM DELAY========//
void delay(unsigned char ms)
{
unsigned char i;
for(i=0;i<ms;i++);
}
//======= ham kiem tra ban ======//
void kt_ban()
{
unsigned char x;
P3=0xff;
SR=0;
RW=1;
do
{
EN=1;
delay(50);
EN=0;
x=P3;
x=x&0x80;
}
while(x!=0x80);
}
//======= ham ghi lenh=====//
void ghi_lenh(unsigned char lenh)
{
delay(50);
P3=lenh;
SR=0;
RW=0;
EN=1;
delay(1);
EN=0;
}
//======= ham ghi du lieu =====//
void ghi_dulieu(unsigned char dulieu)
{
delay(50);
P3=dulieu;
SR=1;
RW=0;
EN=1;
delay(1);
EN=0;
}
//======= ham ghi chuoi =====//
void ghi_chuoi(unsigned char *chuoi)
{
while(*chuoi)
{
delay(50);
ghi_dulieu(*chuoi);
chuoi++;
}
}
//========== khoi dong lcd start==========//
void start()
{
ghi_lenh(0x38);
ghi_lenh(0x01); // Xoa man hinh
ghi_lenh(0x0f); // Co dich hien thi
}
//========== ghi so ================//
void ghi_so(unsigned char so)
{
unsigned char a,b,c;
a=so/100;
ghi_dulieu(a+48);
b=(so-100*a)/10;
ghi_dulieu(b+48);
c=(so-100*a-100*b);
ghi_dulieu(c+48);
}
//======= ham quet ban phim=========//
unsigned char quet_bp()
{
if(OUT1==0)
{
if(IN1==0)
{
return 1;
delay(3000);
delay(3000);
}
if(IN2==0)
{
return 2;
delay(3000);
delay(3000);
}
if(IN3==0)
{
return 3;
delay(3000);
delay(3000);
}
}
if(OUT2==0)
{
if(IN1==0)
{
return 4;
delay(3000);
delay(3000);
}
if(IN2==0)
{
return 5;
delay(3000);
delay(3000);
}
if(IN3==0)
{
return 6;
delay(3000);
delay(3000);
}
}
if(OUT3==0)
{
if(IN1==0)
{
return 7;
delay(3000);
delay(3000);
}
if(IN2==0)
{
return 8;
delay(3000);
delay(3000);
}
if(IN3==0)
{
return 9;
delay(3000);
delay(3000);
}
}
if(OUT4==0)
{
if(IN1==0)
{
return 10;
delay(3000);
delay(3000);
}
if(IN2==0)
{
return 11;
delay(3000);
delay(3000);
}
if(IN3==0)
{
return 12;
delay(3000);
delay(3000);
}
}
}
//============== Chuong trinh chinh main==========//
unsigned char a,pass,s;
void main()
{
pass=123;
delay(100);
start();
s=0;
while(1)
{
ghi_chuoi(" dtvtk8d ");
do
{
a=quet_bp();
}
while(a!=12);
ghi_lenh(0x01);
ghi_chuoi(" nhap pass word ");
do
{
a=quet_bp();
delay(80000);
if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9)
{
ghi_chuoi("*");
s=s*10+a;
}
}
while(a!=10);
if(s==pass)
{
ghi_chuoi(" mat khau dung ");
}
else
{
ghi_chuoi(" mat khau sai ");
} ;
delay(100000);
delay(100000);
delay(100000);
}
}