本帖最后由 dengxm2009 于 2015-9-5 22:45 编辑
/************************************************************************************/
// ?????????·????
#include "c8051f020.h" // SFR declarations
#include <stdio.h>
#include <string.h>
#include ".\init\init.h"
#include ".\io_ToUart\SimUart.h"
#include ".\general\general.h"
/************************************************************************************/
/************************************************************************************
// ?????°????±????¨??
*************************************************************************************/
/************************************************************************************
// ×??????ù?÷
*************************************************************************************/
void EMI_Init()
{
EMI0CF = 0x0F;
}
void Port_IO_Init()
{
P1MDOUT = 0x14;
XBR2 = 0xC2;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x0C;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
// EMI_Init();
Port_IO_Init();
Oscillator_Init();
}
/************************************************************************************
// ?÷???·???ò
*************************************************************************************/
void main (void) {
unsigned int data i;
unsigned long j;
unsigned int k;
unsigned char xdata *x;
unsigned char xdata temp;
char data et;
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;
Init_Device();
Init_sim_uart1(18432000,9600);
SimUart1_WriteString("SRAM_rw_test program running!\r\n",strlen("SRAM_rw_test program running!\r\n"));
k=0;
i=0;
x=0x0000;
for(j=0;j<32767;j++)
{
et=*x;
i=j%256;
*x=i; //i=0~255
temp=*x;
if(temp!=i)
{
k++;
}
x++;
}
if (k==0)
SimUart1_WriteString("External SRAM read&write test succeed!\r\n",strlen("External SRAM read&write test succeed!\r\n"));
else
SimUart1_WriteString("External SRAM read&write test fail!\r\n",strlen("External SRAM read&write test fail!\r\n"));
while(1);
}
加上EMI初始化
默认优化选项8 程序可以运行,但是不正常,
Init_sim_uart1(18432000,9600);这句的参数无法传到这个子程序里面。
编译选项选择0,程序运行到晶振初始化
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
这句卡死。
外接573,62256集成块。数据地址复用。EMI初始化不知正确不正确?
EMI0CF = 0x0F;
转载
|