Anh hopeman cho bọn em 1 ví dụ xuất nhập tín hiệu các cổng I/O với nhé. Em lập trình cho các cổng output ra thì đúng theo lập trình rồi nhưng thử với input thì không được. Mắc quá anh ạ! A giúp em một bài toán như này nhé.
" Khi tín hiệu ở chân RD2 = 0 thì tín hiệu ở chân RB5 sẽ có dạng xung(Led nhấp nháy, khoảng delay tự chọn)và RB6 = 1.
Còn nếu RD2=1 thì RB5 = 1 và RB6 sẽ có tín hiệu dạng xung.
Em có lập trình như thế này. Anh xem giúp em với nhé. :
#include "C:\Documents and Settings\Administrator\Desktop\vd10\vd10.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SLAVE|SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_8MHZ);
SET_TRIS_B(0x00);
SET_TRIS_D(0xFF);
// TODO: USER CODE!!
while( input(PIN_D2) )
{
delay_ms(250);
output_low(pin_B5);
output_high(pin_B6);
}
while( !input(PIN_D2) )
{
delay_ms(250);
output_low(pin_B6);
output_high(pin_B5);
}
}
|