📄 test7279.lst
字号:
C51 COMPILER V7.06 TEST7279 06/04/2005 15:57:16 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TEST7279
OBJECT MODULE PLACED IN test7279.OBJ
COMPILER INVOKED BY: c:\KEIL\C51\BIN\C51.exe test7279.c DB OE
stmt level source
1 #include "c8051f020.h"
2 #include <intrins.h>
3
4 sbit HD7279_DAT=P1^7;
5 sbit HD7279_CLK=P1^6;
6
7 #define NOSELECT7279 P5 |= 0x80 //SPICS4(P57)=1
8 #define SELECT7279 P5 &= ~(0x80) //SPICS4(P57)=0;
9 #define Set7279DAT HD7279_DAT=1
10 #define Clr7279DAT HD7279_DAT=0
11 #define Set7279CLK HD7279_CLK=1
12 #define Clr7279CLK HD7279_CLK=0
13
14 // HD7279测试/演示程序
15
16 // I/O口初始化
17
18 void Delay1ms(unsigned char T);
19 void Delay1s(unsigned char T);
20 void Delay1us(unsigned char T);
21 void Send7279Byte(unsigned char ch)
22 {
23 1 char i;
24 1 SELECT7279; //置CS低电平
25 1 Delay1us(50); //延时50μ
26 1
27 1 for (i=0;i<8;i++)
28 1 {
29 2 if (ch&0x80) //输出7位到HD7279A的DATA端
30 2 {
31 3 Set7279DAT;
32 3 }
33 2 else
34 2 {
35 3 Clr7279DAT;
36 3 }
37 2 Set7279CLK; //置CLK高电平
38 2 ch=ch<<1; //待发数据左移
39 2 Delay1us(8); //延时8μ
40 2 Clr7279CLK; //置CLK低电平
41 2 Delay1us(8); //延时50μ
42 2 }
43 1 Clr7279DAT; //发送完毕,DATA端置低,返回
44 1 }
45 unsigned char Receive7279Byte(void)
46 {
47 1 unsigned char i,ch;
48 1 ch=0;
49 1 Set7279DAT; //DATA端置为高电平,输入状态
50 1 Delay1us(50); //延时50μ
51 1 for (i=0;i<8;i++)
52 1 {
53 2 Set7279CLK; //置CLK高电平
54 2 Delay1us(8); //延时8μ
55 2 ch=ch<<1; //接收数据左移1位
C51 COMPILER V7.06 TEST7279 06/04/2005 15:57:16 PAGE 2
56 2 if (HD7279_DAT)
57 2 ch+=1; //接收1位数据
58 2 Clr7279CLK; //置CLK低电平
59 2 Delay1us(8); //延时8μ
60 2 }
61 1 Clr7279DAT; //接收完毕,DATA端重新置成低电平(输出状态)
62 1 return ch;
63 1 }
64
65 void FlashLED(unsigned char No)
66 {
67 1 char i;
68 1 Send7279Byte(0x88); //发闪烁指令
69 1 i=0x1;
70 1 while (No)
71 1 {
72 2 i=i<<1;
73 2 No--;
74 2 }
75 1 Send7279Byte(~i); //1闪烁
76 1 NOSELECT7279; //置CS高电平
77 1 }
78
79 /*
80 void BlankLED(unsigned char ch)
81 {
82 Send7279Byte(0x98); //发消隐指令
83 Send7279Byte(ch); //1-显示 0-消隐
84 NOSELECT7279; //置CS高电平
85 }
86 */
87
88 void MoveLeft(void)
89 {
90 1 Send7279Byte(0xA1); //发左移指令
91 1 NOSELECT7279; //置CS高电平
92 1 }
93
94 void MoveRight(void)
95 {
96 1 Send7279Byte(0xA0); //发右移指令
97 1 NOSELECT7279; //置CS高电平
98 1 }
99
100 unsigned char code BdSeg[]={
101 0x7e,0x30,0x6d,0x79, // 0 1 2 3
102 0x33,0x5b,0x5f,0x70, // 4 5 6 7
103 0x7f,0x7b,0x77,0x1f, // 8 9 a b
104 0x4e,0x3d,0x4f,0x47, // c d e f
105 0x00,0x01};
106
107 void DispLED(char *DispBuf,char ShowDot)//ShowDot 显示小数点位
108 {
109 1 char i,ch;
110 1 ShowDot--;
111 1 for (i=0;i<6;i++)
112 1 {
113 2 ch=DispBuf[i];
114 2 if ((ch>='a') && (ch<='f'))
115 2 {
116 3 ch-='a';ch+=0xa;
117 3 }
C51 COMPILER V7.06 TEST7279 06/04/2005 15:57:16 PAGE 3
118 2 if ((ch>='A') && (ch<='F'))
119 2 {
120 3 ch-='A';ch+=0xa;
121 3 }
122 2 Send7279Byte(0x90+5-i); //不译码
123 2 if (ch==' ')
124 2 Send7279Byte(0x00);
125 2 else
126 2 if (ch=='-')
127 2 Send7279Byte(0x01);
128 2 else
129 2 {
130 3 if (ShowDot==i)
131 3 Send7279Byte(0x80|BdSeg[ch&0x0f]);
132 3 else
133 3 Send7279Byte(BdSeg[ch&0x0f]);
134 3 }
135 2 }
136 1 NOSELECT7279; //置CS高电平
137 1 }
138
139 char GetKeyValue(void)
140 {
141 1 char KeyValue;
142 1 if (CPT1CN&0x40) return -1; //无键按下
143 1 Send7279Byte(0x15); //发读键盘指令
144 1 KeyValue=Receive7279Byte();
145 1 NOSELECT7279; //置CS高电平
146 1 return KeyValue;
147 1 }
148
149 void WaitKeyOff(void)
150 {
151 1 while (!(CPT1CN&0x40));
152 1 }
153
154 void Test7279(bit LoopFlag)
155 {
156 1 char i,KeyValue;
157 1 Delay1ms(25); //等待25ms复位时间
158 1 Send7279Byte(0xA4); //发复位指令
159 1 NOSELECT7279; //置CS高电平
160 1 if (LoopFlag==0) return;
161 1 DispLED("123456",0); //显示123456
162 1 for (i=0;i<8;i++)
163 1 {
164 2 Delay1s(1);
165 2 MoveLeft();
166 2 }
167 1
168 1 DispLED("123456",0); //显示123456
169 1 DispLED("7890AB",2); //显示123456
170 1 DispLED("CDEF -",3); //显示123456
171 1
172 1 for (i=0;i<6;i++)
173 1 {
174 2 Delay1s(1);
175 2 MoveRight();
176 2 }
177 1
178 1 DispLED("F 1",1); //显示123456
179 1
C51 COMPILER V7.06 TEST7279 06/04/2005 15:57:16 PAGE 4
180 1 FlashLED(0); //第一位闪烁
181 1 Delay1s(1);
182 1 FlashLED(1); //第二位闪烁
183 1 Delay1s(1);
184 1 FlashLED(8); //关闪烁
185 1
186 1 //BlankLED(0x23); //注意:执行消隐后,键盘输入中断口不能恢复.
187 1
188 1 for (;;)
189 1 {
190 2 KeyValue=GetKeyValue();
191 2 if(KeyValue!=-1)
192 2 {
193 3 Send7279Byte(0xC8); //发送键码值,按方式1译码下载显示
194 3 Send7279Byte(KeyValue%16);
195 3 NOSELECT7279; //置CS高电平
196 3 WaitKeyOff();
197 3 }
198 2 }
199 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 544 ----
CONSTANT SIZE = 46 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 13
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -