kakaculo123
07-01-2011, 06:28 PM
huhu.mấy a xem lại dùng e đoạn code này dùm nha.e điều khiển portc có ngắt TRR0.điều khiển led chạy từ phải sang trái từ chậm dần sang nhanh dần.dịch thì đúng nhưng chỉ sang có 1 led ah help!!!!!!
chương trinh e viết bằng ngôn ngữ c
#include <16F877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=4000000)
#byte portc=0x07 ///khai bao dia chi portb
int16 count;
int8 a;
int j;
//Chuong trinh ngat TMR0
#int_timer0
void interrupt_timer0()
{
set_timer0(0);
++count;
if(count==560)
{
count=0;
if(a==1)
{
while(1)
{
for(j=0;j<8;j++)
{
portc=1<<j; // dich trai a 1bit
delay_ms((j+1)*50);
}
}
}
}
}
//Chuong trinh chinh
main()
{
set_tris_c(0);
set_tris_b(0);
enable_interrupts(global);
enable_interrupts(int_timer0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_timer0(0);
count=0;
a=1;
while(true)
{
portc=a;
}
}
chương trinh e viết bằng ngôn ngữ c
#include <16F877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=4000000)
#byte portc=0x07 ///khai bao dia chi portb
int16 count;
int8 a;
int j;
//Chuong trinh ngat TMR0
#int_timer0
void interrupt_timer0()
{
set_timer0(0);
++count;
if(count==560)
{
count=0;
if(a==1)
{
while(1)
{
for(j=0;j<8;j++)
{
portc=1<<j; // dich trai a 1bit
delay_ms((j+1)*50);
}
}
}
}
}
//Chuong trinh chinh
main()
{
set_tris_c(0);
set_tris_b(0);
enable_interrupts(global);
enable_interrupts(int_timer0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_timer0(0);
count=0;
a=1;
while(true)
{
portc=a;
}
}