标题:
Msp430f5529跟FDC2214源码与资料下载
[打印本页]
作者:
1106998808
时间:
2018-7-21 12:57
标题:
Msp430f5529跟FDC2214源码与资料下载
例程跟2018ti杯d题
全部资料51hei下载地址:
FDC2214_F5529_Good程序.rar
(66.03 KB, 下载次数: 70)
2018-7-21 12:56 上传
点击文件名下载附件
下载积分: 黑币 -5
MSP430F5529 TI官方开发板的实例程序(非常好).rar
(611.21 KB, 下载次数: 56)
2018-7-21 12:56 上传
点击文件名下载附件
下载积分: 黑币 -5
0.png
(7.47 KB, 下载次数: 63)
下载附件
2018-7-21 18:45 上传
Msp430f5529单片机驱动fdc2214的源码:
#include <msp430F5529.h>
#include "IIC_Soft.h"
#include "FDC2214.h"
#include "delay.h"
#define uint8_t unsigned char
#define UCA1_OS 1 // 1 = oversampling mode, 0 = low-freq mode
#define UCA1_BR0 17 // Value of UCA1BR0 register
#define UCA1_BR1 0 // Value of UCA1BR1 register
#define UCA1_BRS 0 // Value of UCBRS field in UCA1MCTL register
#define UCA1_BRF 6 // Value of UCBRF field in UCA1MCTL register
void bcUartSend(uint8_t * buf, uint8_t len);
void delay_ms(unsigned int count);
void UartSend(uint8_t * buf);
void sys_clk_config(void);
void uart_config(void);
unsigned char HexToChar(unsigned char bHex);
/*
* main.c
*/
int main(void) {
unsigned long ch0_value = 0;
unsigned char dat[8]=0;
WDTCTL = WDTPW + WDTHOLD;
sys_clk_config();
uart_config();
__bis_SR_register(GIE);
FDC2214_Init();
// __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
// __no_operation(); // For debugger
while(1)
{
ch0_value = FDC2214_GetResult(0); //读取通道0,发送到串口,转为字符型方便观察。
UartSend("Ch0_value is:");
dat[0] = (unsigned char)(((ch0_value>>24)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>24)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
UartSend("\n");delay_ms(100);
ch0_value = FDC2214_GetResult(1);
UartSend("Ch1_value is:");
dat[0] = (unsigned char)(((ch0_value>>24)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>24)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
UartSend("\n");delay_ms(100);
ch0_value = FDC2214_GetResult(2);
UartSend("Ch2_value is:");
dat[0] = (unsigned char)(((ch0_value>>24)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>24)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
UartSend("\n");delay_ms(100);
ch0_value = FDC2214_GetResult(3);
UartSend("Ch3_value is:");
dat[0] = (unsigned char)(((ch0_value>>24)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>24)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>16)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>8)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>4)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
dat[0] = (unsigned char)(((ch0_value>>0)>>0)&0X0F);
dat[0] = HexToChar(dat[0]);
Uart_Send_Char(dat[0]);
UartSend("\n");delay_ms(100);
UartSend("\n"); //换行,延时,方便观察数据
delay_ms(10000);delay_ms(10000);
}
// return 0;
}
/************USCI_A1中断*************/
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{ switch(__even_in_range(UCA1IV,4))
{
case 0:break;
case 2:
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = UCA1RXBUF; // 将接收到的数据发送出去
break;
case 4:break;
default: break;
}
}
// Sends 'len' bytes, starting at 'buf'
void bcUartSend(uint8_t * buf, uint8_t len)
{
uint8_t i = 0;
// Write each byte in buf to USCI TX buffer, which sends it out
while (i < len)
{
UCA1TXBUF = *(buf+(i++));
// while (!(UCA1IFG&UCTXIFG));
// delay_ms(20);
// Wait until each bit has been clocked out...
while(!(UCTXIFG==(UCTXIFG & UCA1IFG))&&((UCA1STAT & UCBUSY)==UCBUSY));
}
}
void UartSend(uint8_t * buf)
{
while(*buf !='\0')
{
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF=*buf;
*buf++;
delay_ms(2);
}
}
void Uart_Send_Char(uint8_t dat)
{
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF=dat;
}
void delay_ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<10;j++)
delay_us();
}
void sys_clk_config(void) //外部晶振4M
{
P5SEL |= BIT2|BIT3;
UCSCTL6 &= ~XT2OFF;
UCSCTL4 = UCSCTL4&(~(SELA_7))|SELA_1;
UCSCTL3 |= SELREF_2;
while (SFRIFG1 & OFIFG)
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
SFRIFG1 &= ~OFIFG;
}
UCSCTL4 = UCSCTL4&(~(SELS_7|SELM_7))|SELS_5|SELM_5;
}
void uart_config(void)
{
P4SEL |= BIT4+BIT5;
UCA1CTL1 |= UCSWRST;
UCA1CTL1 |= UCSSEL_2;
UCA1BR0 = 34;//115200,外部4M
UCA1BR1 = 0;
UCA1MCTL |= UCBRS_6+UCBRF_0;
UCA1CTL1 &= ~UCSWRST;
UCA1IE |= UCRXIE;
}
unsigned char HexToChar(unsigned char bHex)
{
if((bHex>=0)&&(bHex<=9))
{
bHex += 0x30;
}
else if((bHex>=10)&&(bHex<=15))//Capital
{
bHex += 0x37;
}
else
{
bHex = 0xff;
}
return bHex;
}
复制代码
作者:
从何说起
时间:
2018-7-22 00:32
232021045.248是什么。。。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1