?? main.c
字號:
#include "systemInit.h"
#include "uartGetPut.h"
#include "LM3S_I2CM.h"
#include <stdio.h>
// 定義LM75A(NXP半導體數字溫度傳感器,I2C接口)
#define LM75A_SLA (0x90 >> 1) // 定義LM75A的器件地址
#define LM75A_REG_TMP 0x00 // 定義LM75A的溫度寄存器地址
// 讀取LM75A的溫度值,并通過UART發送顯示
void LM75A_TmpDisp(char *pcTmp)
{
char Tab[8][4] = {"000", "125", "250", "375", "500", "625", "750", "875"};
char s[20];
short t;
t = pcTmp[0];
t <<= 8;
t |= pcTmp[1] & 0xE0;
if (t < 0)
{
t = -t;
uartPutc('-');
}
sprintf(s, "%d", (int)(t) / 256);
uartPuts(s);
uartPutc('.');
uartPuts(Tab[(t >> 5) & 0x07]);
uartPuts("\r\n");
}
// 主函數(程序入口)
int main(void)
{
char cBuf[2];
unsigned long ulStatus;
tI2CM_DEVICE LM75A = {LM75A_SLA, LM75A_REG_TMP, 1, cBuf, 2};
jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 時鐘初始化:晶振,6MHz
uartInit(); // UART初始化
I2CM_Init(); // I2C主機初始化
for (;;)
{
ulStatus = I2CM_DataRecv(&LM75A);
if (ulStatus == I2C_MASTER_ERR_NONE) // 沒有錯誤
{
LM75A_TmpDisp(cBuf); // 顯示LM75A溫度
}
else
{
uartPuts("Error\r\n");
if (ulStatus & I2C_MASTER_ERR_ADDR_ACK) // 地址應答錯誤
{
uartPuts("cannot find LM75A.\r\n");
}
if (ulStatus & I2C_MASTER_ERR_DATA_ACK) // 數據應答錯誤
{
uartPuts("cannot get data from LM75A.\r\n");
}
if (ulStatus & I2C_MASTER_ERR_ARB_LOST) // 多主機通信仲裁失敗
{
uartPuts("arbitration lost.\r\n");
}
break;
}
SysCtlDelay(1500 * (TheSysClock / 3000));
}
for (;;)
{
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -