Код
/-----------------------------------------------------------------------------
#include <ioC8051f320.h> // SFR declarations
#include <intrinsics.h>
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F32x
//-----------------------------------------------------------------------------
__sfr __no_init volatile unsigned short TMR2RL @ 0xCA; // Timer2 reload value
__sfr __no_init volatile unsigned short TMR2 @ 0xCC; // Timer2 counter
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
#define SYSCLK 24500000 / 8 // SYSCLK frequency in Hz
#define LED P2_bit.P22 // LED='1' means ON
#define SW2 P2_bit.P0 // SW2='0' means switch pressed
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init (void);
void PORT_Init (void);
void Timer2_Init (int counts);
__interrupt void Timer2_ISR (void);
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void) {
// disable watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer
// enable)
SYSCLK_Init (); // Initialize system clock to
// 24.5MHz
PORT_Init (); // Initialize crossbar and GPIO
while (1) {
if (!P2_bit.P20) {P2_bit.P22&=0x01;} else {P2_bit.P22==0x00;};
if (!P2_bit.P21) {P2_bit.P23&=0x01;} else {P2_bit.P23==0x00;};// код мигания
}
}
//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal 24.5MHz / 8
// oscillator as its clock source. Also enables missing clock detector reset.
//
void SYSCLK_Init (void)
{
OSCICN = 0x80; // configure internal oscillator for
// its lowest frequency
RSTSRC = 0x08; // enable missing clock detector
}
void PORT_Init (void)
{
XBR0 = 0x00;
XBR1 = 0x40;
P2 &= 0x03; // настраиваем пины 0 и 1 на вход
P2MDOUT |= 0x0C; // обозначаем выход для пинов на которых диоды
P2_bit.P22&=0x00; //гасим загорающиеся диоды
P2_bit.P23&=0x00; //гасим загорающиеся диоды
}
#include <ioC8051f320.h> // SFR declarations
#include <intrinsics.h>
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F32x
//-----------------------------------------------------------------------------
__sfr __no_init volatile unsigned short TMR2RL @ 0xCA; // Timer2 reload value
__sfr __no_init volatile unsigned short TMR2 @ 0xCC; // Timer2 counter
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
#define SYSCLK 24500000 / 8 // SYSCLK frequency in Hz
#define LED P2_bit.P22 // LED='1' means ON
#define SW2 P2_bit.P0 // SW2='0' means switch pressed
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init (void);
void PORT_Init (void);
void Timer2_Init (int counts);
__interrupt void Timer2_ISR (void);
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void) {
// disable watchdog timer
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer
// enable)
SYSCLK_Init (); // Initialize system clock to
// 24.5MHz
PORT_Init (); // Initialize crossbar and GPIO
while (1) {
if (!P2_bit.P20) {P2_bit.P22&=0x01;} else {P2_bit.P22==0x00;};
if (!P2_bit.P21) {P2_bit.P23&=0x01;} else {P2_bit.P23==0x00;};// код мигания
}
}
//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal 24.5MHz / 8
// oscillator as its clock source. Also enables missing clock detector reset.
//
void SYSCLK_Init (void)
{
OSCICN = 0x80; // configure internal oscillator for
// its lowest frequency
RSTSRC = 0x08; // enable missing clock detector
}
void PORT_Init (void)
{
XBR0 = 0x00;
XBR1 = 0x40;
P2 &= 0x03; // настраиваем пины 0 и 1 на вход
P2MDOUT |= 0x0C; // обозначаем выход для пинов на которых диоды
P2_bit.P22&=0x00; //гасим загорающиеся диоды
P2_bit.P23&=0x00; //гасим загорающиеся диоды
}
Однако условия не выполняются,независимо от того нажата кнопка или нет,такое ощущения что эти пины не настроились на ввод.Ошибка в коде?