اطلاعیه

Collapse
No announcement yet.

راه اندازی سنسور LM75 با codevisionAVR

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    راه اندازی سنسور LM75 با codevisionAVR

    با سلام
    توی سایت های مختلف نگاه کردم و دیدم در حق این سنسور جفا شده
    برنامه ای که توی پروتوس هم شبیه سازی کردم رو براتون میزارم
    ان شاء الله اگر عملی هم کار کردم براتون قرار میدم.
    [FONT=Yekan]#include <io.h>[/FONT]#include <mega16.h>
    #include <delay.h>
    #include <i2c.h>
    #include <lm75.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <lcd.h>
    #asm
    .equ __lcd_port=0x12; //portD
    .equ __i2c_port=0x15;
    .equ __sda_bit=1;
    .equ __scl_bit=0;
    #endasm


    int t;
    char buffer[17];
    unsigned char chip;
    signed char thyst=37;
    signed char tos=38;
    unsigned char pol=0;


    void main(void)
    {
    i2c_init();
    lcd_init(16);
    lm75_init(0, 37, 38, 0);


    while (1)
    {
    t = lm75_temperature_10(0);
    lcd_clear();
    sprintf(buffer,"%-i.%-u%cC",t/10,abs(t%10),0xdf);
    lcd_puts(buffer);
    }
    [FONT=Yekan]}
    [/FONT]




    البته کدش رو از CodeVisionAVR User Manual_Decrypted کش رفتم که میتونید به اون هم مراجعه کنید.
    اگر بزرگواری پیدا بشه و بتونه این قسمت رو ترجمه کنه ممنون میشم.

    5.24.10 National Semiconductor LM75 Temperature SensorFunctions
    These functions are intended for easy interfacing between C programs and the LM75 I2C bus
    temperature sensor, using both the hardware TWI and software bit-banged I2C bus functions.
    One of the following header files, located in the .\INC subdirectory must be #include -d before using
    these functions:
    • lm75_twi.h for hardware TWI
    • lm75.h for software bit-banged I2C bus.
    The appropriate header files for hardware TWI (twi.h or twix.h) or software bit-banged I2C bus (i2c.h)
    functions prototypes are automatically #include -d with the lm75_twi.h or lm75.h.
    The Project|Configure|C Compiler|Libraries|I2C menu must be used for specifying the I/O port
    allocation of the SCL and SDA signals, along the bit rate of the SCL clock, for bit-banged I2C bus (not
    the hardware TWI) communication.
    Note: For proper operation, the LM75 Functions require the presence of 3.3k - 4.7k pull-up
    resistors to +5V (+3.3V for XMEGA devices) on the SCL and SDA signals.
    The LM75 Functions are:
    void lm75_init(unsigned char chip,signed char thyst,signed char tos, unsigned char pol)
    this function initializes the LM75 sensor chip.
    Before calling this function, the TWI hardware, respectively I2C bus, must be initialized by calling the
    twi_master_init (twi_init, twi_master_init and lm75_twi_init for XMEGA devices), respectively
    i2c_init functions.This is the first function that must be called prior to using the other LM75 Functions.
    If more then one chip is connected to the I2C bus, then the function must be called for each one,
    specifying accordingly the function parameter chip.
    Maximum 8 LM75 chips can be connected to the I2C bus, their chip address can be from 0 to 7.
    The LM75 is configured in comparator mode, where it functions like a thermostat.
    The O.S. output becomes active when the temperature exceeds the tos limit, and leaves the active
    state when the temperature drops below the thyst limit.
    Both thyst and tos are expressed in °C.
    pol represents the polarity of the LM75 O.S. output in active state.
    If pol is 0, the output is active low and if pol is 1, the output is active high.
    Refer to the LM75 data sheet for more information.
    void lm75_twi_init(TWI_MASTER_INFO_t *ptwim)
    this function is used to initialize the LM75 library’s internal variables when using the TWI
    Functions for Master Mode Operation for XMEGA Devices.
    It is not used for non-XMEGA devices.
    The ptwim parameter must point to a TWI_MASTER_INFO_t structure variable, that is used to hold
    the information required by the TWI module when operating in master mode.
    The lm75_twi_init function must be called before lm75_init.
    Refer to the supplied example at the end of this chapter for more details.
    int lm75_temperature_10(unsigned char chip)
    this function returns the temperature of the LM75 sensor with the address chip.
    The temperature is in °C and is multiplied by 10.
    A 300ms delay must be present between two successive calls to the lm75_temperature_10 function.
لطفا صبر کنید...
X