微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > MSP430G2553单片机驱动TLC5540

MSP430G2553单片机驱动TLC5540

时间:11-30 来源:互联网 点击:
#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();
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top