/*转自本人新浪博中的记录,时间:2010-09-19 18:53:47
#include"systemInit.h"
#include<timer.h>
#define uchar unsigned char
#define uint unsigned int
uint i,j,k;
uchar temp1,temp2,temp3;
#define A_PERIPH SYSCTL_PERIPH_GPIOA
#define PA GPIO_PORTA_BASE
#define B_PERIPH SYSCTL_PERIPH_GPIOB
#define PB GPIO_PORTB_BASE
#define rs GPIO_PIN_1
#define rw GPIO_PIN_2
#define e GPIO_PIN_3
#define D_PERIPH SYSCTL_PERIPH_GPIOD
#define PD GPIO_PORTD_BASE
#define PD1 GPIO_PIN_1
#define key1 GPIOPinRead(PD,PD1)
#define G_PERIPH SYSCTL_PERIPH_GPIOG
#define PG GPIO_PORTG_BASE
#define PG5 GPIO_PIN_5
#define key2 GPIOPinRead(PG,PG5)
const uchar table[]=" shizhong dabao";
const uchar table2[]=" 00:00:00";
const uchar table3[]="0123456789";
void delay(uchar ms)//延时函数
{
SysCtlDelay(ms*(TheSysClock/3000));
}
void w_com(uchar com)//1602写指令函数
{
GPIOPinWrite(PB,rs,0x00);
GPIOPinWrite(PA,0xff,com);
GPIOPinWrite(PB,e,0xff);
delay(1);
GPIOPinWrite(PB,e,0x00);
}
void w_data(uchar dat)//1602写数据函数
{
GPIOPinWrite(PB,rs,0xff);
GPIOPinWrite(PA,0xff,dat);
GPIOPinWrite(PB,e,0xff);
delay(1);
GPIOPinWrite(PB,e,0x00);
}
void init()//初始化函数
{
w_com(0x38);
w_com(0x0c);
w_com(0x06);
w_com(0x01);
w_com(0x80);
}
void keyscan()//键盘扫描函数
{
if(key1==0x00)
{
delay(5);
while(key1==0x00);
temp2++;
if(temp2==60)
temp2=0;
j=temp2/10;
k=temp2;
w_com(0x80+0x46);
w_data(table3[j]);
w_com(0x80+0x47);
w_data(table3[k]);
}
if(key2==0x00)
{
delay(5);
while(key2==0x00);
temp3++;
if(temp3==24)
temp3=0;
j=temp3/10;
k=temp3;
w_com(0x80+0x43);
w_data(table3[j]);
w_com(0x80+0x44);
w_data(table3[k]);
}
}
int main(void)
{
jtagWait();
clockInit();
SysCtlPeriEnable(A_PERIPH);
GPIOPinTypeOut(PA,0xff);
SysCtlPeriEnable(B_PERIPH);
GPIOPinTypeOut(PB,rs);
GPIOPinTypeOut(PB,rw);
GPIOPinTypeOut(PB,e);
GPIOPinWrite(PB,rw,0x00);
SysCtlPeriEnable(D_PERIPH);
GPIOPinTypeIn(PD,PD1);
SysCtlPeriEnable(G_PERIPH);
GPIOPinTypeIn(PG,PG5);
SysCtlPeriEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER);
TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
TimerLoadSet(TIMER0_BASE,TIMER_A,6000000UL);
TimerEnable(TIMER0_BASE,TIMER_A);
IntEnable(INT_TIMER0A);
IntMasterEnable();
init();
for(i=0;i<16;i++)
{
w_data(table[i]);
}
w_com(0x80+0x40);
for(i=0;i<11;i++)
{
w_data(table2[i]);
}
while(1)
{
keyscan();
}
}
void Timer0A_ISR(void)//timero中断函数
{
unsigned long ulStatus;
ulStatus=TimerIntStatus(TIMER0_BASE,true);
TimerIntClear(TIMER0_BASE,ulStatus);
if(ulStatus & TIMER_TIMA_TIMEOUT)
{
temp1++;
if(temp1==60)
{
temp1=0;
temp2++;
if(temp2==60)
{
temp2=0;
temp3++;
if(temp3==24)
temp3=0;
j=temp3/10;
k=temp3;
w_com(0x80+0x43);
w_data(table3[j]);
w_com(0x80+0x44);
w_data(table3[k]);
}
j=temp2/10;
k=temp2;
w_com(0x80+0x46);
w_data(table3[j]);
w_com(0x80+0x47);
w_data(table3[k]);
}
j=temp1/10;
k=temp1;
w_com(0x80+0x49);
w_data(table3[j]);
w_com(0x80+0x4a);
w_data(table3[k]);
}
}