📄 max1169.c
字号:
/*
* DEMO of maxqi2c Software I2C Driver
* (uses evkits for the MAX1169 and MAXQ2000)
*
* by: Paul Holden - MAXIM INTEGRATED PRODUCTS
*
*
* DESC: Test program for the maxqi2c.c/maxqi2c.h I2C
* driver for the MAXQ2000. The program reads
* 16-bit samples from the MAX1169 (running in
* continuous conversion mode) and transmits them
* using the UART0 port.
*
* NOTE - THE FOLLOWING CODE ASSUMES THE MAXQ2000 HAS
* A Fsysclk=20MHz.
*/
#include "iomaxq200x.h"
#include "maxqi2c.h"
void main()
{
unsigned char data[2];
// 1. Init UART0
PD7_bit.bit0 = 1; // Set TX0 pin as output
SCON0 = 0x42;
SMD0 = 0x02;
PR0 = 0x07DD; // 19200bps
// 2. Init bit-banged I2C port
i2cInit();
// 3. Send initial I2C request
// [S] [ADDR+R] [A] [clock_stretch] [DATA0] [A] [DATA1] [A (termination)]
i2cData = (unsigned char *)(&data); // cast needed!
i2cDataAddr = 0x7E;
i2cDataLen = 0x0002;
i2cDataTerm = I2C_TERM_ACK;
i2cRecv();
// 4. Init continuous conversion
// [clock_stretch] [DATA0] [A] [DATA1] [A (termination)]
i2cDataAddr = 0x00;
// 5. Receive a 16-bit sample and transfer it to the UART0 port
// one byte at a time. Repeat forever...
while (1)
{
i2cRecv();
while(!SCON0_bit.TI); // Wait for UART0 Buffer to be empty
SCON0_bit.TI = 0; // Reset TI flag
SBUF0 = data[0]; // Send data byte 0
while(!SCON0_bit.TI); // Wait for UART0 Buffer to be empty
SCON0_bit.TI = 0; // reset TI flag
SBUF0 = data[1]; // Send data byte 1
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -