您的位置 首页 被动

MSP430G2553单片机驱动TLC5540

includemsp430g2553h>includestdiohtypedefunsignedcharINT8U;typedefunsignedintINT16U;defineADC_CTRL

#include <msp430g2553.h>

#include “stdio.h”
typedef unsigned char INT8U;
typedef unsigned int INT16U;
#define ADC_CTRL_DIR_PORT (P2DIR)
#define ADC_CTRL_OUT_PORT (P2OUT)
#define ADC_DATA_DIR_PORT (P1DIR)
#define ADC_DATA_IN_PORT (P1IN)

#define ADC_OE_BIT (BIT0)
#define ADC_CLK_BIT (BIT1)

#define ADC_OE_H (ADC_CTRL_OUT_PORT |= ADC_OE_BIT)
#define ADC_OE_L (ADC_CTRL_OUT_PORT &= ~ADC_OE_BIT)

#define ADC_CLK_H (ADC_CTRL_OUT_PORT |= ADC_CLK_BIT)
#define ADC_CLK_L (ADC_CTRL_OUT_PORT &=~ ADC_CLK_BIT)

INT16U RcvDataBuff_G[50];
void ADC_RcvData(INT16U *pData,INT16U RcvDataNum);
INT16U ADC_RcvOneData(void);
void ClockInit(void);
void ADC_PortInit(void);
unsigned char UartInit(unsigned long baud,unsigned char parity,unsigned char dataBits,unsigned char stopBits);
void UART_PutChar( int c);
void UART_PutString( int *s);
unsigned char UART_GetChar();

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
unsigned char i;
INT16U ADC_Temp;

ADC_PortInit();
ClockInit();
UartInit(9600,n,8,1);
_EINT();

while(1)
{
ADC_RcvData(RcvDataBuff_G,50);
for(i = 0;i < 50;i++)
printf(“ADC_Ruselt = %d “,RcvDataBuff_G[i]);
// ADC_Temp = (INT16U)ADC_RcvOneData();
//printf(“ADC_Ruselt = %d “,ADC_Temp);
__delay_cycles(100000);
}
}

void ADC_PortInit(void)
{
ADC_CTRL_DIR_PORT |= ADC_OE_BIT + ADC_CLK_BIT;
ADC_DATA_DIR_PORT = 0x00;//数据输入端口
}
void ClockInit(void)
{
if(CALDCO_1MHZ == 0xff || CALBC1_1MHZ == 0xff)
{
while(1);
}
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
}

INT16U ADC_RcvOneData(void)
{
INT16U ADCResult,i;
ADC_CLK_L;
ADC_OE_H;
for(i = 0;i < 3;i++)
{
ADC_CLK_L;
_NOP();
ADC_CLK_H;
}
ADC_OE_L;
ADCResult = ADC_DATA_IN_PORT;
return (ADCResult);
}
void ADC_RcvData(INT16U *pData,INT16U RcvDataNum)
{
INT16U i;
for(i = 0;i < RcvDataNum;i++)
{
pData[i] = (INT16U)ADC_RcvOneData();
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/beidong/318545.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部