我写的程序运行很短一段时间,不知道为什么就被reset了
#include<REG51F990.H>
#include "F981_LNIT.H"
#include<stdio.h>
sbit LED1=P1^0;
sbit LED2=P1^1;
void delay_ms( int delay);
void main(void)
{
OSCILLATOR_Init ();
PORT_Init ();
tiMER0_Init ();
EA = 1;
LED1 = 0;
while(1)
{
// LED1=0;//
//// LED2=0;
//// delay_ms(500);
// delay_ms_1();
// LED1=0x01;
//// delay_ms(500);
// delay_ms_1();
}
}
//-----------------------------------------------------------------------------
// delay_ms
//-----------------------------------------------------------------------------
//
// ÑÓ³ÙxxxxºÁÃ루һ°ãÓÃÓÚ³ÌÐò³õʼ»¯ÖУ©
//
//-----------------------------------------------------------------------------
void delay_ms( int delay)
{
int i;
int j;
for(i=0;i<delay;i++)
// for(j=0;j<6000;j++); //delay 1ms
for(j=0;j<1220;j++); //delay 1ms
}
void OSCILLATOR_Init (void)
{
REG0CN |= 0x10; // Enable the precision osc. bias
OSCICN |= 0x80; // Enable the precision internal osc.
// RSTSRC = 0x06; // Enable missing clock detector and
// leave VDD Monitor enabled.
RSTSRC = 0x00;
CLKSEL = 0x30; // Select precision internal osc.
// divided by 8 as the system clock
PCA0MD &= 0xDF; //disable watchdog timer
}
void PORT_Init (void)
{
// Configure TouchSense switch
P0MDIN &= ~0x08; // P0.3 is analog
P0MDOUT &= ~0x08; // P0.3 is open-drain
P0 |= 0x08; // P0.3 latch -> '1'
// Configure Hardware Switch
P0MDIN |= 0x04; // P0.2 is digital
P0MDOUT &= ~0x04; // P0.2 is open-drain
P0 |= 0x04; // Set P0.2 latch -> '1'
// // Configure LEDs
// P0MDIN |= 0x03; // P0.0, P0.1 are digital
// P0MDOUT |= 0x03; // P0.0, P0.1 are push-pull
// Configure LEDs
P1MDIN |= 0x03; // P0.0, P0.1 are digital
P1MDOUT |= 0x03; // P0.0, P0.1 are push-pull
// Configure UART
P0MDOUT |= 0x10; // Enable UTX as push-pull output
// Configure Crossbar
P0SKIP |= 0x01; // Skip P0.0, Enable PCA output on P0.1
XBR0 = 0x01; // Enable UART on P0.4(TX) and P0.5(RX)
XBR2 = 0x40; // Enable crossbar and weak pull-ups
}
一周热门 更多>