#include <string.h>
#include "mmu.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "def.h"
#include "option.h"
#include "timer.h"
#define LED_OPEN1 ~(1<<5)
#define LED_OPEN2 ~(1<<6)
#define LED_OPEN3 ~(1<<7)
#define LED_CLOSE1 (1<<5)
#define LED_CLOSE2 (1<<6)
#define LED_CLOSE3 (1<<7)
int flag = 1;
static void __irq time_handler(void);
void led_run(void);
void dely(int);
//led init
void led_init(void)
{
rGPGCON &= ~((3<<10) | (3<<12) | (3<<14));
rGPGCON |= (1<<10) | (1<<12) | (1<<14);
}
static void cal_cpu_bus_clk(void)
{
U8 m,p,s;
U32 val;
val = (rMPLLCON);
m = (val>>12) & 0xff;
p = (val>>4) & 0x3f;
s = (val) & 3;
SYS_FCLK = (((FIN / 100) * (8 + m) * 2) / ((p + 2) * (1 << s))) * 100;
val = rCLKDIVN;
m = (val>>1) & 0x3;
p = (val) & 0x1;
val = rCAMDIVN;
s = val>>8;
switch(m)
{
case 0:
SYS_HCLK = SYS_FCLK;
break;
case 1:
SYS_HCLK = SYS_FCLK>>1;
break;
case 2:
if(s & 2)
SYS_HCLK = SYS_FCLK >> 3;
else
SYS_HCLK = SYS_FCLK >> 2;
break;
case 3:
if(s & 1)
SYS_HCLK = SYS_FCLK / 6;
else
SYS_HCLK = SYS_FCLK / 3;
break;
default:
break;
}
if(p)
{
SYS_PCLK = SYS_HCLK >> 1;
}
else
{
SYS_PCLK = SYS_HCLK;
}
rUPLLCON = (56<<12) | (2<<4) | 2;
}
//mpll init
void set_clk(void)
{
ChangeMPllValue(92,1,1);//init rmpllcon
SetClockDivider(2,1);//init clkdivn
cal_cpu_bus_clk();
}
static void __irq time_handler(void)
{
led_run();
ClearPending(BIT_TIMER0);
}
void dely(int tt)
{
int i = 0;
int j = 0;
for(;i < tt; i++)
{
for(;j < 100000000; j++);
}
}
void led_run(void)
{
if(flag)
{
rGPGDAT |= LED_CLOSE1 | LED_CLOSE2 | LED_CLOSE3;
flag = 0;
}
else
{
rGPGDAT &= LED_OPEN1 & LED_OPEN2 & LED_OPEN3;
flag = 1;
}
}
void time_init(void)
{
U32 outf = 0;
U32 m,p,s;
rTCFG0 = 49;
rTCFG1 = 3;
m = (rTCFG0) & 0xff;
p = (rTCFG1) & 0xf;
switch(p)
{
case 0:
s = 2;
break;
case 1:
s = 4;
break;
case 2:
s = 8;
break;
case 3:
s = 16;
break;
default:
break;
}
outf = SYS_PCLK / (m + 1) / s;
//printf("m is %u,s is %u\n",m,s);
//printf("outf is %u\n",outf);
rTCNTB0 = 62500;
rTCMPB0 = 0;
printf("rTCNTB0 is %u,rTCMPB0 is %u\n",rTCNTB0,rTCMPB0);
rTCON |=(1<<1); //将计数值装入TCNTB0、TCMPB0
rTCON = 0x9;
printf("rTCON is %x\n",rTCON);
ClearPending(BIT_TIMER0);
printf("rSRCPND is %x\n",rSRCPND);
printf("rINTPND is %x\n",rINTPND);
pISR_TIMER0 = (U32) time_handler;
EnableIrq(BIT_TIMER0);
printf("rINTMSK is %x\n",rINTMSK);
}
int Main()
{
MMU_Init();
set_clk();
led_init();
time_init();
while(1);
return 0;
}
这个程序我调试了将近2天的时间,很多问题,一开始由于硬件的限制调试起来很麻烦,后来就轻松了。不过这个程序写完以后还是觉得其实就是一个中断的问题和时钟的问题,如果你能搞清楚这两个问题就ok了。。。
现在只能写这些小程序,老师竟然让我写一个视频存储程序,让我有点纠结,尽量把....