基于ARM7 TDMI-S CPU的LPC2103的多功能电子钟
if(GPIO_READ(7)==0)
{
//启动 输出开启的闹钟信息
printf("RTC ----%02d -%02d -%02d _ %02d : %02d : %02d WEEK=%d-- \n",nian,yue,ri,shi,fen,miao,week);
for(al_num=0;al_num<4;al_num++)
{
if(al_on3off[al_num]==1)
{
printf("The number%d alarm is on.---Alarm time--%d : %d --\n",al_num,al_shi[al_num],al_fen[al_num]);
}
}
}
}
UINT8 GetKey()
{keyreturn=0;
key4=GPIO_READ(18)| (GPIO_READ(15)<1)|(GPIO_READ(14)<2)|(GPIO_READ(16)<3)|(GPIO_READ(2)<4)|(GPIO_READ(3)<5)|(GPIO_READ(4)<6)|(GPIO_READ(27)<7)|(GPIO_READ(6)<8)|(GPIO_READ(7)<9);
switch (keystate)
{
case 0:
if(key4!=1023) //检测到有按键,转到状态1,相当于是消抖过程
{
keystate=1;
}
break;
case 1:
if(key4!=1023) //再次检测到有按键,确认按键按下,返回一个值,并转到状态2
{
keyreturn=1;
keystate=2;
}
else
{
keystate=0; //没有检测到按键,说明状态0检测到是一个抖动,重新转到状态0
}
break;
case 2:
if(key4==1023) //检测到按键松开,状态转到状态0,一次完整的按键过程结束
{
keystate=0;
}
break;
}
return keyreturn;
}
void data_shift(UINT8 dat)
{
UINT8 i;
for(i=0; i<8; i++)
{
GPIO_SET(CLK,LOW);
if(dat & 0x01){
GPIO_SET(DATA,0);
}
else{
GPIO_SET(DATA,1);
}
GPIO_SET(CLK,HIGH);
dat >>= 1;
}
}
void Refresh_LED(UINT16 dat)
{
static UINT8 i = 0;
UINT8 a,b,c,d;
a = dat /1000;
b = dat % 1000 / 100;
c = dat % 1000 % 100 /10;
d = dat % 1000 % 100 % 10;
switch(i)
{
case 0:
i++;
GPIO_SET(DIG_EN0,LOW);
data_shift(DIGData[d]);
break;
case 1:
i++;
GPIO_SET(DIG_EN1,LOW);
data_shift(DIGData[c]);
break;
case 2:
i++;
GPIO_SET(DIG_EN2,LOW);
if(g_Dot)
data_shift(DIGData[b] & ~(0x01 < 0));
else
data_shift(DIGData[b] | (0x01 < 0));
break;
case 3:
i = 0;
GPIO_SET(DIG_EN3,LOW);
data_shift(DIGData[a]);
break;
}
}
/*********************************************************************************************************
** Function name: Timer1_ISR
** Descriptions: 定时器1中断主程序
** input parameters: 无
** ouput parameters: 无
** Returned value: 无
*********************************************************************************************************/
void __irq Timer1ISR (void)
{
T1IR = 0x01; /* 清除中断标志 */
miao++;
if(g_Dot)
g_Dot = 0;
else
g_Dot = 1;
VICVectAddr = 0x00; /* 中断向量结束 */
}
void __irq Timer2ISR (void)
{
GPIO_SET(DIG_EN0,HIGH);
GPIO_SET(DIG_EN1,HIGH);
GPIO_SET(DIG_EN2,HIGH);
GPIO_SET(DIG_EN3,HIGH);
Refresh_LED(display);
time10++;
T2IR = 0x01; /* 清除中断标志 */
VICVectAddr = 0x00; /* 中断向量结束 */
}
void Timer1Init(void)
{
T1TCR = 0x02; /* 定时器1复位 */
T1PR = 0; /* 不设时钟分频 */
T1MCR = 0x03; /* 匹配后复位TC,并产生中断 */
T1MR0 = Fpclk ; /* 设置1秒匹配值 */
T1IR = 0x01; /* 清除中断标志 */
T1TCR = 0x01; /* 启动定时器1 */
}
void timeupdate()//时间更新函数
{
if(miao>59)
{
fen++;
if(al_flag&&al_yunxu) //表示闹钟开启,bian a!!
{
for(al_num=0;al_num<4;al_num++)
{if(fen==al_fen[al_num]&&shi==al_shi[al_num]&&al_on3off[al_num]==1)
{ al_flag--;
al_on3off[al_num]=0;
if(al_flag==0)
GPIO_SET(24,1);
LS=1;
}
}
}
miao=0;
if(fen>59)
{
shi++;
fen=0;
if(shi>23)
{
ri++;
week++;
if(week>7){week=1;}
shi=0;
if(ri>yue_deal())
{
yue++;
ri=1;
if(yue>12)
{
nian++;
yue=1;
if(nian>9999)
nian=1000;
}
}
}
}
}
}
/*********************************************************************************************************
** Function name: Timer0\2Init
** Descriptions: 定时器0&2初始化
** input parameters: 无
** ouput parameters: 无
** Returned value: 无
*********************************************************************************************************/
void Timer2Init(void) //这里也初始化了T0,用于pwm输出,驱动蜂鸣器
{
PINSEL0 &= ~(3 < 10);
PINSEL0 |= (2 < 10); //P0.5 作MAT0.1输出
T0TCR=0x02; //复位
T0PR =0x00; //不预分频
T0PWMCON=0x02; //MAT0.1为PWM输出,在P0.5脚
T0MR0=Fcclk/1000;
T0MCR=0x02; //每FCLK/1000复位一次T0
T0MR1=((Fcclk/2000)/10)*10;
T2TCR = 0x02; /* 定时器2复位 */
T2PR = 0; /* 不设时钟分频 */
T2MCR = 0x03; /* 匹配后复位TC,并产生中断 */
T2MR0 = Fpclk /200; /* 设置5毫秒匹配值 */
T2IR = 0x01; /* 清除中断标志 */
T2TCR = 0x01; /* 启动定时器2 */
}
void PLL_Init(void)
{
PLLCON = 1;
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 < 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 < 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 < 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 < 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 < 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
}
ARM7TDMI-SLPC2103多功能电子 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)