مساء الخير اخي عبدلله وعليكم السلام ورحمه الله وبركاته
شكرا لك على المساعده..
الملفات المرفقه لاتعمل لدي لا اعرف لماذا .
انا استخدم بروتس 8.6
الميكروسي 7 برو
هل لهذا علاقه
شكرا لك
|
السلام عليكم
تفضل أخي
كود تعريف الحساس DH22 وتفعيل التايمر الداخلي تايمر ( 0)
كود:
// ENG / ABDALLA HEGAZY **
// DATA / 2019/1/20 **
// RH _temp. controller **
// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;
unsigned char Check, T_byte1, T_byte2, RH_byte1, RH_byte2, Ch ;
unsigned RH1, Temp1,Temp, RH, Sum;
//////////////////////////////
void StartSignal(){
TRISC.F7 = 0; //Configure RD0 as output
PORTC.F7 = 0; //RD0 sends 0 to the sensor
delay_ms(18);
PORTC.F7 = 1; //RD0 sends 1 to the sensor
delay_us(30);
TRISC.F7 = 1; //Configure RD0 as input
}
//////////////////////////////
void CheckResponse(){
Check = 0;
delay_us(40);
if (PORTC.F7 == 0){
delay_us(80);
if (PORTC.F7 == 1) Check = 1; delay_us(40);}
}
//////////////////////////////
char ReadData(){
char i, j;
for(j = 0; j < 8; j++){
while(!PORTC.F7); //Wait until PORTD.F0 goes HIGH
delay_us(30);
if(PORTC.F7 == 0)
i&= ~(1<<(7 - j)); //Clear bit (7-b)
else {i|= (1 << (7 - j)); //Set bit (7-b)
while(PORTC.F7);} //Wait until PORTD.F0 goes LOW
}
return i;
}
//////////////////////////////
//Timer0
//Prescaler 1:1; TMR0 Preload = 35536; Actual Interrupt Time : 10 ms
//Place/Copy this part in declaration section
void InitTimer0(){
T0CON = 0x88;
TMR0H = 0x8A;
TMR0L = 0xD0;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x8A;
TMR0L = 0xD0;
//Enter your code here
}
}
//==========================PROGRAM1======================================//
void PROGRAM1()
{
StartSignal(); CheckResponse();
if(Check == 1)
{
RH_byte1 = ReadData(); RH_byte2 = ReadData();
T_byte1 = ReadData(); T_byte2 = ReadData();
Sum = ReadData();
if(Sum == ((RH_byte1+RH_byte2+T_byte1+T_byte2) & 0XFF)){
Temp = T_byte1;
Temp = (Temp << 8) | T_byte2;
RH = RH_byte1;
RH = (RH << 8) | RH_byte2;
Lcd_Out(1, 1, "Temp: . C T ");
Lcd_Out(2, 1, "Humi: . % H ");
if (Temp > 0X8000){
Lcd_Out(1, 11, "-");
Temp = Temp & 0X7FFF; }
LCD_Chr(1, 7, 48 + ((Temp / 100) % 10));
LCD_Chr(1, 8, 48 + ((Temp / 10) % 10));
LCD_Chr(1, 10, 48 + (Temp % 10));
LCD_Chr(2, 7, 48 + ((RH / 100) % 10));
LCD_Chr(2, 8, 48 + ((RH / 10) % 10));
LCD_Chr(2, 10, 48 + (RH % 10));
}
else{
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD
Lcd_Out(1, 1, "Check sum error");}
}
else
{
Lcd_Out(1, 1, "[..] NO response");
Lcd_Out(2, 1, "|||| the sensor");
delay_ms(2000);Lcd_Cmd(_LCD_CLEAR);
}
delay_ms(2000);
}
void main() {
TRISC=0; PORTC=0; TRISB=0; PORTB=0; TRISD=243; PORTD=0;
TRISA=1;PORTA=0; TRISE=0; PORTE=0;
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 7; // Disable comparators
InitTimer0();
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD
Lcd_Out(1, 1, "Welcome!"); delay_ms(2000);
while(1){
PROGRAM1();
}
}
نسخة برنامج البروتس 8.3
بالتوفيق