View Single Post
Old 07-08-2009, 01:37 AM   #8
dung h
Đệ tử 4 túi
 
Tham gia ngày: May 2009
Bài gửi: 74
:
bạn có thể tham khảo chương trình này:
đếm từ 0000->9999 sử dụng ngắt timer1 tao 1s
code:
Code:
#include<16f877a.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
#use delay(clock =20000000)
#use fast_io(b)
#use fast_io(d)
#byte portb=0x06
#byte portd=0x08

int8 a,b,c,d,dem=0;
int16 count=0;
const char code[]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

#int_timer1
void ngat_timer1()
{
  dem++;
  if(dem>19)
  {
   count++;
   dem=0;
   if(count>9999)
   count=0;
  }
  set_timer1(15535);
}

void chuyendoi(int16 x)
{
  a=(int8)(count%10);
  b=(int8)((count/10)%10);
  c=(int8)((count/100)%10);
  d=(int8)(count/1000);
}
void tre()
{
 int8 i;
 for(i=0;i<255;i++)
 {
 }
}
void quetled()
{
  portb=code[a];
  portd=0x01;
  tre();
  portb=code[b];
  portd=0x02;
  tre();
  portb=code[c];
  portd=0x04;
  tre();
  portb=code[d];
  portd=0x08;
  tre();
}

void main()
{
  set_tris_b(0x00);
  set_tris_d(0x00);
  set_tris_c(0x00);
  setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
  set_timer1(15535);
  enable_interrupts(int_timer1);
  enable_interrupts(global);
  
  while(true)
  {
   chuyendoi(count);
   quetled();
   output_c(code[a]);
  }
}
try to best!
dung h vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn