资源简介
msp430f4793与ad7190的spi通讯。
代码片段和文件信息
#include “msp430F4793.h“
#include
#include
#define SPI_CLK_UP P3OUT|=BIT0;
#define SPI_CLK_DOWN P3OUT&=~BIT0;
#define SPI_CS_UP P3OUT|=BIT1;
#define SPI_CS_DOWN P3OUT&=~BIT1;
#define SPI_DOUT_UP P2OUT|=BIT4;
#define SPI_DOUT_DOWN P2OUT&=~BIT4;
#define SPI_DIN P2IN&BIT5
#define f 0x80 //字库定义对应的LCD段码显示
#define g 0x40
#define e 0x20
#define d 0x10
#define a 0x08
#define b 0x04
#define c 0x02
#define h 0x01
#define D 0x01
#define C 0x02
#define B 0x04
#define A 0x08
#define G 0x40
#define F 0x04
#define E 0x02
const char char_gen[10] = { // definitions for digits //字库定义要现实的8段字符数字
a+b+c+d+e+f // Displays “0“
b+c // Displays “1“
a+b+d+e+g // Displays “2“
a+b+c+d+g // Displays “3“
b+c+f+g // Displays “4“
a+c+d+f+g // Displays “5“
a+c+d+e+f+g // Displays “6“
a+b+c // Displays “7“
a+b+c+d+e+f+g // Displays “8“
a+b+c+d+f+g // Displays “9“
};
const char char_GEN[30]=
{
000000000
A+B+C+D
E+F // Displays “0“ //字库定义要现实的 米8 字符数字
B+C
0 // Displays “1“
A+B+D+G
E // Displays “2“
A+B+C+D+G
0 // Displays “3“
B+C+G
F // Displays “4“
A+C+D+G
F // Displays “5“
A+C+D+G
E+F // Displays “6“
A+B+C
0 // Displays “7“
A+B+C+D+G
E+F // Displays “8“
A+B+C+D+G
F // Displays “9“
};
void delay(int length) // 延时
{
int i=1000;
while(length>0)
{
length--;
while(i>0)
i--;
}
}
void Write_AD7190(unsigned long count) //向写AD7190指令
{
int i;
SPI_CLK_UP;
delay(10);
SPI_CS_UP;
delay(10);
SPI_CS_DOWN;
delay(10);
for(i=0;i<8;i++)
{
SPI_CLK_DOWN;
if(0x80==(count&0x80))
{
SPI_DOUT_UP;
}
else
{
SPI_DOUT_DOWN;
}
delay(10);
SPI_CLK_UP;
delay(10);
count<<=1;
}
SPI_CS_UP;
}
unsigned int Read_AD7190(void) //从AD7190读取数据
{
unsigned long MAXNO1number;
int jimx;
int LSBMSBNOs[8]={0};
MAX=0;
m=0;
SPI_CLK_UP;
SPI_CS_UP;
delay(10);
delay(10);
SPI_CS_DOWN;
delay(10);
评论
共有 条评论