پاسخ : ماژول مخابراتی صنعتی و مطمئن
سلام کدش را تکمیل که کردم میفرستم :read:
نوشته اصلی توسط 1hamid
unsigned a1,sdata,d1,ad,ha,e1; unsigned uart_rd,b=0,i,error; char txt2[7]; char txt1[7]; char txt3[7]; char txt4[7]; char txt5[7]; char txt6[7]; int rec[14]; int chek[3]; const int f1=1; void main() { OPTION_REG =0b10000111; CMCON=0B00000111; ADCON0.ADON=0 ; ADCON1=0B00000111; TXSTA.TX9=0; TXSTA.TXEN=1; TXSTA.SYNC=0; TXSTA.BRGH=0; RCSTA.SPEN=1; RCSTA.RX9=0; RCSTA.CREN=1; ADDEN_BIT=0; UART1_Init(9600); SSPCON.SSPEN=0; // Initialize UART module at 9600 bps TRISC=0b11000000; TRISA=0x00; TRISB=0x00; PORTA=0; PORTB=0; PORTC.RC2=1 ; delay_ms(1000); PORTC.RC2=0; delay_ms(100); while(1){ delay_ms(10); //sleep mode PORTC.RC5=1; PORTC.RC3=1; delay_ms(200); uart1_write(0xff); delay_ms(f1); uart1_write(0x56); delay_ms(f1); uart1_write(0xAE); delay_ms(f1); uart1_write(0x35); delay_ms(f1); uart1_write(0xA9); delay_ms(f1); uart1_write(0x55); delay_ms(f1); uart1_write(0x90); delay_ms(f1); //freq 433.92 uart1_write(0x06); delay_ms(f1); uart1_write(0x9F); delay_ms(f1); uart1_write(0x00); delay_ms(f1); // drfsk 10 kbps uart1_write(0x03); delay_ms(f1); // pout uart1_write(0x01); delay_ms(f1); // baud rate 9600 uart1_write(0x03); delay_ms(f1); //parity uart1_write(0x00); delay_ms(f1); //tw 0.5 s uart1_write(0x05); delay_ms(f1); //id //if (PORTC.RC3==0){ uart1_write(0x00); delay_ms(f1); uart1_write(0x00); delay_ms(1); uart1_write(0x01); // } PORTC.RC5=0; PORTC.RC3=1; while(1){ if (UART1_Data_Ready() == 1) { PORTC.RC2=1; uart_rd= UART1_Read(); a1=uart_rd; rec[b]=a1; if (b==13){b=0; break;} //for s2 module b==17 b++; } } delay_ms(1000); PORTC.RC5=0; PORTC.RC3=0; PORTC.RC2=0; a1=0; while(1){ if (UART1_Data_Ready() == 1) { PORTC.RC2=1; uart_rd= UART1_Read(); a1=uart_rd; d1=0; } ad=a1 <<4 ; ha=a1 >>2; error=ha <<4; if(a1>0x2f){a1=0;} if (ad==0x30){a1=0;} if (error==0x30){a1=0;} PORTA=a1; e1=a1 >> 4; PORTB=e1; d1++; if (d1==4000){d1=0; a1=0;PORTC.RC2=0;PORTA=0;PORTB=0;} } } }
unsigned a1,d1,e1,adress=250; int uart_rd,b=0,sum=0,i,error=0,sdata; char txt2[7]; char txt1[7]; char txt3[7]; char txt4[7]; char txt5[7]; char txt6[7]; int rec[14]; const int f1=1; void main() { OPTION_REG =0b10000111; CMCON=0B00000111; ADCON0.ADON=0 ; ADCON1=0B00000111; TXSTA.TX9=0; TXSTA.TXEN=1; TXSTA.SYNC=0; TXSTA.BRGH=0; RCSTA.SPEN=1; RCSTA.RX9=0; RCSTA.CREN=1; ADDEN_BIT=0; UART1_Init(9600); SSPCON.SSPEN=0; // Initialize UART module at 9600 bps TRISC=0b11000000; TRISA=0B00111111; while(1){ delay_ms(10); PORTC.RC5=0; PORTC.RC3=0; delay_ms(10); PORTC.RC5=0; PORTC.RC3=1; delay_ms(10); //sleep mode PORTC.RC5=1; PORTC.RC3=1; delay_ms(20); //if(error==1){ uart1_write(0xff); delay_ms(f1); uart1_write(0x56); delay_ms(f1); uart1_write(0xAE); delay_ms(f1); uart1_write(0x35); delay_ms(f1); uart1_write(0xA9); delay_ms(f1); uart1_write(0x55); delay_ms(f1); uart1_write(0x90); delay_ms(f1); //freq 433.92 uart1_write(0x06); delay_ms(f1); uart1_write(0x9F); delay_ms(f1); uart1_write(0x00); delay_ms(f1); // drfsk 10 kbps uart1_write(0x03); delay_ms(f1); // pout uart1_write(0x01); delay_ms(f1); // baud rate 9600 uart1_write(0x03); delay_ms(f1); //parity uart1_write(0x00); delay_ms(f1); //tw 0.5 s uart1_write(0x05); delay_ms(f1); //id uart1_write(0x00); delay_ms(f1); uart1_write(0x00); delay_ms(1); uart1_write(0x01); // } PORTC.RC5=0; PORTC.RC3=1; while(1){ if (UART1_Data_Ready() == 1) { PORTC.RC2=1; uart_rd= UART1_Read(); a1=uart_rd; rec[b]=a1; if (b==13){b=0; break;} //for s2 module b==17 b++; } } PORTC.RC5=0; PORTC.RC3=0; while(1){ sdata=PORTA; if((PORTA.RA0==1)&&(PORTA.RA1==1)) {sdata=0;} if((PORTA.RA2==1)&&(PORTA.RA3==1)) {sdata=0;} if((PORTA.RA4==1)&&(PORTA.RA5==1)) {sdata=0;} uart1_write(sdata); if (sdata>0){PORTC.RC2=1;} delay_ms(50); PORTC.RC2=0; } } }
دیدگاه