| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | //***************************************************************************** |
| 2 | // File Name : ds1631test.c |
||
| 3 | // |
||
| 4 | // Title : example usage of DS1631 library functions |
||
| 5 | // Revision : 1.0 |
||
| 6 | // Notes : |
||
| 7 | // Target MCU : Atmel AVR series |
||
| 8 | // Editor Tabs : 4 |
||
| 9 | // |
||
| 10 | // Revision History: |
||
| 11 | // When Who Description of change |
||
| 12 | // ----------- ----------- ----------------------- |
||
| 13 | // 20-Feb-2004 pstang Created the program |
||
| 14 | //***************************************************************************** |
||
| 15 | |||
| 16 | //----- Include Files --------------------------------------------------------- |
||
| 17 | #include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
||
| 18 | #include <avr/interrupt.h> // include interrupt support |
||
| 19 | |||
| 20 | #include "global.h" // include our global settings |
||
| 21 | #include "uart.h" // include uart function library |
||
| 22 | #include "rprintf.h" // include printf function library |
||
| 23 | #include "timer.h" // include timer function library (timing, PWM, etc) |
||
| 24 | #include "vt100.h" // include VT100 terminal support |
||
| 25 | #include "i2c.h" // include i2c support |
||
| 26 | #include "ds1631.h" // include DS1631 support |
||
| 27 | |||
| 28 | void ds1631test(void); |
||
| 29 | |||
| 30 | //----- Begin Code ------------------------------------------------------------ |
||
| 31 | int main(void) |
||
| 32 | { |
||
| 33 | // initialize our libraries |
||
| 34 | // initialize the UART (serial port) |
||
| 35 | uartInit(); |
||
| 36 | uartSetBaudRate(115200); |
||
| 37 | // make all rprintf statements use uart for output |
||
| 38 | rprintfInit(uartSendByte); |
||
| 39 | // initialize the timer system |
||
| 40 | timerInit(); |
||
| 41 | // clear terminal screen |
||
| 42 | vt100ClearScreen(); |
||
| 43 | vt100SetCursorPos(1,1); |
||
| 44 | // print a little intro message so we know things are working |
||
| 45 | rprintf("\r\nWelcome to DS6131 test!\r\n"); |
||
| 46 | |||
| 47 | // run tests |
||
| 48 | ds1631test(); |
||
| 49 | |||
| 50 | return 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | |||
| 54 | void ds1631test(void) |
||
| 55 | { |
||
| 56 | s16 T=0; |
||
| 57 | |||
| 58 | // initialize i2c function library |
||
| 59 | i2cInit(); |
||
| 60 | i2cSetBitrate(100); |
||
| 61 | |||
| 62 | // initialize |
||
| 63 | if(ds1631Init(DS1631_I2C_ADDR)) |
||
| 64 | { |
||
| 65 | rprintf("DS1631 detected and initialized!\r\n"); |
||
| 66 | } |
||
| 67 | else |
||
| 68 | { |
||
| 69 | rprintf("Cannot detect DS1631!\r\n"); |
||
| 70 | return; |
||
| 71 | } |
||
| 72 | |||
| 73 | // set config |
||
| 74 | ds1631SetConfig(DS1631_I2C_ADDR, 0x0F); |
||
| 75 | // set the temperature limit registers |
||
| 76 | ds1631SetTH(DS1631_I2C_ADDR, 35<<8); |
||
| 77 | ds1631SetTL(DS1631_I2C_ADDR, 30<<8); |
||
| 78 | // read them back for verification |
||
| 79 | rprintf("TH is set to: %d\r\n",ds1631GetTH(DS1631_I2C_ADDR)>>8); |
||
| 80 | rprintf("TL is set to: %d\r\n",ds1631GetTL(DS1631_I2C_ADDR)>>8); |
||
| 81 | |||
| 82 | while(1) |
||
| 83 | { |
||
| 84 | // start convert |
||
| 85 | ds1631StartConvert(DS1631_I2C_ADDR); |
||
| 86 | // wait until done |
||
| 87 | // this works but seems to take forever (5-10 seconds) |
||
| 88 | //while(!(ds1631GetConfig(DS1631_I2C_ADDR) & DS1631_CONFIG_DONE)); |
||
| 89 | // 12-bit conversion are only suppored to take this long |
||
| 90 | timerPause(750); |
||
| 91 | |||
| 92 | // read temp |
||
| 93 | T = ds1631ReadTemp(DS1631_I2C_ADDR); |
||
| 94 | |||
| 95 | |||
| 96 | // Print the raw temperature reading |
||
| 97 | rprintf("Raw Temp: %d ", T); |
||
| 98 | // Print the formatted temperature reading |
||
| 99 | rprintf("Real Temp is: "); |
||
| 100 | rprintfNum(10, 4, TRUE , ' ', T>>8); |
||
| 101 | rprintf("."); |
||
| 102 | rprintfNum(10, 4, FALSE, '0', (10000*((u32)(T&0x00FF)))/256 ); |
||
| 103 | rprintf(" degrees C\r\n"); |
||
| 104 | |||
| 105 | timerPause(50); |
||
| 106 | } |
||
| 107 | } |
Powered by WebSVN v2.8.3