安徽财贸职业学院
#include \#include \#include %unsigned char gettimebuf[7]; unsigned char settimebuf[7];
unsigned char time1[]={\ : : %unsigned char date[]={\ - - \sbit KS1 = P0^0; sbit KS2 = P0^1; sbit KS3 = P3^7;
//*********************************** #define
delay_time 25767
unsigned char t[4]; unsigned char x[2]; void delay(unsigned int x) { }
void shijian(void)
{ds1302int(0x10,0x10,0x5,0x15,0x49,0x01); LCD_init(); LCD_clear(); while(1)
-4-
unsigned int y,z; for(y=0;y
{
gettimebuf[0]=read_1302 (0x81); time1[6]=(gettimebuf[0])/16+48; time1[7]=(gettimebuf[0])+48; delay(50);
gettimebuf[1]=read_1302 (0x83); time1[3]=(gettimebuf[1])/16+48; time1[4]=(gettimebuf[1])+48; delay(50);
安徽财贸职业学院
}
}
gettimebuf[2]=read_1302 (0x85); time1[0]=(gettimebuf[2])/16+48; time1[1]=(gettimebuf[2])+48; LCD_write_english_string(0,1,time1+0);
delay(50); delay(50);
gettimebuf[3]=read_1302 (0x87); LCD_write_english_string(6,1,time1+1);
date[8]=(gettimebuf[3])/16+48; date[9]=(gettimebuf[3])+48; gettimebuf[4]=read_1302 (0x89); date[5]=(gettimebuf[4])/16+48; date[6]=(gettimebuf[4])+48; gettimebuf[5]=read_1302 (0x8d); date[2]=(gettimebuf[5])/16+48; date[3]=(gettimebuf[5])+48; LCD_write_english_string(0,0,date+0);
delay(50);
LCD_write_english_string(6,0,date+1); delay(50);
void hanzi(void)
{ LCD_write_chinese_string(0,2,12,3,0,1); }
void main(void) {
unsigned int i;
LCD_init(); //初始化液晶 LCD_clear(); BELL=0;
LCD_write_chinese_string(1,4,12,6,3,2);
chinese_string(0, 0, 30000);
-5-
安徽财贸职业学院
}
LCD_LED=1; while(1) { }
P0=0xff;KS3=1; KS1=0; i=P0; switch(i) { }
case 0xfa:delay(100);if(i==0xfa){LCD_clear();hanzi();}break; case 0xf6:delay(100);if(i==0xf6){LCD_clear();shijian();}break; case default:break;
0xee:delay(100);if(i==0xee){LCD_clear();LCD_draw_bmp_pixel(0,0,bmp,84,48);}break;
delay(100);
2.2 Nokia5110头文件:
#include \#include \#include \#include \
/*----------------------------------------------------------------------- LCD_init : 3310LCD初始化 编写日期 :2009-5-1 最后修改日期 :2009-5-1
-----------------------------------------------------------------------*/ void delay_1us(void) //1us延时函数 {
unsigned int i; for(i=0;i<1000;i++);
-6-
安徽财贸职业学院
}
void delay_1ms(void) //1ms延时函数 {
unsigned int i; for (i=0;i<1140;i++); }
void delay_nms(unsigned int n) //N ms延时函数 {
unsigned int i=0; for (i=0;i void LCD_init(void) { // 产生一个让LCD复位的低电平脉冲 LCD_RST = 0; delay_1us(); LCD_RST = 1; // 关闭LCD LCD_CE = 0; delay_1us(); // 使能LCD LCD_CE = 1; delay_1us(); LCD_write_byte(0x21, 0); LCD_write_byte(0xc8, 0); LCD_write_byte(0x06, 0); LCD_write_byte(0x13, 0); LCD_write_byte(0x20, 0); // 使用扩展命令设置LCD模式 // 设置偏置电压 // 温度校正 // 1:48 // 使用基本命令 -7- 安徽财贸职业学院 LCD_clear(); // 清屏 // 设定显示模式,正常显示 LCD_write_byte(0x0c, 0); // 关闭LCD LCD_CE = 0; } /*----------------------------------------------------------------------- LCD_clear : LCD清屏函数 编写日期 :2009-5-1 最后修改日期 :2009-5-1 -----------------------------------------------------------------------*/ void LCD_clear(void) { unsigned int i; LCD_write_byte(0x0c, 0); LCD_write_byte(0x80, 0); for (i=0; i<504; i++) LCD_write_byte(0, 1); } /*----------------------------------------------------------------------- LCD_set_XY : 设置LCD坐标函数 输入参数:X :0-83 Y :0-5 编写日期 :2009-5-1 最后修改日期 :2009-5-1 -----------------------------------------------------------------------*/ void LCD_set_XY(unsigned char X, unsigned char Y) { LCD_write_byte(0x40 | Y, 0); } /*----------------------------------------------------------------------- -8- // column LCD_write_byte(0x80 | X, 0); // row