Anda di halaman 1dari 2

04-Jun-11

Xut nhp I/O


input_a() nhp t Port A input_b() nhp t Port B V d: data = input_b(); input(pin) nhp t mt chn port V d: while ( !input(PIN_B1) ); // waits for B1 to go high if( input(PIN_A0) ) printf("A0 is now high\r\n");

15

To xung vung
V d: To xung vung f=1 KHz ti chn RB0 (Cch 1) #include <16F84.h> #use delay(clock=20000000) Main() { while(1) { output_high(pin_B0); delay_us(500); // delay 250us output_low (pin_B0); delay_us (500 ); } } V d: To xung vung f=1 KHz ti chn RB0 (Cch 2) #include <16F84.h> #use delay(clock=20000000) Main() { int1 x; while(1) { output_bit(pin_B0,!x); delay_us(500); } }

16

04-Jun-11

Delay
dng hm delay, cn c khai bo #use delay (clock=20000000) u file (v d cho fosc=20 MHz) delay_cycles(x) delay x (hng s t 1 255) chu k lnh 1 chu k lnh = 4 chu k my delay_us(x) delay x s x l bin (int16) hoc hng t 0 65535 delay_ms(x) delay x ms x l bin (int16) hoc hng t 0 65535

13

Xut nhp I/O


s dng Port A v Port B, cn c khai bo #use fast_io(A) #use fast_io(B) u file Hoc #use fast_io(ALL) set_tris_a(value) xc lp Port A (0: output, 1: input) set_tris_b(value) xc lp Port B V d: SET_TRIS_B( 0x0F ); // B7,B6,B5,B4 are outputs // B3,B2,B1,B0 are inputs output_a(value) xut ra Port A output_b(value) xut ra Port B V d: OUTPUT_B(0xf0); output_high(pin) xut mc 1 ra mt chn port output_low(pin) xut mc 0 ra mt chn port V d: output_high(PIN_A0); output_low(PIN_A1); (Pin constants are defined in the devices .h file) output_bit(pin,value) xut value (0 hay 1) ra pin V d: output_bit( PIN_B0, 0); // Same as output_low(pin_B0); output_bit( PIN_B0,input( PIN_B1 ) ); // Make pin B0 the same as B1 output_float(pin) to cc thu h 14

Anda mungkin juga menyukai