![]() |
|
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 |
Nhập môn đệ tử
Tham gia ngày: Apr 2008
Bài gửi: 4
: |
chuong trinh ban lam minh co thu ma sao khi chi can nhan rb3 den rb7 deu xay ra ngat dong loat ma minh nho rb3 dau co ngat dau ma sao no cung thanh ngat luon la sao
va khi vao ngat no thuc hien tat ca cac ngat tu rb4 den rb7 khong chua cai nao roi thoat khoi ngat la sao vay?? mong ban giai thich dieu vo ly do. ct của Master: Code:
#include <16f877a.h> #include <def_877a.h> #use delay(clock = 20000000) #fuses HS, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOPROTECT #use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, force_hw) const unsigned int8 dulieu[]={1,2,4,8,16,32,64,128}; const unsigned int8 address_slave[]={0,0x10,0x20,0x30,0x40}; int8 a,i,kytu; void ghi(int8 address,int8 data) { i2c_start(); i2c_write(address); i2c_write(data); i2c_stop(); } #INT_RB void ngat_RB() { if((RBIF)&&(RBIE)) { if(RB4==0) { a=1; i=0; } else if(RB5==0) { a=2; i=0; } else if(RB6==0) { a=3; i=0; } else if(RB7==0) { a=4; i=0; } } RBIF=0; } void main() { enable_interrupts(GLOBAL); enable_interrupts(INT_RB); set_tris_d(0); portd=0; while(TRUE) { kytu=a; delay_ms(100); while(kytu==a) { if(a!=0) { delay_ms(50); ghi(address_slave[a],dulieu[i]); i++; if(i==8) { i=0; } } } } } Code:
#include <16f877a.h> #include <def_877a.h> #use delay(clock = 20000000) #fuses HS, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOPROTECT #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x10, force_hw) int8 dulieu; #INT_SSP void ngat_i2c() { int8 state; state = i2c_isr_state(); if(state < 0x80) { dulieu = i2c_read(); portd = dulieu; delay_ms(50); } } void main() { enable_interrupts(GLOBAL); enable_interrupts(INT_SSP); set_tris_d(0); while(TRUE) { portd = 0; } } Em muốn post sơ đồ mạch lên mà không biết chèn code như thế nào, mong Admin chỉ giùm em cách tải file từ máy...[/QUOTE] |
![]() |
![]() |
|
|