chuong trinh dem xung ngoai dung ngat hien thi tren 2 led 7 doan
//chuong trinh dem xung ngoai dung ngat hien thi tren 2 led 7 doan
//chan thuc hien ngat ngoai RB0/int
//portC noi voi cac doan a,b,c..h
//RD0,RD1 lam nhiem vu quet led
#include"16f877a.h"
#include"def_877a.h"
#use delay(clock=4000000)
int bien_dem,chuc,don_vi,chuc_7doan,don_vi_7doan;
//khai bao ngat ngoai
#int_ext
void ngat_ngoai()
{
bien_dem++;
if (bien_dem>=99) bien_dem=0;
}
//dinh nghia ma 7 doan
const int ma_7doan[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
//chuong trinh con hien thi
void hien_thi()
{
portc=chuc_7doan;
rd0=0;
delay_ms(50);
rd0=1;
portc=don_vi_7doan;
rd1=0;
delay_ms(50);
rd1=1;
}
//chuong trinh chinh
void main()
{
//dinh nghia cac dau vao ra
trisc=0;
trisd0=0;
trisd1=0;
trisb0=1;
bien_dem=0;
//khai bao cho phep ngat
enable_interrupts(int_ext);
enable_interrupts(global);
ext_int_edge(h_to_l);
while (true)
{
chuc=bien_dem/10;
don_vi=bien_dem%10;
chuc_7doan=ma_7doan[chuc];
don_vi_7doan=ma_7doan[don_vi];
hien_thi();
}
}
Bạn đang đọc truyện trên: AzTruyen.Top