Ðề tài: CCS C for PIC16F877A
View Single Post
Old 19-08-2006, 04:51 PM   #14
boys3509_2006
Đệ tử 2 túi
 
Tham gia ngày: Feb 2006
Bài gửi: 32
:
CCS C for PIC16F877A

Em mượn tạm đoạn code của nhh anh mổ xẻ nó giùm em nhé

//************************************************** **
// Author : nhh
// Date : 02/04/06
// Hardware: PIC16F877A
//************************************************** **
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)
#byte portb=0x06
#define led pin_B0
int16 count;
int8 a;

//Chuong trinh ngat TMR0
#int_timer0
void interrupt_timer0()
{
set_timer0(6);
++count;
if(count==2000)
{
count=0;
a=a<<1; // dich trai a 1bit
}
if(a==256)
{
a=1;
count=0;
}
}

//Chuong trinh chinh
main()
{
set_tris_b(0);
enable_interrupts(global);
enable_interrupts(int_timer0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_timer0(6);
count=0;
a=1;
while(true)
{
portb=a;
}
}

Anh giải thích mấy cỗ có giùm em. Tại sao phải setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2); mà ko Div 3, 4,... hở anh ?
boys3509_2006 vẫn chưa có mặt trong diễn đàn