Bit set komut karşılığı

  • Konbuyu başlatan fatih akalper
  • Başlangıç tarihi
Katılım
14 Ocak 2019
Mesajlar
3
Puanları
1
Yaş
27
bit_set komutunun micro c pro for arm(stm32f407vg işlemci) daki karşılığ nedir acaba acil yardım lütfen...
kısaca kod
bit_set(veri,(7-i)) //i for döngüsü ile değişiyor.
 

mehmet.bey

Usta Üye
Katılım
19 Ara 2011
Mesajlar
1,270
Puanları
183
Kod:
/* Bit Operation macros */
#define sbi(b,n) ((b) |=   (1<<(n)))        /* Set bit number n in byte b   */
#define cbi(b,n) ((b) &= (~(1<<(n))))       /* Clear bit number n in byte b */
#define rbi(b,n) ((b) &    (1<<(n)))        /* Read bit number n in byte b  */
#define fbi(b,n) ((b) ^=   (1<<(n)))        /* Flip bit number n in byte b  */

#define bit_is_set(b,n)   (b & (1<<n))      /* Test if bit number n in byte b is set   */
#define bit_is_clear(b,n) (!(b & (1<<n)))   /* Test if bit number n in byte b is clear */ 

#define pinToggle(PORT, n)  (PORT ^= 1 << n)
 
Konu Sah
Katılım
14 Ocak 2019
Mesajlar
3
Puanları
1
Yaş
27
Mehmet bey öncelikle cevap verdıgınız için çok tesekkur ederım. DHT22(AM2302) sensörünün micro c pro for arm programında (stm32f407vg işlemci) nasıl kullanıldıgı veya kodları hakkında tecrübeniz varmı. Ben micro c nin pic için olan versıyonunu pro arm a göre entegre etmeye çalıştım ancak dht yi çalıştıramadım. Yardımcı olursanız sevınırım
Kod:
// 1us DE 1 KESME OLUSTURUR.
     //NVIC_SetIntPriority(IVT_INT_TIM7, _NVIC_INT_PRIORITY_LVL0);
     RCC_APB1ENR.TIM4EN = 1;
     TIM4_CR1.CEN = 0;
     TIM4_DIER.UIE = 1;
     TIM4_PSC = 0;
     TIM4_ARR = 83;
     NVIC_IntEnable(IVT_INT_TIM4);


void Timer4_interrupt()iv IVT_INT_TIM4
{
TIM4_SR.UIF = 0;
  sayici++;
}

void Start_Signal(void) {
  TIM4_CR1.CEN = 1;
  DHT22_PIN_OUT;                    // Configure connection pin as output
  DHT22_PIN = 0;                              // Connection pin output low
  delay_ms(25);                               // Wait 25 ms
  DHT22_PIN = 1;                              // Connection pin output high
  delay_us(25);                               // Wait 25 us
  DHT22_PIN_IN;                    // Configure connection pin as input
}

unsigned short Check_Response() {
  //TMR1H = 0;                                  // Reset Timer1
  //TMR1L = 0;                                  // Enable Timer1 module
    sayici=0;
    TIM4_CR1.CEN = 1;                        
  //
  while(!DHT22_PIN && sayici < 100);  // Wait until DHT11_PIN becomes high (checking of 80µs low time response)
  if(sayici > 99)                              // If response time > 99µS  ==> Response error
  return 0;
  else {  
     sayici = 0;                        // Reset Timer1
    while(DHT22_PIN && sayici < 100);          // Wait until DHT11_PIN becomes low (checking of 80µs high time response)
 
    if(sayici > 99){                            // If response time > 99µS  ==> Response error
      return 0;                               // Return 0 (Device has a problem with response)
      }
    else
      return 1;                               // Return 1 (response OK)
  }
}

