📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 10/18/2006 12:12:58 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE MAIN.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <AT89X52.H>
2 #include <stdio.h>
3 #include <absacc.h>
4 unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,
5 0x6d,0x7d,0x07, 0x7f,0x6f,};
6 unsigned char sec; //定义计数值,每过1秒,sec加1
7 unsigned int tcnt; //定时中断次数
8 bit write=0; //写24C08的标志;
9 sbit gewei=P1^3; //个位选通定义
10 sbit shiwei=P1^2; //十位选通定义
11 /////////24C08读写驱动程序////////////////////
12 sbit scl=P3^6; // 24c08 SCL
13 sbit sda=P3^7; // 24c08 SDA
14 void delay1(unsigned char x)
15 { unsigned int i;
16 1 for(i=0;i<x;i++);
17 1 ;}
18 void flash() //延时2us
19 {
20 1 ;
21 1 ;
22 1 }
23 void x24c08_init() //24c08初始化子程序
24 {
25 1 scl=1;
26 1 flash();
27 1 sda=1;
28 1 flash();
29 1 }
30 void start() //启动I2C总线
31 {
32 1 sda=1;
33 1 flash();
34 1 scl=1;
35 1 flash();
36 1 sda=0;
37 1 flash();
38 1 scl=0;
39 1 flash();
40 1 }
41 void stop() //停止I2C总线
42 {
43 1 sda=0;
44 1 flash();
45 1 scl=1;
46 1 flash();
47 1 sda=1;
48 1 flash();
49 1 }
50 void writex(unsigned char j) //写一个字节
51 {
52 1 unsigned char i,temp;
53 1 temp=j;
54 1 for (i=0;i<8;i++)
55 1 {
C51 COMPILER V7.06 MAIN 10/18/2006 12:12:58 PAGE 2
56 2 temp=temp<<1;
57 2 scl=0;
58 2 lash();
*** WARNING C206 IN LINE 58 OF MAIN.C: 'lash': missing function-prototype
59 2 sda=CY;
60 2 flash();
61 2 scl=1;
62 2 flash();
63 2 }
64 1 scl=0;
65 1 lash();
66 1 sda=1;
67 1 flash();
68 1 }
69 unsigned char readx() //读一个字节
70 {
71 1 unsigned char i,j,k=0;
72 1 scl=0;
73 1 flash();
74 1 sda=1;
75 1 for (i=0;i<8;i++)
76 1 {
77 2 flash();
78 2 scl=1;
79 2 flash();
80 2 if (sda==1) j=1;
81 2 else j=0;
82 2 k=(k<<1)|j;
83 2 scl=0;
84 2 }
85 1 flash();
86 1 return(k);
87 1 }
88 void clock() // I2C总线时钟
89 {
90 1 unsigned char i=0;
91 1 scl=1;
92 1 flash();
93 1 while ((sda==1)&&(i<255))i++;
94 1 scl=0;
95 1 flash();
96 1 }
97 ////////从24c02的地址address中读取一个字节数据/////
98 unsigned char x24c08_read(unsigned char address)
99 {
100 1 unsigned char i;
101 1 start();
102 1 writex(0xa0);
103 1 clock();
104 1 writex(address);
105 1 clock();
106 1 start();
107 1 writex(0xa1);
108 1 clock();
109 1 i=readx();
110 1 stop();
111 1 delay1(10);
112 1 return(i);
113 1 }
114 //////向24c02的address地址中写入一字节数据info/////
115 void x24c08_write(unsigned char address,unsigned char info)
116 {
C51 COMPILER V7.06 MAIN 10/18/2006 12:12:58 PAGE 3
117 1 EA=0;
118 1 start();
119 1 writex(0xa0);
120 1 clock();
121 1 writex(address);
122 1 clock();
123 1 writex(info);
124 1 clock();
125 1 stop();
126 1 EA=1;
127 1 delay1(50);
128 1 }
129 /////////////24C08读写驱动程序完/////////////////////
130 void Delay(unsigned int tc) //延时程序
131 {
132 1 while( tc != 0 )
133 1 {unsigned int i;
134 2 for(i=0; i<100; i++);
135 2 tc--;}
136 1 }
137 void LED() //LED显示函数
138 {
139 1 shiwei=0;
140 1 P0=table[sec/10];
141 1 Delay(8);
142 1 shiwei=1;
143 1 gewei=0;
144 1 P0=table[sec%10];
145 1 Delay(5);
146 1 gewei=1;
147 1 }
148 void t0(void) interrupt 1 using 0 //定时中断服务函数
149 {
150 1 TH0=(65536-50000)/256; //对TH0 TL0赋值
151 1 TL0=(65536-50000)%256; //重装计数初值
152 1 tcnt++; //每过250ust tcnt加一
153 1 if(tcnt==20) //计满20次(1秒)时
154 1 {
155 2 tcnt=0; //重新再计
156 2 sec++;
157 2 write=1; //1秒写一次24C08
158 2 if(sec==100) //定时100秒,在从零开始计时
159 2 {sec=0;}
160 2 }
161 1 }
162 void main(void)
163 {
164 1 TMOD=0x01; //定时器工作在方式1
165 1 ET0=1;
166 1 EA=1;
167 1 x24c08_init(); //初始化24C08
168 1 sec=x24c08_read(2);//读出保存的数据赋于sec
169 1 TH0=(65536-50000)/256; //对TH0 TL0赋值
170 1 TL0=(65536-50000)%256; //使定时器0.05秒中断一次
171 1 TR0=1; //开始计时
172 1 while(1)
173 1 {
174 2 LED();
175 2 if(write==1) //判断计时器是否计时一秒
176 2 {
177 3 write=0; //清零
178 3 x24c08_write(2,sec); //在24c08的地址2中写入数据sec
C51 COMPILER V7.06 MAIN 10/18/2006 12:12:58 PAGE 4
179 3 }
180 2 }
181 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 420 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 7
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -