四.软件设置
4.1主函数(main.c)
//说明见工程文件夹下的Doc文件夹内Readme.txt文件
//============================================================================
#include \包含总头文件
int main(void) {
uint_8 LCDBuffer[20]; //uint_8 * g_DispalyInit;
//1.声明主函数使用的局部变量
uint_32 remember;
//2.关总中断
enter_critical(); // 进入临界区,关中断 //3.初始化底层模块
light_init(LIGHT_PORT, LIGHT_PIN_BLUE, LIGHT_OFF); //蓝灯初始化
uart_init (UART_1,BUSCLK, 9600); //串口1初始化, 总线时钟24000Khz,波特率9600
tpm_init(TPM0,TPM_CLKSRC_PLL,1000000);//1s
LCDInit(); //LCD初始化 //4.变量赋初值
g_time[0]=00; //(1) \时分秒\缓存初始化(00:00:00) g_time[1]=00; g_time[2]=00; //g_time[3]=11; // g_time[4]=51; g_time[3]=' '; g_time[4]='Z'; g_time[5]='h'; g_time[6]='a'; g_time[7]='o';
8
g_time[8]=' '; g_time[9]='Y'; g_time[10]='u'; g_time[11]='e'; g_time[12]=' '; g_time[13]=' '; g_time[14]=' ';
//g_DispalyInit = (uint_8 *)\
remember = g_time[2]; //(2) 临时变量remember初始化 //5.开中断
uart_enable_re_int(UART_1); //启动串口1接收中断 tpm_enable_int(TPM0); //启动模块中断 init_critical(); //开总中断 // LCDShow(g_DispalyInit);
//进入主循环
//主循环开始=============================================================
for(;;) {
if (g_time[2] != remember) //判断秒钟是否发生变化 {
LCDBuffer[0]=g_time[0]/10+'0'; LCDBuffer[1]=g_time[0]+'0'; LCDBuffer[2]=':';
LCDBuffer[3]=g_time[1]/10+'0'; LCDBuffer[4]=g_time[1]+'0'; LCDBuffer[5]=':';
LCDBuffer[6]=g_time[2]/10+'0'; LCDBuffer[7]=g_time[2]+'0'; LCDBuffer[8]=g_time[3]; LCDBuffer[9]=g_time[4]; LCDBuffer[10]=g_time[5]; LCDBuffer[11]=g_time[6];
9
LCDBuffer[12]=g_time[7]; LCDBuffer[13]=g_time[8]; LCDBuffer[14]=g_time[9]; LCDBuffer[15]=g_time[10]; LCDBuffer[16]='^'; LCDBuffer[17]='_'; LCDBuffer[18]='^';
uart_sendN(UART_1,11,g_time); remember=g_time[2]; LCDShow(LCDBuffer); }
} // end_while
//主循环结束============================================================= }
return 0;
4.2中断子程序(isr.c)
#include \
//========================中断函数服务例程=============================== //串口0接收中断服务例程 void isr_uart0_re(void) {
uint_8 ch; uint_8 flag = 1;
enter_critical();
ch = uart_re1(UART_0, &flag); if (0 == flag) {
uart_send1(UART_0, ch); }
exit_critical(); }
10
//串口1接收中断服务例程 void isr_uart1_re(void) {
static uint_8 index=0; //收到的个数 uint_8 flag = 1; enter_critical();
if(index>11)index=0;//三个字节一收,时分秒 g_time[index]=uart_re1(UART_1,&flag); if(0==flag) index++;
exit_critical(); }
//串口2接收中断服务例程 void isr_uart2_re(void) {
uint_8 ch; uint_8 flag = 1;
enter_critical();
ch = uart_re1(UART_2, &flag); if (0 == flag) {
uart_send1(UART_2, ch); } exit_critical(); }
//tpm定时中断 void tpm0_isr(void) {
static uint_32 TPMCounter = 0; {
TPMCounter++;
11
//定时器溢出中断标志
if((TPM_SC_REG(TPM0_BASE_PTR) & TPM_SC_TOF_MASK) == TPM_SC_TOF_MASK)
}
BSET(TPM_SC_TOF_SHIFT,TPM_SC_REG(TPM0_BASE_PTR));//清标志位 if(TPMCounter > 100) //TPM每中断100次(即1s)闪烁一次。 { } }
TPMCounter = 0; SecAdd1(g_time);
4.3LCD子程序(lcd.c)
//=========================================================================== // 文件名称:lcd.c // 功能概要:lcd构件头文件
// 版权所有: 苏州大学飞思卡尔嵌入式中心(sumcu.suda.edu.cn) // 版本更新: 2013-03-17 V1.2
//=========================================================================== #include \
//lcd控制位和数据位端口及引脚号 struct GPIO LCD[11]= { };
//内部函数原型说明
extern void LCDCommand(uint_8 cmd);
//===========================================================================
12
{LCD_RS_PORT,LCD_RS}, {LCD_RW_PORT,LCD_RW}, {LCD_E_PORT,LCD_E}, {LCD_D0_PORT,LCD_D0}, {LCD_D1_PORT,LCD_D1}, {LCD_D2_PORT,LCD_D2}, {LCD_D3_PORT,LCD_D3}, {LCD_D4_PORT,LCD_D4}, {LCD_D5_PORT,LCD_D5}, {LCD_D6_PORT,LCD_D6}, {LCD_D7_PORT,LCD_D7},