#include <lpc210x.h>
#define FOSC 10000000
#define FCCLK 40000000 //FOSC*4
#define FCCO FCCLK*4
#define FPCLK (FCCLK/4) //10MHZ so if time = 20ms ,T = 1/10MHZ = 0.1us, mr1 = 20/0.1us so 200000
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<100;j++);
}
}
const unsigned char swg_num[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Init_pll()
{
PLLCON = 0x1;
VPBDIV = 0x0;
PLLCFG = ((FCCLK/FOSC)-1)|(0x2<<5);
PLLFEED = 0XAA;
PLLFEED = 0X55;
while((PLLSTAT&0x1<<10)==0)
{
}
PLLCON |= 0x2;
PLLFEED = 0XAA;
PLLFEED = 0X55;
}
void Set_num(int n)
{
int i = 0;
int tem,wei;
tem = n;
do
{
wei = tem%10;
tem = tem/10;
IOSET = 0xff;
IOCLR = swg_num[wei];
IOCLR = 0xf<<8;
IOSET = 0x1<<(8+i);
delay(1000);
i++;
}while(tem!=0) ;
}
int count = 1111;
int flag = 0;
int flag1 = 0;
/*__irq void Int_isr2(void)
{
count++;
if(count == 2000)
{
count = 0;
}
Set_num(count);
delay(500);
IOCLR = 0xff;
VICVectAddr = 0x0;
}*/
__irq void Int_isr1(void)
{
count++;
if(count == 2000)
{
count = 0;
}
IOSET = 0xff;
/*Set_num(count);
//delay(900000);
IODIR |= 0x1<<12;
if(flag1 == 0)
{
IOSET = 0x1<<12;
flag1 = 1;
}
else
{
IOCLR = 0x1<<12;
flag1 = 0;
} */
while((EXTINT&0x1)!=0)
{
EXTINT = 0x1;
}
VICVectAddr = 0x0;
}
__irq void Int_isr(void)
{
IODIR |= 0x1<<7;
if(flag == 0)
{
IOSET = 0x1<<7;
flag = 1;
}
else
{
IOCLR = 0x1<<7;
flag = 0;
}
// while((EXTINT&0x1)!=0)
// {
// EXTINT = 0x1;
//}
T1IR = 0x1;
VICVectAddr = 0x0;
}
int main ()
{
Init_pll();
PINSEL0 &= ~0x3fff;
IODIR |= 0xfff;
PINSEL1 |=0x1;
T0TC = 0x0;
T0PR = 0x0;
T1TC = 0x0;
T1PR = 0x0; //地
T0MR0 = 100000;
T1MR1 = 200000;
T0MCR = 0x3;
T1MCR |= (0x3<<3);
IODIR &= ~(0x1<<16);
VICIntSelect = 0x0;
VICVectCntl1 = (0x1<<5)|14;
VICVectAddr1 = (unsigned long)Int_isr1;
VICVectAddr3 = (unsigned long)Int_isr;
// VICVectAddr2 = (unsigned long)Int_isr2;
// VICVectCntl2 = (0x1<<4)|4;
VICVectCntl3 = (0x1<<5)|5;
EXTPOLAR &= ~0x1;
EXTMODE &= ~0x1;
EXTINT = 0x1;
VICIntEnable |= (0x1<<14);//|(0x1<<5) |(0x1<<4)
T0TCR = 0x1;
T1TCR = 0x1;
while(1)
{
Set_num(count);
}
}
评论0