![]() |
|
|
#6 |
|
Đệ tử 1 túi
Tham gia ngày: Jul 2011
Bài gửi: 25
: |
Code:
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)
#byte portb=0x06
#byte intcon=0x000B
#bit RB4=portb.4
#bit RB5=portb.5
#bit RBIF=intcon.0 //dinh nghia co ngat RB
#bit RBIE=intcon.3 //dinh nghia bit cho phep ngat RB
int8 a=0;
int8 bien;
const unsigned char ma_ledthuan[]= {
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x81,0x82,0x84,0x88,0x90,0xA0,0xC0,0xC1,
0xC2,0xC4,0xC8,0xD0,0xE0,0xE1,0xE2,0xE4,
0xE8,0xF0,0xF1,0xF2,0xF4,0xF8,0xF9,0xFA,
0xFC,0xFD,0xFE,0xFF,0x00};
const unsigned char ma_lednguoc[]= {
0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x81,0x41,0x21,0x11,0x09,0x05,0x03,0x83,
0x43,0x23,0x13,0x0b,0x07,0x87,0x47,0x27,
0x17,0x0f,0x8f,0x4f,0x2f,0x1f,0x9f,0x5f,
0x3f,0xbf,0x7f,0xFF,0x00};
// Chuong trinh ngat
#int_RB
void ngat_RB()
{
if((RBIF)&&(RBIE))
{
//Kiem tra sw1
{
if(RB4==1)
{
a++ ;
// thêm delay_ms(10) thì nó không chạy dc
}
//Kiem tra sw2
RBIF=0; //Xoa co ngat RB
}
}
}
// Chuong trinh chinh
void main()
{
set_tris_b(0b11110000);
portb=0b11110000;
enable_interrupts(global);
enable_interrupts(int_RB);
ext_int_edge(H_to_L);
while(true)
{
if(a%2==0)
{
for(bien=0;bien<=36;bien++)
{
if(a%2==1)
bien=37;
output_d(ma_ledthuan[bien]);
Delay_ms(200);
}
}
else
{
for(bien=0;bien<=36;bien++)
{
if(a%2==0)
bien=37;
output_d(ma_lednguoc[bien]) ;
delay_ms(200) ;
}
}
}
}
Nó báo sẽ không ngắt khi chay hàm delay_ms Các bác giúp em với |
|
|
|
| Ðiều Chỉnh | |
| Xếp Bài | |
|
|