Mọi người có thể giúp mình chỉnh sửa đoạn code này không????mình không rành lắm nên mong mọi ngừoi có thể chỉ dẩn chi tiết....thank mọi người...
#include "D:\Documents and Settings\Administrator\My Documents\Downloads\Compressed\Den giao thong 2 cot den \Den giao thong\demo.h"
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
include <16f877a.h>
include <KhaiBaoTGhi_16F877A.h>
fuses nowdt, put, hs, noprotect, nolvp
use delay (clock=20000000)
use fast_io(b)
use fast_io(d)
int8 J,k,chuc1,chuc2,dvi1,dvi2;
int16 t_do,a,t_xanh,b;
const unsigned char
dig[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9
0};
INT_TIMER1
VOID NGAT() // bat dau chuong trinh ngat
{ J++;
IF(J==10) // khi j=10 thi thoi gian dung 1s
{ k=k+1; // bien k dung de xac dinh thoi gian cho cot 1
if((k<26)&&(k>0))
{ a=t_do;
t_do=t_do-1;
b=t_xanh;
t_xanh=t_xanh-1;
if(a<5) // thoi gian hien thi cho led vang
{ portc=0x22; // Den v2 va d1 sang
b=a;
}
else
portc=0x21; // den x2 va den d1 sang
}
if((k<26)&&(k>24)) // khi du 25s thi chuyen sang
cot 2
{ t_do=24;
t_xanh=19;
}
if(k>25) // bat dau hien thi cho cot 2
{ b=t_do;
t_do=t_do-1;
a=t_xanh;
t_xanh=t_xanh-1;
if (b<5) // khi den xanh du 20s thi den vang
bat dau sang
{ portc=0x14; // den do 2 va den vang 1 sang
a=b;
}
else
portc=0x0c; // den do 2 va den xanh 1 sang
}
chuc1=a/10;
dvi1=a%10;
chuc2=b/10;
dvi2=b%10;
if(k>49) // khi cot 2 xong 25s thi chuyen ve cot 1
{ k=0; // khoi tao lai gia tri dem ban dau
t_do=24;
t_xanh=19;
}
SET_TIMER1(3035); // cai lai thoi gian cho timer1
J=0;
}
SET_TIMER1(3035); // cai lai thoi gian cho timer1
}
void main() // bat dau chuong trinh chinh
{ set_tris_b(0x00); // khoi tao cho port b,c,d la ngo ra
set_tris_d(0x00);
set_tris_c(0x00);
j=0; // khoi tao cho bien dem timer1
k=0; // khoi tao cho bien dem cua tung cot
t_do=24; // gan gia tri ban dau cho den do va xan
t_xanh=19;
SET_TIMER1(3035); //dat so dem cho timer1
T1CON=0x35; //khoi tao gia tri cho timer
enable_interrupts(INT_TIMER1); //tran thi ngat
enable_interrupts(global); //cho phep ngat timer
WHILE(TRUE)
{ portb=dig[chuc1]; //dua gia tri chuc1 ra portb
portd=0xf8; //chi led o vi tri chuc1 la sang
delay_ms(8); //dung de nhin thay duoc led sa
portd=0xf0; //chong lem
portb=dig[dvi1]; //dua gia tri dvi1 ra portb
portd=0xf4; //chi led o vi tri dvi1 la sang
delay_ms(8);
portd=0xf0;
portb=dig[chuc2]; //dua gia tri chuc2 ra portb
portd=0xf2; //chi led o vi tri chuc2 la sang
delay_ms(8);
portd=0xf0;
portb=dig[dvi2]; //dua gia tri dvi2 ra portb
portd=0xf1; //chi led o vi tri dvi2 la sang
delay_ms(8);
portd=0xf0;
}
}
}
#include "D:\Documents and Settings\Administrator\My Documents\Downloads\Compressed\Den giao thong 2 cot den \Den giao thong\demo.h"
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
include <16f877a.h>
include <KhaiBaoTGhi_16F877A.h>
fuses nowdt, put, hs, noprotect, nolvp
use delay (clock=20000000)
use fast_io(b)
use fast_io(d)
int8 J,k,chuc1,chuc2,dvi1,dvi2;
int16 t_do,a,t_xanh,b;
const unsigned char
dig[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9
0};
INT_TIMER1
VOID NGAT() // bat dau chuong trinh ngat
{ J++;
IF(J==10) // khi j=10 thi thoi gian dung 1s
{ k=k+1; // bien k dung de xac dinh thoi gian cho cot 1
if((k<26)&&(k>0))
{ a=t_do;
t_do=t_do-1;
b=t_xanh;
t_xanh=t_xanh-1;
if(a<5) // thoi gian hien thi cho led vang
{ portc=0x22; // Den v2 va d1 sang
b=a;
}
else
portc=0x21; // den x2 va den d1 sang
}
if((k<26)&&(k>24)) // khi du 25s thi chuyen sang
cot 2
{ t_do=24;
t_xanh=19;
}
if(k>25) // bat dau hien thi cho cot 2
{ b=t_do;
t_do=t_do-1;
a=t_xanh;
t_xanh=t_xanh-1;
if (b<5) // khi den xanh du 20s thi den vang
bat dau sang
{ portc=0x14; // den do 2 va den vang 1 sang
a=b;
}
else
portc=0x0c; // den do 2 va den xanh 1 sang
}
chuc1=a/10;
dvi1=a%10;
chuc2=b/10;
dvi2=b%10;
if(k>49) // khi cot 2 xong 25s thi chuyen ve cot 1
{ k=0; // khoi tao lai gia tri dem ban dau
t_do=24;
t_xanh=19;
}
SET_TIMER1(3035); // cai lai thoi gian cho timer1
J=0;
}
SET_TIMER1(3035); // cai lai thoi gian cho timer1
}
void main() // bat dau chuong trinh chinh
{ set_tris_b(0x00); // khoi tao cho port b,c,d la ngo ra
set_tris_d(0x00);
set_tris_c(0x00);
j=0; // khoi tao cho bien dem timer1
k=0; // khoi tao cho bien dem cua tung cot
t_do=24; // gan gia tri ban dau cho den do va xan
t_xanh=19;
SET_TIMER1(3035); //dat so dem cho timer1
T1CON=0x35; //khoi tao gia tri cho timer
enable_interrupts(INT_TIMER1); //tran thi ngat
enable_interrupts(global); //cho phep ngat timer
WHILE(TRUE)
{ portb=dig[chuc1]; //dua gia tri chuc1 ra portb
portd=0xf8; //chi led o vi tri chuc1 la sang
delay_ms(8); //dung de nhin thay duoc led sa
portd=0xf0; //chong lem
portb=dig[dvi1]; //dua gia tri dvi1 ra portb
portd=0xf4; //chi led o vi tri dvi1 la sang
delay_ms(8);
portd=0xf0;
portb=dig[chuc2]; //dua gia tri chuc2 ra portb
portd=0xf2; //chi led o vi tri chuc2 la sang
delay_ms(8);
portd=0xf0;
portb=dig[dvi2]; //dua gia tri dvi2 ra portb
portd=0xf1; //chi led o vi tri dvi2 la sang
delay_ms(8);
portd=0xf0;
}
}
}
Comment