unsigned short Read_Data(unsigned short* dht_data) {
  short i;
  *dht_data = 0;
  for(i = 0; i < 8; i++){
    sayici=0;//TMR1H = 0;                                // Reset Timer1
    //TMR1L = 0;
    while(!DHT22_PIN)
    if(sayici > 100) {                       // If low time > 100  ==>  Time out error (Normally it takes 50µs)
        return 1;
        }
        sayici = 0;                                // Reset Timer1
    //TMR1L = 0;
    while(DHT22_PIN)
    if(sayici > 100) {                       // If high time > 100  ==>  Time out error (Normally it takes 26-28µs for 0 and 70µs for 1)
    return 1;
                                     // Return 1 (timeout error)
      }
       if(sayici > 50)                           // If high time > 50  ==>  Sensor sent 1
       *dht_data |= (1 << (7 - i));           // Set bit (7 - i)
  }
  return 0;                                   // Return 0 (data read OK)
}
 
Moderatör tarafında düzenlendi:

muratmert4

Usta Üye
Katılım
26 Eyl 2007
Mesajlar
1,049
Puanları
158
Yaş
46
Konum
ANTALYA
C:
/*
 * Project name:
     DHT22 click (Demonstration of mikroBUS DHT22 click board)
 * Copyright:
     (c) Mikroelektronika, 2015.
 * Revision History:
     20140225:
       - initial release (FJ);
 * Description:
     This code demonstrates how to use DHT22 click with EasyMX Pro v7 board.
     DHT22 sensor measures temperature and relative humidity.
 * Test configuration:
     MCU:             STM32F107VC
                      http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/CD00171190.pdf
     Dev. Board:      EasyMx PRO v7 for STM32
                      http://www.mikroe.com/eng/products/view/852/easymx-pro-v7-for-stm32/
     Oscillator:      HS-PLL 72.0000 MHz
                      http://www.mikroe.com/store/components/displays/
     SW:              mikroC PRO for ARM
                      http://www.mikroe.com/mikroc/arm/
 * NOTES:
     - Place DHT22 click board at the mikroBUS socket 1 on the EasyMx Pro v7 board.
     - Put EasyTFT in its socket, turn on backlight using the SW11.3
 */

#include <resources.h>

// TFT module connections
unsigned int TFT_DataPort at GPIOE_ODR;
sbit TFT_RST at GPIOE_ODR.B8;
sbit TFT_RS at GPIOE_ODR.B12;
sbit TFT_CS at GPIOE_ODR.B15;
sbit TFT_RD at GPIOE_ODR.B10;
sbit TFT_WR at GPIOE_ODR.B11;
sbit TFT_BLED at GPIOE_ODR.B9;
// End TFT module connections

// AM2302 module connections
sbit AM2302_Bus_Out at GPIOD_ODR.B13;
sbit AM2302_Bus_In at GPIOD_IDR.B13;
// END AM2302 module connections

char AM2302_Data[5] = {0, 0, 0, 0, 0};
unsigned humidity = 0, temperature = 0;

//Get Sensor values

char AM2302_Read(unsigned *humidity, unsigned *temperature) {
  char i = 0, j = 1;
  char timeout = 0;
  char sensor_byte;

  GPIO_Digital_Input(&GPIOD_BASE, _GPIO_PINMASK_13);  //Set GPIOD pin 13 as digital input

  GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_13); //Set GPIOD pin 13 as digital output
  AM2302_Bus_Out = 1;                                 //Set GPIOD pin 13 HIGH for 100 milliseconds
  Delay_ms(100);                                      //Delay 100ms
  AM2302_Bus_Out = 0;                                 //Host the start signal down time min: 0.8ms, typ: 1ms, max: 20ms
  Delay_ms(2);                                        //Delay 2ms
  AM2302_Bus_Out = 1;                                 //Set GPIOD pin 13 HIGH
  GPIO_Digital_Input(&GPIOD_BASE, _GPIO_PINMASK_13);  //Set GPIOD pin 13 as digital input

  // Bus master has released time min: 20us, typ: 30us, max: 200us
  timeout = 200;
  while (AM2302_Bus_In) {
    Delay_us(1);
    if (!timeout--) {
      return 1;
    } //ERROR: Sensor not responding
  }
 
  // AM2302 response signal min: 75us, typ: 80us, max: 85us
  while (!AM2302_Bus_In) { //response to low time
    Delay_us(1);
  }
 
  while (AM2302_Bus_In) { //response to high time
    Delay_us(1);
  }
 
  /*
   * time in us:            min  typ  max
   * signal 0 high time:    22   26   30 (bit=0)
   * signal 1 high time:    68   70   75 (bit=1)
   * signal 0,1 down time:  48   50   55
   */
  
  i = 0; //get 5 byte
  for (i = 0; i < 5; i++) {
    j = 1;
    for (j = 1; j <= 8; j++) { //get 8 bits from sensor
      while (!AM2302_Bus_In) { //signal "0", "1" low time
        Delay_us(1);
      }
      Delay_us(30);
      sensor_byte <<= 1;       //add new lower byte
      if (AM2302_Bus_In) {     //if sda high after 30us => bit=1 else bit=0
        sensor_byte |= 1;
        delay_us(45);
        while (AM2302_Bus_In) {
          Delay_us(1);
        }
      }
    }
    AM2302_Data[i] = sensor_byte;
  }
 
  *humidity = (AM2302_Data[0] << 8) + AM2302_Data[1];
  *temperature = (AM2302_Data[2] << 8) + AM2302_Data[3];

  return 0;
}

