新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > MSP430G2553單片機(jī)驅(qū)動TLC5540

MSP430G2553單片機(jī)驅(qū)動TLC5540

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
#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)

本文引用地址:http://m.butianyuan.cn/article/201611/323975.htm

#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;//數(shù)據(jù)輸入端口
}
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();
}
}



評論


技術(shù)專區(qū)

關(guān)閉