Em chỉ thử test mấy cái hàm trong đó thôi, khi em đưa sang PIC Simulator để mô phỏng thì không thấy có tín hiệu gì ở Port C cả. Rất mong bác giúp đỡ, em cảm ơn bác nhiều. Đây là phần code của em cho phần I2C:
'**********************************************'
#include <16F877A.h>
#device adc=8
#use delay(clock=10000000)
#fuses NOWDT,RC, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=9)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#use fast_io(c)
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// set_tris_c(0x00);
while (1)
{
i2c_start();
i2c_write(0xa0); // Device address
i2c_write(0xf1); // subaddress
i2c_start(); // Restart
i2c_write(0xa1); // to change data direction
i2c_read(); // Now read from slave
i2c_stop();
}
}
|