Toi dang tim cach su dung che do CCP1 cua PIC877a tao ra song vuong, chuong trinh viet bang CCS C. Nhung chay mo phong bang Proteous thi lai thu duoc song co chu ki khong phai la 2 ms. Xin moi nguoi sua giup. Cam on!
Code:
#include <16F877.h>
#INCLUDE<def_877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int16 pulse;
#int_ccp1
void isr()
{
if (!bit_test(PORTB,0)){
output_high(PIN_b0);
}
else{
output_low(PIN_B0);}
CCP_1+=1000;
}
void main()
{
CHAR VALUE;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_ccp1(CCP_COMPARE_INT);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);
pulse = 1000;
TRISB = 0;
PORTB = 0;
CCP_1 = PULSE;
set_timer1(0);
while(true);
}