本人刚开始学习单片机,使用的是N79E815AS28单片机,根据N79E81x_Sample_Code_V1.0.2里面的代码做了一个简单的程序,但是发现如果延时超过6毫秒就会死机,串口没有东西输出,以下是全部代码,中文注释里面有具体说明,请各位大神帮看一下是什么原因导致的。
#include <stdio.h>
#include "Include/N79E81x.h"
#include "Include/Typedef.h"
#include "Include/Define.h"
#include "Include/Delay.h"
#define Uart_Port_Sel 0x00
#define FOSC_221184
#ifdef FOSC_110592
#define VALUE_10us 65536-9 //27*12/11.0592 = 10 us
#define VALUE_1ms 65536-923 //2769*12/11.0592 = 1 ms
#endif
#ifdef FOSC_184320
#define VALUE_10us 65536-15 //15*12/18.432 = 10 us
#define VALUE_1ms 65536-1536 //1536*12/18.432 = 1 ms
#endif
#ifdef FOSC_221184
#define VALUE_10us 65536-18 //18*12/22.1184 = 10 us
#define VALUE_1ms 65536-1843 //1843*12/22.1184 = 1 ms
#endif
#ifdef FOSC_368640
#define VALUE_10us 65536-93 //93*12/36.864 = 10 us
#define VALUE_1ms 65536-3072 //3072*12/36.864 = 1 ms
#endif
//-------------------------------------------------------------------------
void Delay10us(UINT16 u16CNT)
{
TR0 = 1;
while (u16CNT != 0)
{
TL0 = LOBYTE(VALUE_10us);
TH0 = HIBYTE(VALUE_10us);
while (TF0 != 1);
TF0 = 0;
u16CNT --;
}
TR0 = 0;
}
//------------------------------------------------------------------------------
void Delay1ms(UINT32 u32CNT)
{
TR0 = 1;
while (u32CNT != 0)
{
TL0 = LOBYTE(VALUE_1ms);
TH0 = HIBYTE(VALUE_1ms);
while (TF0 != 1);
TF0 = 0;
u32CNT --;
}
TR0 = 0;
}
// Use timer1 as baud rate generator
void InitialUART0_Timer1(UINT32 u32Baudrate)
{
SCON = 0x52;
TMOD = 0x20;
#ifdef FOSC_110592
TH1 = 256 - (28800/u32Baudrate); /* 11.059M/384=28800 */
#endif
#ifdef FOSC_184320
TH1 = 256 - (48000/u32Baudrate); /* 18.4320M/384=48000 */
#endif
#ifdef FOSC_221184
TH1 = 256 - (57600/u32Baudrate); /* 22.1184M/384=57600 */
#endif
#ifdef FOSC_331776
TH1 = 256 - (86400/u32Baudrate); /* 33.1776M/384=86400 */
#endif
#ifdef FOSC_368640
TH1 = 256 - (96000/u32Baudrate); /* 36.8640M/384=96000 */
#endif
TR1 = 1;
}
void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
{
printf("delay x=%d\n",x); //如果不注释这句,delay(30)都不会死机,注释掉后就是传过来的参数大于4就会卡死
for(y=125;y>0;y--)
{
}
}
}
void main(void)
{
AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
InitialUART0_Timer1(9600); // 9600 Baud Rate @ 11.0592MHz
ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
printf ("Name: N79E84x Series UART Sample Code.\n"); //注释这句后,后面的AAAA都没有输出来,单片机死了吗?
while(1)
{
printf("AAAA\n");
//Delay1ms(5); //传过去的参数大于6就会卡死
delay(30); //传过去的参数大于4就会卡死
}
}
void UART_ISR(void) interrupt 4
{
if(RI == 1)
RI = 0;
else
TI = 0;
}
|