⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c.svn-base

📁 由MSP430F135做控制器的温度控制详细程序
💻 SVN-BASE
字号:


#include"../inc/resources.h"

void delay( unsigned int dt)
{
	unsigned int i;
	for( i = 0; i < dt; i--);
}

void basic_clk_config( void )
{
		
	BCSCTL1 &= ~XT2OFF;     //turn on XT2
	do{
		IFG1 &= ~OFIFG;		//clear OFIFG
		delay(0xff);            //waiting for XT2  ready
	
	}while( (IFG1 & OFIFG) != 0 );
	
	BCSCTL2 |= SELM_2 + DIVM_0 + SELS +DIVS_1; //MCLK 4MHZ; SMCLK 2MHZ
	
	//flsh program clk
	FCTL2 = FWKEY + FSSEL_1 + FN3 + FN1;	 //MCLK/11 
	
}


void port1_6_config( void )
{
	//P1 configure
	P1SEL = 0x00;           //P1 select for the  pin  for keyboard
	P1DIR = 0x00;           //P1.0--7  in
	P1OUT = 0x00;           
	P1IES = 0xff;		//intflag set with fall-edge 
	P1IFG = 0x00;		//clear interruput flag
	P1IE  = 0xff;           //enable interrupt 
 
	//P2 configure
	P2SEL = 0x00;           //P2 select for the  pin
	P2DIR = 0xff;           //P2.0~7 out for  lamp     
	P2OUT = 0x00;
	P2IES = 0x00;		//intflag set with fall-edge
	P2IFG = 0x00;           //clear interflag
	P2IE  = 0xff;           //disable interrupt 
	
	//P3 configure
	P3SEL = 0x30;           //P3.4~5 select for the UART0,
	P3DIR = 0xdf;           // p3.5 in for uart RXD;  others out for control;
	P3OUT = 0x00;
	
	//P4 configure
	P4SEL = 0x02;           //P4.2 for tb1,other select for out
	P4DIR = 0xff;           //P4.0~7  out  
	P4OUT = 0x00;           //p4 out for led 

	//P5 configure
	P5SEL = 0x00;           //P5 select for the  pin
	P5DIR = 0xff;           //P5 out 
	P5OUT = 0x00;           //p5 out for led

	//P6 configure
	P6SEL = 0xff;		// P6.2 ADC option select
	P6DIR = 0x00;		// P6 initinal in state 
	P6OUT = 0x00;
	
}
	
void timer_a_config( void )
{
	TACCR0 = 25000 -1;		//0.025s
	TACTL |= TASSEL_2 + ID_2;
	TACTL |= MC_1 + TAIE;
	
}



void timer_b_config( void )
{
	
	TBCCR0 = 50000 - 1;		// 0.05 s
	TBCTL = TBSSEL_2 + CNTL_0 + ID_2 + MC_1 + TBIE;//smclk/4=1mhz
	TBCCTL1 = CAP + SCS + CCIS0 + CM_1 + CCIE;
}


void uart_config( void )
{
	//USART0 INIT 主机
	UCTL0 &= ~SWRST; 	//SWRST reset
	UCTL0 |= 0x98; 		//8 bit data;odd check ; 1 start bit ; 1 stop bit;
	UTCTL0 |= 0x08;		//clocl select smclk
	
	UBR00 = 0x05;//0xA0;
	UBR10 =0x0D; //0x01;		//4MHz clock 1200bps 
                                        //4MHz/1200 = 3333.3333  
	UMCTL0= 0x07;		//Modulation Control   0.3333*8 = 2.6663
	ME1 = URXE0 + UTXE0;      //????
		
	
	IE1 |= ( UTXIE0 + URXIE0 );	//enable interrupt???
	//rs485out_();
}





void msp430config( void )
{    

	WDTCTL = WDTPW + WDTHOLD;	//colse WDT     
	
	basic_clk_config();
	
	//IO port config
	port1_6_config();

	//timer A
        timer_a_config(); 
	

        
        //timer B
        timer_b_config();
        
	//UART 
	uart_config();
       
	_EINT();		//enable all interrupt
        
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -