- Ảnh mô phỏng protues.
- Đây là code chương trình.
#include <16f877a.h>
#use delay (clock=4000000)
#use fast_io(d)
#use fast_io(b)
#use fast_io(c)
#use fast_io(a)
#byte portd=0x08
#bit ra0=0x05.0 // Binh thuong
#bit ra1=0x05.1 // Gio cao diem
#bit ra2=0x05.2 // Ban dem
#bit ra3=0x05.3 // Nut chuyen che do
#bit rb0=0x06.0 // led1
#bit rb1=0x06.1 // led2
#bit rb2=0x06.2 // led3
#bit rb3=0x06.3 // led4
#bit rc0=0x07.0 // x1
#bit rc1=0x07.1 // v1
#bit rc2=0x07.2 // d1
#bit rc3=0x07.3 // x2
#bit rc4=0x07.4 // v2
#bit rc5=0x07.5 // d2
#define bat 1
#define tat 0
//--------------------------------
int m[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int num1,donvi1,chuc1;
int num2,donvi2,chuc2;
//---------------------delay-------------
void delay(int ms)
{
int a,b;
for(a=0;a<ms;a++)
for(b=0;b<50;b++)
{
}
}
//-------------hien thi---------------------
void ht1(void)
{
int c;
for(c=0;c<50;c++)
{
chuc1=num1/10;
donvi1=num1%10;
output_d(m[chuc1]);
rb2=bat;
delay(10);
rb2=tat;
output_d(m[donvi1]);
rb3=bat;
delay(10);
rb3=tat;
chuc2=num2/10;
donvi2=num2%10;
output_d(m[chuc2]);
rb0=bat;
delay(10);
rb0=tat;
output_d(m[donvi2]);
rb1=bat;
delay(10);
rb1=tat;
}
}
void main(void)
{
set_tris_d(0x00);
set_tris_b(0xff);
set_tris_c(0x00);
set_tris_a(0xff);
output_d(0xFF);
rc0=tat;
rc5=tat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
while(true)
{
///--------------che do binh thuong -----------------
if(!ra0)
{
delay_ms(100);
while(!ra0)
{
binhthuong:
num1=35;
num2=30;
do
{
set_tris_b(0x00);
rc0=bat;
rc5=bat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num2=num1=5;
do
{
set_tris_b(0x00);
rc1=bat;
rc5=bat;
rc0=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num1=30;
num2=35;
do
{
set_tris_b(0x00);
rc2=bat;
rc3=bat;
rc0=tat;
rc1=tat;
rc4=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
num1=num2=5;
do
{
set_tris_b(0x00);
rc2=bat;
rc4=bat;
rc0=tat;
rc1=tat;
rc3=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
goto binhthuong;
}
}
//---------------gio cao diem--------------------------
if(!ra1)
{
delay_ms(100);
while(!ra1)
{
caodiem:
num1=60;
num2=55;
do
{
set_tris_b(0x00);
rc0=bat;
rc5=bat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num2=num1=5;
do
{
set_tris_b(0x00);
rc1=bat;
rc5=bat;
rc0=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num1=55;
num2=60;
do
{
set_tris_b(0x00);
rc2=bat;
rc3=bat;
rc0=tat;
rc1=tat;
rc4=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
num1=num2=5;
do
{
set_tris_b(0x00);
rc2=bat;
rc4=bat;
rc0=tat;
rc1=tat;
rc3=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
goto caodiem;
}
}
//-------------------ban dem---------------
if(!ra2)
{
delay_ms(100);
while(!ra2)
{
dem:
rc4=bat;
rc1=bat;
delay_ms(1000);
rc4=tat;
rc1=tat;
goto dem;
}
}
//---------------------- ket thuc chuong trinh ----------------------
}
}
Download 1 trong 2 link bên dưới !
- Link download project không có quảng cáo Click here
- Link download project Click here
- Đây là code chương trình.
#include <16f877a.h>
#use delay (clock=4000000)
#use fast_io(d)
#use fast_io(b)
#use fast_io(c)
#use fast_io(a)
#byte portd=0x08
#bit ra0=0x05.0 // Binh thuong
#bit ra1=0x05.1 // Gio cao diem
#bit ra2=0x05.2 // Ban dem
#bit ra3=0x05.3 // Nut chuyen che do
#bit rb0=0x06.0 // led1
#bit rb1=0x06.1 // led2
#bit rb2=0x06.2 // led3
#bit rb3=0x06.3 // led4
#bit rc0=0x07.0 // x1
#bit rc1=0x07.1 // v1
#bit rc2=0x07.2 // d1
#bit rc3=0x07.3 // x2
#bit rc4=0x07.4 // v2
#bit rc5=0x07.5 // d2
#define bat 1
#define tat 0
//--------------------------------
int m[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int num1,donvi1,chuc1;
int num2,donvi2,chuc2;
//---------------------delay-------------
void delay(int ms)
{
int a,b;
for(a=0;a<ms;a++)
for(b=0;b<50;b++)
{
}
}
//-------------hien thi---------------------
void ht1(void)
{
int c;
for(c=0;c<50;c++)
{
chuc1=num1/10;
donvi1=num1%10;
output_d(m[chuc1]);
rb2=bat;
delay(10);
rb2=tat;
output_d(m[donvi1]);
rb3=bat;
delay(10);
rb3=tat;
chuc2=num2/10;
donvi2=num2%10;
output_d(m[chuc2]);
rb0=bat;
delay(10);
rb0=tat;
output_d(m[donvi2]);
rb1=bat;
delay(10);
rb1=tat;
}
}
void main(void)
{
set_tris_d(0x00);
set_tris_b(0xff);
set_tris_c(0x00);
set_tris_a(0xff);
output_d(0xFF);
rc0=tat;
rc5=tat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
while(true)
{
///--------------che do binh thuong -----------------
if(!ra0)
{
delay_ms(100);
while(!ra0)
{
binhthuong:
num1=35;
num2=30;
do
{
set_tris_b(0x00);
rc0=bat;
rc5=bat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num2=num1=5;
do
{
set_tris_b(0x00);
rc1=bat;
rc5=bat;
rc0=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num1=30;
num2=35;
do
{
set_tris_b(0x00);
rc2=bat;
rc3=bat;
rc0=tat;
rc1=tat;
rc4=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
num1=num2=5;
do
{
set_tris_b(0x00);
rc2=bat;
rc4=bat;
rc0=tat;
rc1=tat;
rc3=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
goto binhthuong;
}
}
//---------------gio cao diem--------------------------
if(!ra1)
{
delay_ms(100);
while(!ra1)
{
caodiem:
num1=60;
num2=55;
do
{
set_tris_b(0x00);
rc0=bat;
rc5=bat;
rc1=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num2=num1=5;
do
{
set_tris_b(0x00);
rc1=bat;
rc5=bat;
rc0=tat;
rc2=tat;
rc3=tat;
rc4=tat;
ht1();
num1--;
num2--;
}
while(num2!=0);
num1=55;
num2=60;
do
{
set_tris_b(0x00);
rc2=bat;
rc3=bat;
rc0=tat;
rc1=tat;
rc4=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
num1=num2=5;
do
{
set_tris_b(0x00);
rc2=bat;
rc4=bat;
rc0=tat;
rc1=tat;
rc3=tat;
rc5=tat;
ht1();
num1--;
num2--;
}
while(num1!=0);
goto caodiem;
}
}
//-------------------ban dem---------------
if(!ra2)
{
delay_ms(100);
while(!ra2)
{
dem:
rc4=bat;
rc1=bat;
delay_ms(1000);
rc4=tat;
rc1=tat;
goto dem;
}
}
//---------------------- ket thuc chuong trinh ----------------------
}
}
Download 1 trong 2 link bên dưới !
- Link download project không có quảng cáo Click here
- Link download project Click here
EmoticonEmoticon