📄 main.c
字号:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include "lcd1602.h"
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
unsigned int g,s,b,q,w,sw;
unsigned int TimBuf[3];
unsigned char word1[]="Happy everyday!",word2[]="Interval(minute)";
unsigned char hour[]="00";
unsigned char min[]="00";
unsigned char sec[]="00";
unsigned char maohao[]=":";
void IO_Init()
{
DDRB=0XFF;
DDRA=0XFF;
PUCR=0X02; //PORTB Pull_up
}
void ECT_Init()
{
INTCR=0X00;
TSCR1=0x80;
TSCR2=0x07;
// TSCR2=0x00;
TIE=0x01;
TIOS=0x01;
TCTL2=0x00;
TFLG1=0x01;
TC0=0xF424;
}
void main(void)
{
IO_Init();
ECT_Init();
LCD_init();
LCD_cmd(CLR_SCREEN);
LCD_cmd(DISP_ON);
LCD_cmd(CURSOR_OFF);
//LCD_cmd(CURSOR_FLASH_OFF);
LCD_write_string(0,0,word1);
EnableInterrupts;
for(;;)
{
PORTB=~TimBuf[0];
LCD_write_string(1,0,hour);
LCD_write_string(1,2,maohao);
LCD_write_string(1,3,min);
LCD_write_string(1,5,maohao);
LCD_write_string(1,6,sec);
// LCD_write_string(1,2,maohao);
// LCD_write_string(0,2,word1);
// LCD_write_string(0,1,word1);
}
}
interrupt void ECT0_ISR()
{
TFLG1=0x01;
//秒,分,时,开始计时
TimBuf[0]++;
//PORTB=~TimBuf[0];
if(TimBuf[0]>=60)
{
TimBuf[0]=0;
TimBuf[1]++;
if(TimBuf[1]>=60)
{
TimBuf[1]=0;
TimBuf[2]++;
if(TimBuf[2]>=24)
{
TimBuf[2]=0;
}
}
}
sw=TimBuf[2]/10;
w= TimBuf[2]%10;
q=TimBuf[1]/10;
b=TimBuf[1]%10;
s=TimBuf[0]/10;
g=TimBuf[0]%10;
hour[0]=sw+0x30;
hour[1]=w+0x30;
min[0]=q+0x30;
min[1]=b+0x30;
sec[0]=s+0x30;
sec[1]=g+0x30;
//sec[0]=s+0x30;
//sec[1]=g+0x30;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -