|
Tài trợ cho PIC Vietnam |
Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
Ðiều Chỉnh | Xếp Bài |
11-06-2013, 02:16 AM | #1 |
Đệ tử 1 túi
Tham gia ngày: Apr 2013
Bài gửi: 17
: |
Lỗi ngắt chân RB0
Code của mình như sau:
Code:
#include <Coordinator.h> #include "def_18f4620.c" #include "slave_2_tx_rx.h" #use delay(clock = 4000000) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) #define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H) #bit CS = 0xF80.4 #bit RST = 0xF82.2 #bit INT_ = 0xF81.0 #bit WAKE = 0xF82.1 #bit CS_Direction = 0xF92.4 #bit RST_Direction = 0xF94.2 #bit INT_Direction = 0xF93.0 #bit WAKE_Direction = 0xF94.1 INT temp,command1; int new_rx; #INT_EXT void EXT_isr(void) { new_rx = true; } void main() { TRISD3=0; //////////////// CS_Direction = 0; // Set direction to be output RST_Direction = 0; // Set direction to be output INT_Direction = 1; // Set direction to be input WAKE_Direction = 0; // Set direction to be output Delay_ms(5); setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4); // Initialize SPI module pin_reset(); // Activate reset from pin software_reset(); // Activate software reset RF_reset(); // RF reset set_WAKE_from_pin(); // Set wake from pin set_long_address(ADDRESS_long_2); set_short_address(coord_address_short); // Set short address set_PAN_ID(PAN_ID); // Set PAN_ID init_ZIGBEE_nonbeacon(); // Initialize ZigBee module nonbeacon_PAN_coordinator_device(); set_TX_power(31); // Set max TX power set_frame_format_filter(1); // 1 all frames, 3 data frame only set_reception_mode(1); // 1 normal mode delay_ms(10); enable_int(); pin_wake(); // Wake from pin ext_int_edge(H_to_L); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); printf(" RESET - THIET BI THU \r\n"); while (new_rx) { new_rx = false; temp = read_ZIGBEE_short(INTSTAT); // Read and flush register INTSTAT read_RX_FIFO(); command1=DATA_RX[0]; printf("|Gia tri:%D \n",command1); delay_ms(200); } } |
|
|