MSP430G2553单片机驱动TLC5540
#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();
}
}
MSP430G2553TLC5540ADC转 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)