📄 1302+18b20+点阵屏.lst
字号:
C51 COMPILER V8.05a 1302_18B20_点阵屏 05/24/2009 12:02:11 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE 1302_18B20_点阵屏
OBJECT MODULE PLACED IN 1302+18B20+点阵屏.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 1302+18B20+点阵屏.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*****************************************************
2 16*128 LED点阵屏 C 程序
3 ******************************************************
4 声明:
5 本程序供大家学习之用,用勿用于商业用途。尊重版权。
6
7 编写:邓椿薪
8 时间:2006年1月20日 晚
9 邮箱:love2151@xinhuanet.com
10 *******************************************************
11
12 //595连级输出数据,138行驱动。P0_1为移动速度高速/*点阵显示汉字程串口输出字符数据,
13 //P2口输出行扫描信号,P2_7输出595锁存信号。*/
14
15
16 #include <reg51.h>
17 #include<intrins.h>
18 sbit P2_7=P2^7;
19 sbit DQ =P1^2; //定义通信端口
20 #define uchar unsigned char
21 #define uint unsigned int
22 sbit T_CLK=P1^7; //DS1302引脚连接
23 sbit T_IO =P1^6;
24 sbit T_RST=P1^5;
25 sbit ACC0=ACC^0; //1bit数据存储位
26 sbit ACC7=ACC^7;
27 void DS18b20start(void);
28 void RdTemp(void);
29 void convert(void);
30 void WrByte(uchar b);
31 uchar RdByte(void);
32 void RxWait(void);
33 bit RdBit(void);
34 void TxReset(void);
35 void delay(uint t);
36 uchar tplsb,tpmsb; // 温度值低位、高位字节
37 void RTInputByte(uchar); /* 输入 1Byte */
38 uchar RTOutputByte(void); /* 输出 1Byte */
39 void W1302(uchar, uchar); // 向DS1302写入一个字节
40 uchar R1302(uchar); // 从DS1302读出一个字节
41 void Set1302(uchar *); // 写DS1302时间
42 void Read_1302(void); //读取时间
43 void DelayMs(void); // 延时
44 uchar yid,h; //YID为移动计数器,H为行段计数器。
45 uint zimuo; //字模计数器
46 uchar Flag;
47 uchar code hanzi[]; //汉字字模
48 uchar code hanzi0[67][32]; //数字0-59字模
49 uchar code ZaXiang[][32];
50 uchar BUFF[8]; //缓存
51 uchar choice,choice1;
52 uchar xdata HuanCun[224]; //动态缓存
53 void in_data(void); //调整数据
54 void rxd_data(void); //发送数据
55 void TiaoZheng(void); //调整数据
C51 COMPILER V8.05a 1302_18B20_点阵屏 05/24/2009 12:02:11 PAGE 2
56 void TiaoZheng1(void); //调整数据
57 void TiaoZheng2(void); //调整数据
58 void TiaoZheng3(void); //调整数据
59 void TiaoZheng4(void); //调整数据
60 void TiaoZheng5(void); //调整数据
61 void TiaoZheng6(void); //调整数据
62 void TiaoZheng7(void); //调整数据
63 void Large_word(void);
64 void Small_word(void);
65 void sbuf_out(); //16段扫描
66 uchar year,month,day,hour,minute,second,week,temp; //时间变量
67 float wendu;
68 uchar inittime[7]={0x00,0x37,0x13,0x18,0x09,0x04,0x08}; //初始化后设置
69 uchar Number[12]; //存储时间数据
70 unsigned code sw[16]={0x70,0x72,0x74,0x76,0x78,0x7a,0x7c,0x7e,0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6e };
-/*16行段码*/
71
72 /********************************************/
73 void main(void)
74 {
75 1 Set1302(inittime); //初始化
76 1 DelayMs();
77 1 W1302(0x8e,0x00); /* 控制命令,WP=0,写操作?*/
78 1 W1302(0x90,0xa5); //打开充电二级管 一个二级管串联一个2K电阻
79 1 while(1)
80 1 {
81 2 Small_word();
82 2 }
83 1
84 1 }
85 void Small_word(void)
86 {
87 1 uchar i,j,m,d=4;
88 1 yid=0;
89 1 zimuo=0;
90 1 DS18b20start();
91 1 DelayMs();
92 1 Read_1302();
93 1 DelayMs();
94 1 for(m=0;m<8;m++)
95 1 {
96 2 switch(choice)
97 2 {
98 3 case 0:TiaoZheng(); break;
99 3 case 1:TiaoZheng1(); break;
100 3 case 2:TiaoZheng2(); break;
101 3 case 3:TiaoZheng3(); break;
102 3 case 4:TiaoZheng4(); break;
103 3 case 5:TiaoZheng5(); break;
104 3 case 6:TiaoZheng6(); break;
105 3 case 7:TiaoZheng7(); break;
106 3 }
107 2 for(j=0;j<4;j++)
108 2 {
109 3 while(yid<16) //数据移位。
110 3 {
111 4 for(i=0;i<d;i++) //移动速度
112 4 {
113 5 sbuf_out();
114 5 }
115 4 yid++; //移动一步
116 4 }
C51 COMPILER V8.05a 1302_18B20_点阵屏 05/24/2009 12:02:11 PAGE 3
117 3 yid=0;
118 3 zimuo=zimuo+32; //后移一个字,
119 3 if(zimuo>=128)
120 3 zimuo=0;
121 3 }
122 2 choice++; if(choice==8) {Flag=1;choice=0;Large_word();}
123 2 }
124 1
125 1 }
126 void DS18b20start(void)
127 {
128 1 delay(1); // 延时1ms
129 1 convert(); // 启动温度转换,需要750ms
130 1 delay(1000); // 延时1s
131 1 RdTemp(); // 读取温度
132 1 delay(2000);
133 1
134 1 }
135 void Large_word(void)
136 {
137 1 uchar i,d=4;
138 1 yid=0;
139 1 zimuo=0;
140 1 for(i=0;i<12;i++)
141 1 {
142 2 while(yid<16) //数据移位。
143 2 {
144 3 for(i=0;i<d;i++) //移动速度
145 3 {
146 4 sbuf_out();
147 4 }
148 3 yid++; //移动一步
149 3 }
150 2 yid=0;
151 2 zimuo=zimuo+32; //后移一个字,
152 2 if(zimuo>=384)
153 2 zimuo=0;
154 2 choice1++;
155 2 if(choice1==12) {Flag=0;choice1=0;Small_word();}
156 2 }
157 1
158 1 }
159 /********************************/
160 void sbuf_out()
161 {
162 1 for(h=0;h<16;h++) //16行扫描
163 1 {
164 2 in_data(); //调整数据
165 2 rxd_data(); //串口发送数据
166 2 P2=0x7f; //关闭显示。
167 2 P2_7=1; //锁存为高,595锁存信号
168 2 P2=sw[h]; //送段码
169 2
170 2
171 2
172 2 }
173 1 }
174
175 /******************************************************/
176 void in_data(void)
177 {
178 1 char s;
C51 COMPILER V8.05a 1302_18B20_点阵屏 05/24/2009 12:02:11 PAGE 4
179 1 if(Flag==0)
180 1 for(s=3;s>=0;s--) //h为向后先择字节计数器,zimuoo为向后先字计数器
181 1 {
182 2 BUFF[2*s]=HuanCun[zimuo+32*s+2*h]; //把第一个字模的第一个字节放入BUFF0中,第二个字模和第一
-个字节放入BUFF2中
183 2 BUFF[2*s+1]=HuanCun[zimuo+1+32*s+2*h]; // 把第一个字模的第二个字节放入BUFF1中,第二个字模
-的第二个字节放入BUFF3中
184 2 }
185 1 if(Flag==1)
186 1 for(s=3;s>=0;s--) //h为向后先择字节计数器,zimuoo为向后先字计数器
187 1 {
188 2 BUFF[2*s]=hanzi[zimuo+32*s+2*h]; //把第一个字模的第一个字节放入BUFF0中,第二个字模和第一个
-字节放入BUFF2中
189 2 BUFF[2*s+1]=hanzi[zimuo+1+32*s+2*h]; // 把第一个字模的第二个字节放入BUFF1中,第二个字模的
-第二个字节放入BUFF3中
190 2 }
191 1 }
192
193 /*******************************************************/
194 void rxd_data(void) //串行发送数据
195 {
196 1 char s;
197 1 uchar inc,tempyid,temp;
198 1 if(yid<8)
199 1 inc=0;
200 1 else
201 1 inc=1;
202 1 for(s=0+inc;s<6+inc;s++) //发送8字节数据
203 1 {
204 2 if(yid<8)
205 2 tempyid=yid;
206 2 else
207 2 tempyid=yid-8;
208 2 temp=(BUFF[s]>>tempyid)|(BUFF[s+1]<<(8-tempyid)); //h1左移tempyid位后和h2右移8-tempyid相或,取出移位后
-的数据。
209 2 temp=255-temp;
210 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -