嵌入式实验4
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include"system.h"
void delay()
{
int i=5000;
while(i)
{
i--;
}
}
int main(void)
{ int i;
char send[5];
IOWR(LCD_ON_BASE,0,1); delay(); //打开LCD电源
int min=0,sec=0,hse=0,flg=0,flg2=0,hour=0,day=1,month=1;
int led[10]={0x01,0x4f,0x12,0x06,0x4c,0x24,0x20,0x0f,0x00,0x04};
unsigned char loc[5]={0xcb,0xc8,0xc5,0x8b,0x88};
IOWR(TIMER_BASE,1,6);//启动定时器
while(1)
{ IOWR(LCD_BASE,0,0x38); delay(); //功能设置:8位,2行,5x8点阵现在要显示1行
IOWR(LCD_BASE,0,0x0c); delay(); //显示控制:打开显示,关闭光标和闪烁
IOWR(LCD_BASE,0,0x06); delay(); //方式设置:光标右移方式if(IORD(TIMER_BASE,0)&1)
{
if(++hse==2)
{
hse=0;
if((++sec&0xf)==0xa)
sec+=6;
if(sec>=0x60)
{
sec=0;
if((++min&0xf)==0xa)
min+=6;
if(min>=0x60)
{
min=0;
if((++hour&0xf)==0xa)
hour+=6;
if(hour>=0x24)
{
hour=0;
if((++day&0x0F)==0x0A)
day+=6;
if(month==1||month==3||month==5||month==7||month==8||month==0x10||month==0x12)
{
if(day>0x31)
{
day=1;
if((++month&0x0F)==0x0A)
month+=6;
}
}
else if(month==4||month==6||month==9||month==0x11)
{
if(day>0x30)
{
day=1;
if((++month&0x0F)==0x0A)
month+=6;
}
}
else if(month==2)
{
if(day>0x28)
{
day=1;
if((++month&0x0F)==0x0A)
month+=6;
}
}
if(month>0x12)
month=1;
}
}
}
send[0]=month;send[1]=day;send[2]=hour;send[3]=min;send[4]=sec;
for(i=0;i<5;i++)
{
while((IORD(UART_BASE,2)&0x40)==0); //发送准备好
IOWR(UART_BASE,1,((send[i]&0xf0)>>4)+0x30);
delay();
while((IORD(UART_BASE,2)&0x40)==0);
IOWR(UART_BASE,1,(send[i]&0x0f)+0x30);
delay();
if(i==0||i==1)
{
while((IORD(UART_BASE,2)&0x40)==0);
IOWR(UART_BASE,1,'\\');
delay(); delay();
}
if(i==2||i==3)
{
while((IORD(UART_BASE,2)&0x40)==0);
IOWR(UART_BASE,1,':');
delay(); delay();
}
}
while((IORD(UART_BASE,2)&0x40)==0);
IOWR(UART_BASE,1,'\r');//回车
delay(); delay();
}
IOWR(TIMER_BASE,0,0);
if((IORD(PIO_KEY_BASE,0)&1)==0)
if(++flg==3)
flg=0;
IOWR(LCD_BASE,0,0x80); delay(); //地址设置:AC=0
IOWR(LCD_BASE,2,'M'); delay();IOWR(LCD_BASE,2,'o');delay(); IOWR(LCD_BASE,2,'n');delay();IOWR(LCD_BASE,2,':'); delay();
IOWR(LCD_BASE,2,((month&0xf0)>>4)+0x30);delay();IOWR(LCD_BASE,2,(month&0xf)+0x 30);delay();
IOWR(LCD_BASE,2,' ');delay();IOWR(LCD_BASE,2,' ');delay();
IOWR(LCD_BASE,2,'D');
delay();IOWR(LCD_BASE,2,'a');delay();IOWR(LCD_BASE,2,'y');delay();IOWR(LCD_BASE,2, ':'); delay();
IOWR(LCD_BASE,2,((day&0xf0)>>4)+0x30);
delay();IOWR(LCD_BASE,2,(day&0xf)+0x30);delay();
IOWR(LCD_BASE,0,0xc0); delay(); //地址设置:AC=4F
IOWR(LCD_BASE,2,((hour&0xf0)>>4)+0x30);delay();IOWR(LCD_BASE,2,(hour&0xf)+0x30); delay();IOWR(LCD_BASE,2,':'); delay();
IOWR(LCD_BASE,2,((min&0xf0)>>4)+0x30);delay();
IOWR(LCD_BASE,2,(min&0xf)+0x30);delay(); IOWR(LCD_BASE,2,':'); delay();
IOWR(LCD_BASE,2,((sec&0xf0)>>4)+0x30);delay();IOWR(LCD_BASE,2,(sec&0xf)+0x30); delay();