我是一个普通的本科学生,主专业是通信工程
这个学科学了DSP芯片的原理与开发应用这门课
学起来还是比较吃力的
老师布置了一个设计数字时钟的作业,要求在液晶屏上显示6位的数字时钟
// 常量定义
#define LCDDELAY 1
#define LCDCMDTURNON 0x3f
#define LCDCMDTURNOFF 0x3e
#define LCDCMDSTARTLINE 0xc0
#define LCDCMDPAGE 0xb8
#define LCDCMDVERADDRESS 0x40
#define WAITSTATUS (*(unsigned int *)0x28)
// CTR扩展寄存器定义
ioport unsigned int port8000;
ioport unsigned int port8001;
ioport unsigned int port8002;
ioport unsigned int port8003;
ioport unsigned int port8004;
ioport unsigned int port8005;
ioport unsigned int port8007;
#define CTRGR port8000
#define CTRLCDCMDR port8001
#define CTRKEY port8001
#define CTRCLKEY port8002
#define CTRLCDCR port8002
#define CTRLCDLCR port8003
#define CTRLCDRCR port8004
#define CTRLA port8005
#define CTRLR port8007
void Delay(unsigned int nTime); // 延时函数
void TurnOnLCD(); // 打开显示
void LCDCLS(); // 清除屏幕显示内容
unsigned char ledkey[10][8]=
{
{0x00,0x00,0x7C,0x82,0x82,0x82,0x7C,0x00}, //0
{0x00,0x00,0x00,0x84,0xFE,0x80,0x00,0x00}, //1
{0x00,0x00,0x84,0xC2,0xA2,0x92,0x8C,0x00}, //2
{0x00,0x00,0x44,0x92,0x92,0x92,0x6C,0x00},
{0x00,0x00,0x30,0x28,0x24,0xFE,0x20,0x00},
{0x00,0x00,0x4E,0x92,0x92,0x92,0x62,0x00},
{0x00,0x00,0x7C,0x92,0x92,0x92,0x64,0x00},
{0x00,0x00,0x02,0xC2,0x32,0x0A,0x06,0x00},
{0x00,0x00,0x6C,0x92,0x92,0x92,0x6C,0x00},
{0x00,0x00,0x4C,0x92,0x92,0x92,0x7C,0x00}
};
main()
{
int i,nCount=0,nBW=0;
CTRGR=0; // 初始化ICETEK-CTR
CTRGR=0x80;
CTRGR=0;
CTRLR=0; // 关闭东西方向的交通灯
CTRLR=0x40; // 关闭南北方向的交通灯
TurnOnLCD(); // 打开显示
LCDCLS(); // 清除显示内存
CTRLCDCMDR=LCDCMDSTARTLINE; // 设置显示起始行
CTRLCDCR=0;
for (;;)
{
CTRLCDCMDR=LCDCMDPAGE; // 设置操作页=0
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
CTRLCDCMDR=LCDCMDVERADDRESS; // 起始列=0
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
for ( i=0;i<8;i++ )
{
CTRLCDLCR=( nBW==0 )?(ledkey[nCount][i]):(~ledkey[nCount][i]); // 屏幕左侧第1至8行第i列赋值 port8002=0; // (赋值后当前操作列自动加1,所以不需设置)
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
}
Delay(512);
nCount++;
if ( nCount==10 )
{
nCount=0;
nBW=1-nBW;
}
}
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
void TurnOnLCD()
{
CTRLCDCMDR=LCDCMDTURNON;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
CTRLCDCMDR=LCDCMDSTARTLINE;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
}
void LCDCLS()
{
int i,j;
CTRLCDCMDR=LCDCMDSTARTLINE;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
for ( i=0;i<8;i++ )
{
CTRLCDCMDR=LCDCMDPAGE+i;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
CTRLCDCMDR=LCDCMDVERADDRESS;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
for ( j=0;j<64;j++ )
{
CTRLCDLCR=0;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
}
CTRLCDCMDR=LCDCMDPAGE+i;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
CTRLCDCMDR=LCDCMDVERADDRESS;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
for ( j=0;j<64;j++ )
{
CTRLCDRCR=0;
Delay(LCDDELAY);
CTRLCDCR=0;
Delay(LCDDELAY);
}
}
}
以上是LCD的显示程序
然后是计时的程序
#define TIM *(int *)0x24
#define PRD *(int *)0x25
#define TCR *(int *)0x26
#define IMR *(int *)0x0
#define IFR *(int *)0x1
#define PMST *(int *)0x1d
ioport unsigned int port3002,port3003;
#define DIP port3003
#define LED port3002
void interrupt time(void);
unsigned int nCount,uWork;
main()
{
nCount=uWork=0;
asm(" ssbx INTM"); // 关中断,进行关键设置时不许打扰
// 设置通用定时器
uWork=PMST; // 设置PMST寄存器
PMST =uWork&0xff; // 中断向量表起始地址=80H
IMR = 0x8; // 使能TINT
TCR = 0x41F; // 预分频系数为8
TIM = 0; // 时钟计数器清0
PRD = 0x0f423; // 周期寄存器为0f423H
TCR = 0x42f; // 复位、启动
IFR = 0x100; // 清中断标志位
asm(" rsbx INTM"); // 开中断
LED=0xff;
while ( 1 )
{
}
}
void interrupt time(void)
{
nCount++;
if ( nCount>=4 )
{
LED^=0x55; // 设置指示灯状态
nCount=0;
}
}
不知道怎么让着两个结合起来,在液晶屏上显示数字时钟,我是小白
期待高手解答!! |