📄 1302.c
字号:
/*==============================================================================
当前位置写字符子程序: E =1 RS=1 RW=0 写数据
==============================================================================*/
void LcdWriteData( char dataW )
{
WaitForEnable(); // 检测忙信号
RS = 1; RW = 0; _nop_();_nop_();
DataPort = dataW; _nop_();_nop_();
Elcd = 1; _nop_();_nop_(); Elcd = 0; // 操作允许脉冲信号
}
/*==============================================================================
正常读写操作之前必须检测LCD控制器状态: E=1 RS=0 RW=1
DB7: 0 LCD控制器空闲; 1 LCD控制器忙
==============================================================================*/
void WaitForEnable( void )
{
DataPort = 0xff;
RS =0; RW = 1; _nop_();
Elcd = 1; _nop_();_nop_();
while( DataPort & Busy );
Elcd = 0;
}
/*==============================================================================
显示屏清屏
==============================================================================*/
void LcdClear(void )
{
LcdWriteCommand(0x01,1);
}
/*==============================================================================
开机画面
==============================================================================*/
void LCD_LOGO(void )
{
code char exampl001[] = " BeiJing Vossel ";
code char exampl002[] = "VS1302 Test/Demo";
ePutstr(0,0,exampl001);
ePutstr(0,1,exampl002);
Delay400ms();
}
// =★=★=★=★=★=★=★=★=★=★=★= 4*4按键扫描程序 =★=★=★=★=★=★=★=★=★=★=★=
// P1口为4*4键盘
// =★=★=★=★=★= 按键扫描程序 =★=★=★=★=★=
uchar kbscan(void )
{
uchar sccode,recode;
P1 = 0xf0; //发全0行扫描码,列线输入
if((P1 & 0xf0) != 0xf0) //确定是否有键按下
{
Delay10ms(); //延时去抖
if((P1 & 0xf0) != 0xf0) //再次判断是否为误动作
{
sccode = 0xfe; //逐行扫描初值
while((sccode & 0x10) !=0 )
{
P1=sccode; //输出行扫描码
if((P1 & 0xf0) != 0xf0) //确定本行有键按下
{
recode=(P1 & 0xf0) | 0x0f;
return((~sccode)+(~recode)); //返回特征字节码
}
else
sccode=(sccode<<1) | 0x01; //行扫描码左移一位
}
}
}
return(0); //无按键按下,返回值为0
}
// =★=★=★=★=★= 返回标准键码 =★=★=★=★=★=
uchar GetKeyMa(key )
{
switch(key )
{
case 0x48: // ★ 0
{
return(0x30); // 返回标准 ASCII 码
} break;
case 0x21: // ★ 1
{
return(0x31);
} break;
case 0x41: // ★ 2
{
return(0x32);
} break;
case 0x81: // ★ 3
{
return(0x33);
} break;
case 0x22: // ★ 4
{
return(0x34);
} break;
case 0x42: // ★ 5
{
return(0x35);
} break;
case 0x82: // ★ 6
{
return(0x36);
} break;
case 0x24: // ★ 7
{
return(0x37);
} break;
case 0x44: // ★ 8
{
return(0x38);
} break;
case 0x84: // ★ 9
{
return(0x39);
} break;
case 0x88: // ★ Confirm
{
return(0x88);
} break;
case 0x28: // ★ Cancel
{
return(0x99);
} break;
default:
break;
}
}
// =★=★=★=★=★= 闪光演示 =★=★=★=★=★=
void LED(void)
{
Test_PASS = LED_OFF;
Test_FAIL = LED_ONN;
Delay200ms();
Test_PASS = LED_ONN;
Test_FAIL = LED_OFF;
Delay200ms();
Test_PASS = LED_OFF;
Test_FAIL = LED_ONN;
Delay200ms();
Test_PASS = LED_ONN;
Test_FAIL = LED_OFF;
Delay200ms();
}
/*------------------------------------------------------------------------------
* 函数名称: DisplyDateTime
* 说 明: 日期时间轮显
* 函数功能: 读出VS1302 的日历时钟时间值,并显示
* 调 用: v_Get1302()
* 输 入: 无
* 返 回 值: 无
------------------------------------------------------------------------------*/
void DisplyDateTime(void )
{
//code char exampl10[] = " 2008-08-18 1 ";
//code char exampl11[] = " AM 18:18:18 ";
uchar Curtime[7]; // 数组变量,存储读出的时钟日历数据
uchar temp;
LcdClear(); // 清屏
for(;;)
{
v_Get1302(Curtime); // 读取当前时间日期
Delay200ms();
// 显示年-----------------------------------------------
DispOneChar(2,0,c2); // 显示 20
DispOneChar(3,0,c0);
temp = 0xf0 & Curtime[6]; // 年 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(4,0,temp );
temp = 0x0f & Curtime[6]; // 年 个位的显示
temp = temp | 0x30;
DispOneChar(5,0,temp );
DispOneChar(6,0,exampl01[0]); // 显示 -
// 显示月-----------------------------------------------
temp = 0x10 & Curtime[4]; // 月 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(7,0,temp );
temp = 0x0f & Curtime[4]; // 月 个位的显示
temp = temp | 0x30;
DispOneChar(8,0,temp );
DispOneChar(9,0,exampl01[0]); // 显示 -
// 显示日-----------------------------------------------
temp = 0x30 & Curtime[3]; //日 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(10,0,temp );
temp = 0x0f & Curtime[3]; //日 个位的显示
temp = temp | 0x30;
DispOneChar(11,0,temp );
// 显示星期---------------------------------------------
temp = 0x07 & Curtime[5]; // 星期 个位的显示
temp = temp | 0x30;
DispOneChar(13,0,temp );
// 显示时:首先判断时间格式 12/24-----------------------
switch(0x80 & Curtime[2])
{
case 0x00: // 24 小时制
{
temp = 0x30 & Curtime[2]; // 时 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(5,1,temp );
temp = 0x0f & Curtime[2]; // 时 个位的显示
temp = temp | 0x30;
DispOneChar(6,1,temp );
} break;
case 0x80: // 12 小时制
{
if((0x20 & Curtime[2]) == 0x20) // AM 12小时制 上午
{
DispOneChar(2,1,cA ); // 显示 AM
DispOneChar(3,1,cM );
}
else if((0x20 & Curtime[2]) == 0x00) // PM 12小时制 下午
{
DispOneChar(2,1,cP ); // 显示 PM
DispOneChar(3,1,cM );
}
temp = 0x10 & Curtime[2]; // 时 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(5,1,temp );
temp = 0x0f & Curtime[2]; // 时 个位的显示
temp = temp | 0x30;
DispOneChar(6,1,temp );
} break;
}
DispOneChar(7,1,exampl02[0]); // 显示 :
// 显示分-----------------------------------------------
temp = 0x70 & Curtime[1]; // 分 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(8,1,temp );
temp = 0x0f & Curtime[1]; // 分 个位的显示
temp = temp | 0x30;
DispOneChar(9,1,temp );
DispOneChar(10,1,exampl02[0]); // 显示 :
// 显示秒-----------------------------------------------
temp = 0x70 & Curtime[0]; // 秒 十位的显示
temp = (temp >> 4) | 0x30;
DispOneChar(11,1,temp );
temp = 0x0f & Curtime[0]; // 秒 个位的显示
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -