|
这是我自己使用的,很方便
#include "msp430x22x4.h"
//----------------------------------------------------
//Description: msp430系列单片机常用端口位操作
//write by Meredith
//2007.5.1
//email:cyberkyg@163.com
//
//modify at 2010.4.21
//-----------------------------------------------------
#ifndef _MSP430_KYG_H_
#define _MSP430_KYG_H_
#define U8 unsigned char
#define U16 unsigned int
#define uint unsigned int
#define uchar unsigned char
//----------------IO bits Set/Clr---------------------
#define ClrP1(n) P1OUT&=(~n)
#define SetP1(n) P1OUT|=n
#define ClrP2(n) P2OUT&=(~n)
#define SetP2(n) P2OUT|=n
#define ClrP3(n) P3OUT&=(~n)
#define SetP3(n) P3OUT|=n
#define ClrP4(n) P4OUT&=(~n)
#define SetP4(n) P4OUT|=n
#define ClrP5(n) P5OUT&=(~n)
#define SetP5(n) P5OUT|=n
#define ClrP6(n) P6OUT&=(~n)
#define SetP6(n) P6OUT|=n
//--------------------IO bits Input/Output--------------------------
#define SetInP1(n) P1DIR&=(~n)
#define SetOutP1(n) P1DIR|=n
#define SetInP2(n) P2DIR&=(~n)
#define SetOutP2(n) P2DIR|=n
#define SetInP3(n) P3DIR&=(~n)
#define SetOutP3(n) P3DIR|=n
#define SetInP4(n) P4DIR&=(~n)
#define SetOutP4(n) P4DIR|=n
#define SetInP5(n) P5DIR&=(~n)
#define SetOutP5(n) P5DIR|=n
#define SetInP6(n) P6DIR&=(~n)
#define SetOutP6(n) P6DIR|=n
//---------------------IO bits PULL Enabled/Disabled----------------
#define PullEnabledP1(n) P1REN|=n
#define PullDisabledP1(n) P1REN&=(~n)
#define PullEnabledP2(n) P2REN|=n
#define PullDisabledP2(n) P2REN&=(~n)
#define PullEnabledP3(n) P3REN|=n
#define PullDisabledP3(n) P3REN&=(~n)
#define PullEnabledP4(n) P4REN|=n
#define PullDisabledP4(n) P4REN&=(~n)
#define PullEnabledP5(n) P5REN|=n
#define PullDisabledP5(n) P5REN&=(~n)
#define PullEnabledP6(n) P6REN|=n
#define PullDisabledP6(n) P6REN&=(~n)
//---------------------IO bits PullUp/PullDown----------------------
#define PullDownP1(n) P1OUT&=(n)
#define PullUpP1(n) P1OUT|=n
#define PullDownP2(n) P2OUT&=(~n)
#define PullUpP2(n) P2OUT|=n
#define PullDownP3(n) P3OUT&=(~n)
#define PullUpP3(n) P3OUT|=n
#define PullDownP4(n) P4OUT&=(~n)
#define PullUpP4(n) P4OUT|=n
#define PullDownP5(n) P5OUT&=(~n)
#define PullUpP5(n) P5OUT|=n
#define PullDownP6(n) P6OUT&=(~n)
#define PullUpP6(n) P6OUT|=n
//------------------------IO bits Input-----------
#define P1Input(n) P1IN&n?1:0
#define P2Input(n) P2IN&n?1:0
#define P3Input(n) P3IN&n?1:0
#define P4Input(n) P4IN&n?1:0
#define P5Input(n) P5IN&n?1:0
#define P6Input(n) P6IN&n?1:0
//------------------------------------------------------------------------
#define DCO_F 16 //定义主时钟频率,1,8,12,16(MHZ)
#define _delay_us(n) __delay_cycles((float)(n)*DCO_F) //20us以下误差较大
#define _delay_ms(n) __delay_cycles(n*(1000.0f)*DCO_F)
//----------------------------------------------------------------------------
void Init_CLK(unsigned char nDco);
#endif |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|