📄 lcd_clock_ds1302.lst
字号:
C51 COMPILER V7.20 LCD_CLOCK_DS1302 03/03/2008 10:13:50 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE LCD_CLOCK_DS1302
OBJECT MODULE PLACED IN Lcd_clock_DS1302.OBJ
COMPILER INVOKED BY: E:\Keil C\C51\BIN\C51.EXE Lcd_clock_DS1302.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <reg51.h>
2 #include<intrins.h>
3 #define u8 unsigned char
4 #define u16 unsigned int
5
6 #ifndef lcd_char_1602_2008_3_3
7 #define lcd_char_1602_2008_3_3
8
9
10
11 //Port Definitions**********************************************************
12 sbit lcdrs = P0^2;
13 sbit lcdrw = P0^1;
14 sbit lcden = P0^0;
15 sfr dbport = 0xa0; //P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.数据端口
16
17 //内部等待函数**************************************************************************
18 u8 lcd_wait(void)
19 {
20 1 lcdrs=0;
21 1 lcdrw=1; _nop_();
22 1 lcden=1; _nop_();
23 1 //while(dbport&0x80);//在用Proteus仿真时,注意用屏蔽此语句,在调用gotoxy()时,会进入死循环,
24 1 //可能在写该控制字时,该模块没有返回写入完备命令,即dbport&0x80==0x80
25 1 //实际硬件时打开此语句
26 1 lcden=0;
27 1 return dbport;
28 1 }
29 //向LCD写入命令或数据************************************************************
30 #define lcd_command 0 // Command
31 #define lcd_data 1 // Data
32 #define lcd_clear_screen 0x01 // 清屏
33 #define lcd_homing 0x02 // 光标返回原点
34 void lcd_write(bit style, u8 input)
35 {
36 1 lcden=0;
37 1 lcdrs=style;
38 1 lcdrw=0; _nop_();
39 1 dbport=input; _nop_();//注意顺序
40 1 lcden=1; _nop_();//注意顺序
41 1 lcden=0; _nop_();
42 1 lcd_wait();
43 1 }
44
45 //设置显示模式************************************************************
46 #define lcd_show 0x04 //显示开
47 #define lcd_hide 0x00 //显示关
48
49 #define lcd_cursor 0x02 //显示光标
50 #define lcd_no_cursor 0x00 //无光标
51
52 #define lcd_flash 0x01 //光标闪动
53 #define lcd_no_flash 0x00 //光标不闪动
54
55 void lcd_setdisplay(u8 DisplayMode)
C51 COMPILER V7.20 LCD_CLOCK_DS1302 03/03/2008 10:13:50 PAGE 2
56 {
57 1 lcd_write(lcd_command, 0x08|DisplayMode);
58 1 }
59
60 //设置输入模式************************************************************
61 #define lcd_ac_up 0x02
62 #define lcd_ac_down 0x00 // default
63
64 #define lcd_move 0x01 // 画面可平移
65 #define lcd_no_move 0x00 //default
66
67 void lcd_setinput(u8 inputmode)
68 {
69 1 lcd_write(lcd_command, 0x04|inputmode);
70 1 }
71
72 //移动光标或屏幕************************************************************
73 /*
74 #define lcd_cursor 0x02
75 #define LCD_SCREEN 0x08
76 #define LCD_LEFT 0x00
77 #define LCD_RIGHT 0x04
78 void lcd_move(u8 object, u8 direction)
79 {
80 if(object==lcd_cursor)
81 lcd_write(lcd_command,0x10|direction);
82 if(object==LCD_SCREEN)
83 lcd_write(lcd_command,0x18|direction);
84 }
85 */
86 //初始化LCD************************************************************
87 void lcd_initial()
88 {
89 1 lcden=0;
90 1 lcd_write(lcd_command,0x38); //8位数据端口,2行显示,5*7点阵
91 1 lcd_write(lcd_command,0x38);
92 1 lcd_setdisplay(lcd_show|lcd_no_cursor); //开启显示, 无光标
93 1 lcd_write(lcd_command,lcd_clear_screen); //清屏
94 1 lcd_setinput(lcd_ac_up|lcd_no_move); //AC递增, 画面不动
95 1 }
96
97 //************************************************************************
98 void gotoxy(u8 x, u8 y)
99 {
100 1 if(y==0)
101 1 lcd_write(lcd_command,0x80|x);
102 1 if(y==1)
103 1 lcd_write(lcd_command,0x80|(x-0x40));
104 1 }
105 /*void print(u8 *str)
106 {
107 while(*str!='\0')
108 {
109 lcd_write(lcd_data,*str);
110 str++;
111 }
112 }*/
113 void print(u8 *str)
114 {
115 1 while(*str!='\0')
116 1 {
117 2 lcd_write(lcd_data,*str);
C51 COMPILER V7.20 LCD_CLOCK_DS1302 03/03/2008 10:13:50 PAGE 3
118 2 str++;
119 2 }
120 1 }
121 /*
122 void LCD_LoadChar(u8 user[8], u8 place)
123 {
124 u8 i;
125 lcd_write(lcd_command,0x40|(place*8));
126 for(i=0; i<8; i++)
127 lcd_write(lcd_data,user[i]);
128 }
129 */
130 //************************************************************************
131 #endif
132
133 /**************************************************************************
134
135 THE REAL timeR DS1302 DRIVER LIB
136
137 COPYRIGHT (c) 2005 BY JJJ.
138 -- ALL RIGHTS RESERVED --
139
140 File Name: DS1302.h
141 Author: Jiang Jian Jun
142 Created: 2003/7/21
143 Modified: NO
144 Revision: 1.0
145
146 ***************************************************************************/
147 #ifndef _REAL_timeR_DS1302_2003_7_21_
148 #define _REAL_timeR_DS1302_2003_7_21_
149
150 sbit ds1302_clk = P1^1; //实时时钟时钟线引脚
151 sbit ds1302_io = P1^0; //实时时钟数据线引脚
152 sbit ds1302_rst = P1^2; //实时时钟复位线引脚
153 sbit ACC0 = ACC^0;
154 sbit ACC7 = ACC^7;
155
156 typedef struct __systemtime__
157 {
158 u8 second;
159 u8 minute;
160 u8 hour;
161 u8 week;
162 u8 day;
163 u8 month;
164 u8 year;
165 u8 datestring[9];
166 u8 timestring[9];
167 }systemtime; //定义的时间类型
168
169 #define AM(X) X
170 #define PM(X) (X+12) // 转成24小时制
171 #define ds1302_second 0x80
172 #define ds1302_minute 0x82
173 #define ds1302_hour 0x84
174 #define ds1302_week 0x8A
175 #define ds1302_day 0x86
176 #define ds1302_month 0x88
177 #define ds1302_year 0x8C
178 #define DS1302_RAM(X) (0xC0+(X)*2) //用于计算 DS1302_RAM 地址的宏
179
C51 COMPILER V7.20 LCD_CLOCK_DS1302 03/03/2008 10:13:50 PAGE 4
180 void ds1302inputbyte(u8 d) //实时时钟写入一字节(内部函数)
181 {
182 1 u8 i;
183 1 ACC = d;
184 1 for(i=8; i>0; i--)
185 1 {
186 2 ds1302_io = ACC0; //相当于汇编中的 RRC
187 2 ds1302_clk = 1;
188 2 ds1302_clk = 0;
189 2 ACC = ACC >> 1;
190 2 }
191 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -