bnj j un problème dans le projet d'un fin d’étude , je fait un exemple de capteur DS18B20(température ) mais il ne fonctionne pas voila le schéma et les deux code source (maitre/esclave) Qui peut me aider et je vous remercie
le code de maitre:
Code://das ist nicht gut bat Allah und mohammed ist her prophet**************/ //*****************maitre*************************** char dat[10]; char error; char esclave_1[1]={0}; /// unsigned long temp_moyen; unsigned int lumier_extern,lumier_interne; #define signaler PORTD.F2 #define esclave_1_ 160 #define tempera_1 1 #define temp_com PORTD.RD4 sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction // LCD module connections sbit LCD_RS at RB3_bit; sbit LCD_EN at RB2_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB3_bit; sbit LCD_EN_Direction at TRISB2_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char adresse=160,test=0; char *text="000"; char *text_="0000"; char *_text="0000"; void interrupt() { RS485Master_Receive(dat); } /**********les valeurs des consigne pour les actioneurs********************/ #define t_max 25 #define t_min 35 #define on 1 #define off 0 void condition_actieurs(){ if(temp_moyen>t_max && temp_moyen< 50) temp_com=on; else if(temp_moyen<t_min) temp_com=off; } void affiche_moyen(unsigned long grand,char line, char colon){ text[0] = (grand/100) + 48; text[1] = (grand/10)%10 + 48; text[2] = grand%10 + 48; Lcd_Out(line,colon,text); if(line==1 && colon==6){ Soft_UART_Write(','); Soft_UART_Write(84); //T Soft_UART_Write(58); //: } /**********************pour l'envoi de la valeur calculer**********************/ Soft_UART_Write(_text[0]); Soft_UART_Write(_text[1]); Soft_UART_Write(_text[2]); /**********fin***************/ } void calcule_moyen(){ /****pour_afficher _la_moyenne_de_la_temperature******/ temp_moyen=(unsigned long) (esclave_1[0]); temp_moyen=temp_moyen/1; Lcd_Out(1, 1, "Temp:"); Lcd_Chr(1,10,223); Lcd_Chr(1,11,'C'); affiche_moyen(temp_moyen,1,6); // pour afficher les autres granderus condition_actieurs(); // pour actioner les actioneurs } void main() { Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"Demarage Systeme"); Lcd_Cmd(_LCD_CLEAR); TRISD.F2=0; TRISC=0; TRISC.RC7=1; TRISD.RD7=0; TRISD.RD6=0; TRISD.RD5=0; TRISD.RD4=0; TRISD.F1=0; PORTD=0; UART1_Init(9600); // initialize UART1 module Delay_ms(100); RS485Master_Init(); RCIE_bit = 1; // enable interrupt on UART1 receive TXIE_bit = 0; // disable interrupt on UART1 transmit PEIE_bit = 1; // enable peripheral interrupts GIE_bit = 1; // Delay_ms(500); error = Soft_UART_Init(&PORTD, 2, 3, 9600, 0); // Initialize Soft UART at 14400 bps if (error > 0) { while(1) ; // Stop program } Delay_ms(500); for(;;){ if(test==0){ RS485Master_Send(dat,1,adresse); test=1; } if (dat[5]) { // if an error detected, signal it PORTD.F2=1; // by setting portd to 0xAA Delay_ms(1000); signaler=0; } if (dat[4]) { PORTD.F1=1; dat[4]=0; //******************esclave_1*******************// switch(dat[0]){ case tempera_1: esclave_1[0]=dat[1]; break; calcule_moyen();test=0; adresse=160 ; break; RS485Master_Send(dat,1,adresse); } } } }
le code de esclave:
Code:char dat[9]; sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction unsigned int temp, recup_tmr0,recup_tmr1; float CAL1,CAL2; unsigned long RH1,frequence1,RH2,frequence2; #define signaler PORTB.RB7 #define tempera_1 1 #define tempera_2 2 #define tempera_3 3 #define humidity 4 #define hum_s_1 5 #define hum_s_2 6 #define hum_s_3 7 #define temp_1 0 #define temp_2 1 #define temp_3 2 /********/ #define mux_e0 PORTD.RD0 #define mux_e1 PORTD.RD1 #define mux_e2 PORTD.RD2 #define hum_s1 0 #define hum_s2 1 #define hum_s3 2 // Interrupt routine void interrupt() { RS485Slave_Receive(dat); } /**********************sous programme pour lire les capterus de temperature*****************/ char lire_temp(char pin_capteurs){ char temp_whole; Ow_Reset(&PORTB, pin_capteurs); // Onewire reset signal Ow_Write(&PORTB, pin_capteurs, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTB, pin_capteurs, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTB, pin_capteurs); Ow_Write(&PORTB, pin_capteurs, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTB, pin_capteurs, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTB, pin_capteurs); temp = (Ow_Read(&PORTB, pin_capteurs) << 8) + temp ; temp_whole = temp >> 4 ; return temp_whole; } void main() { TRISC.RC6=0; TRISC.RC7=1; TRISC.RC0=1; TRISA.RA4=1; TRISD=0; PORTD=0; //TRISB=0; //PORTB=0; ADCON0=0; ADCON1=0x0F; UART1_Init(9600); // initialize UART1 module Delay_ms(100); RS485Slave_Init(160); dat[4] = 0; // ensure that message received flag is 0 dat[5] = 0; // ensure that message received flag is 0 dat[6] = 0; // ensure that error flag is 0 RCIE_bit = 1; // enable interrupt on UART1 receive TXIE_bit = 0; // disable interrupt on UART1 transmit PEIE_bit = 1; // enable peripheral interrupts GIE_bit = 1; for(;;){ if (dat[5]) { // if an error detected, signal it by signaler=1; Delay_ms(1000); signaler=0; } if (dat[4]) { // upon completed valid message receive dat[4] = 0; dat[0]=tempera_1; dat[1]=lire_temp(temp_1); RS485Slave_Send(dat,2); Delay_ms(50); } } }
-----