void Clear_TFT_humidity() {
TFT_Set_Font(&Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL);
TFT_Set_Pen(CL_WHITE, 10);
TFT_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
TFT_Rectangle(170,80,230,95);
TFT_Rectangle(40,160,320,180);
}

void Clear_TFT_temperature() {
TFT_Set_Font(&Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL);
TFT_Set_Pen(CL_WHITE, 10);
TFT_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
TFT_Rectangle(170,100,230,115);
TFT_Rectangle(40,160,320,180);
}

void Clear_TFT_Error() {
TFT_Set_Font(&Tahoma15x16_Bold, CL_RED, FO_HORIZONTAL);
TFT_Set_Pen(CL_WHITE, 10);
TFT_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
TFT_Rectangle(40,160,320,180);
TFT_Rectangle(170,100,230,115);
TFT_Rectangle(170,80,230,95);
}

// Process and display current value to TFT
void processValue(unsigned humidity, unsigned temperature) {
  char txt[15];
  float temp;

  temp = humidity / 10.0;
  sprintf(txt, "%2.1f", temp);    // Format Relative_humidity_val and store it to txt
  Clear_TFT_humidity();
  TFT_Write_Text(txt,170,80);
  TFT_Write_Char(0x25,200,80);

  temp = temperature / 10.0;
  sprintf(txt, "%2.1f ºC", temp); // Format UV_val and store it to txt
  Clear_TFT_temperature();
  TFT_Write_Text(txt,170,100);
}

void Display_Init(){
  TFT_Init_ILI9341_8bit(320, 240);
  TFT_BLED = 1;
}

void DrawFrame() {
  TFT_Fill_Screen(CL_WHITE);
  TFT_Set_Pen(CL_BLACK, 1);
  TFT_Line(20, 220, 300, 220);
  TFT_LIne(20,  46, 300,  46);
  TFT_Set_Font(&Tahoma15x16_Bold, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("DHT22  Click  Board  Demo", 25, 14);
  TFT_Set_Font(&Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("EasyMx PRO v7", 19, 223);
  TFT_Set_Font(&Tahoma15x16_Bold, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("www.mikroe.com", 200, 223);
  TFT_Set_Font(&Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("Relative Humidity:", 40, 80);
  TFT_Write_Text("Temperature:", 40, 100);
}

void main() {
  char k = 0, t;
 
  Display_Init();
  DrawFrame();

  while (1) {
    if (AM2302_Read(&humidity, &temperature) == 0)                 // Display AM2302_Read sensor values via TFT
      processValue(humidity, temperature);                         // Display AM2302_Read sensor values via TFT
    else {
      Clear_TFT_Error();
      TFT_Write_Text("ERROR: Sensor not responding", 40, 160);
    }
    Delay_ms(2000); //Delay 2000ms
  }
}
 

Yeni mesajlar

Forum istatistikleri

Konular
114,202
Mesajlar
803,721
Kullanıcılar
418,476
Son üye
Kadir Çalışkanelli

Yeni konular

Üst