#include <16f877a.h>
#FUSES NOWDT,PUT,HS,NOPROTECT,NOLVP
#USE DELAY(clock=20M)
const unsigned char Code7Seg[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
int i,k;
void hienthi(int k); // khai bao ham
// chuong trinh chinh
void main()
{
set_tris_B(0x00); // mat dinh tat led
while(TRUE)
{
for(k=0;k<100;k++) // vong lap 0 den 99
{
hienthi(k);
}
}
}
// ham hien thi
void hienthi(int i)
{
for(int n=0;n<25;n++) // tong delay (20+20) * 25 =1000ms =1s
{
OUTPUT_HIGH(PIN_D0); //cap nguon hang chuc
OUTPUT_B(Code7Seg[i/10]);
delay_ms(20);
OUTPUT_LOW(PIN_D0); // tat nguon hang chuc
OUTPUT_HIGH(PIN_D1); // cap nguon hang don vi
OUTPUT_B(Code7Seg[i%10]);
delay_ms(20);
OUTPUT_LOW(PIN_D1); // tat nguon hang don vi
}
}
Mô Phỏng Proteus 8.6 : https://mega.nz/#!bNF2xSRD!URBqvJPgGlohqpAjI4UJ5twJJS3kmgs4ZcsnxegU17o
Chúc các bạn thành công
0 nhận xét:
Đăng nhận xét