PIN的设置
虽然做过几个项目,但对单片机PIN的设置一直不是很明白,前几天安装了silabs IDE的3.2,有很多例子。下面这个对此做了比较详细的说明。
P0.7与P3.3都是digital,所以P0MDOUT及P3MDOUT可以对相应的PIN做设置。
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This function configures the crossbar and ports pins.
//
// To configure a pin as a digital input, the pin is configured as digital
// and open-drain and the port latch should be set to a '1'. The weak-pullups
// are used to pull the pins high. Pressing the switch pulls the pins low.
//
// To configure a pin as a digital output, the pin is configured as digital
// and push-pull.
//
// An output pin can also be configured to be an open-drain output if system
// requires it. For example, if the pin is an output on a multi-device bus,
// it will probably be configured as an open-drain output instead of a
// push-pull output. For the purposes of this example, the pin is configured
// as push-pull output because the pin in only connected to an LED.
//
// P0.7 digital open-drain Switch 1
// P3.3 digital push-pull LED1
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
P0MDIN |= 0x80; // P0.7 is digital
P3MDIN |= 0x08; // P3.3 is digital
P0MDOUT = 0x00; // P0.7 is open-drain
P3MDOUT = 0x08; // P3.3 is push-pull
P0 |= 0x80; // Set P0.7 latch to '1'
XBR1 = 0x40; // Enable crossbar and enable
// weak pull-ups
}