0% found this document useful (0 votes)
8 views

New Text Document

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

New Text Document

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <BCGK(quetled).

h>
#DEFINE UP PIN_a1
#DEFINE DW PIN_a2
#DEFINE RESET PIN_a0
#DEFINE countDW PIN_a3
#DEFINE rled PIN_b4
#DEFINE bled PIN_b5
int led7[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int max,mdv,mch,ch,dv,t;
int16 sp;

void co_DW()
{
if(input(countDW)==0)
{
while(!input(countDW));
if (sp>0) set_timer3(sp-1);
sp=get_timer3();
}
}
void set_max()
{
if(input(UP)==0)
{
while(!input(UP));
if(max<99) max++;
}
if(input(DW)==0)
{
While(input(DW)==0);
if(max>0&&max>sp) max--;
}
}

void kt_reset()
{
if(input(reset)==0)
{
while(input(reset)==0);
set_timer3(0);
sp=get_timer3();
}
}

void main()
{
set_tris_c(0xff);
set_tris_c(0xff);
set_tris_d(0x00);
set_tris_b(0x00);

// Gia tri khoi tao


max=99;
//Cai dat timer3
setup_timer_3(T3_EXTERNAL|T3_DIV_BY_1);
set_timer3(0);
sp=get_timer3();
while(TRUE)
{
// Phep tinh cac thong so
dv=sp%10;
ch=sp/10;
mdv=max%10;
mch=max/10;

//LED thong bao trang thai


if (sp==max)
{
output_high(rled);
output_low(bled);
}
else
{
output_high(bled);
output_low(rled);
}

//Dieu kien san pham


if (sp<max&&sp>=0) sp= get_timer3();
//Dieu kien de dem xung clock khi tang max thi se dat lai gia tri max_cu
if (sp==max) set_timer3(max);

//Nut UP, DOWN, RESET


set_max();
kt_reset();
co_DW();

//Hien thi led 7 doan theo quet led


for(t=0; t<10;t++)
{
output_d(led7[mch]);
output_bit(pin_b0,0);
delay_us(500);
output_bit(pin_b0,1);

output_d(led7[mdv]);
output_bit(pin_b1,0);
delay_us(500);
output_bit(pin_b1,1);

output_d(led7[ch]);
output_bit(pin_b2,0);
delay_us(500);
output_bit(pin_b2,1);

output_d(led7[dv]);
output_bit(pin_b3,0);
delay_us(500);
output_bit(pin_b3,1);
}
}
}

You might also like