VIDEO DEMO
Chương trình viết bằng C
#include<REGX51.H>
/************khai bao bien*************/
sfr dataP = 0x90;//du lieu la P1
sbit contact = P3^4;
unsigned char dem = 0;
//ma 7 thanh tu 0 den 9 la P1
//0xc0h;0xf9h,0xa4h,0xb0h,0x99h,0x92h,0x82h;0xf8h;0x80h;0x90h.
void delay(long time)
{
while (time--);
}
/******************Chuong trinh con kiem tra phim nhan************/
void phim_an(void)
{
if(contact==0)
{
delay(500); //chong rung phim
while(contact==0);//cho nha phim
delay(500);//chong rung phim
dem++; //tang bien dem
if(dem==10)dem=0;
}
}
/***************hien thi so lan nhan phim********/
void solan_an(void)
{
switch(dem)
{
case 0:{dataP=0xc0;break;}
case 1:{dataP=0xf9;break;}
case 2:{dataP=0xa4;break;}
case 3:{dataP=0xb0;break;}
case 4:{dataP=0x99;break;}
case 5:{dataP=0x92;break;}
case 6:{dataP=0x82;break;}
case 7:{dataP=0xf8;break;}
case 8:{dataP=0x80;break;}
case 9:{dataP=0x90;break;}
};
}
/***********chuong trinh chinh***********/
void main(void)
{
dataP=0xc0;
while(1)
{
phim_an();
solan_an();
}
}
Đăng nhận xét