📄 12864_7920.lst
字号:
C51 COMPILER V7.07 12864_7920 11/07/2007 11:24:18 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE 12864_7920
OBJECT MODULE PLACED IN 12864_7920.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 12864_7920.c BROWSE DEBUG OBJECTEXTEND TABS(8)
stmt level source
1 /********************************************
2 12864(控制器为st7920)驱动 ,采用串行方式,
3 ********************************************/
4 #include"reg52.h"
5 #include "intrins.h"
6 sbit SCLK =P3^4 ; //E
7 sbit SID =P3^3; //RW
8 sbit RST =P3^2; //CS
9 sbit PSB =P3^5;
10 #define ROW1 0x80
11 #define ROW2 0x90
12 #define ROW3 0x88
13 #define ROW4 0x98
14 #define uint unsigned int
15 #define uchar unsigned char
16 uchar code AC_TABLE[]={
17 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行汉字位置
18 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置
19 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行汉字位置
20 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行汉字位置
21 };
22
23 uchar code Hz_0[]={"汉字数字字母 演示"};
24 uchar code Hz_1[]={"打点演示"};
25 uchar code Hz_2[]={"图像演示"};
26 uchar code dsp[]={"欢迎使用KP-51PRO实验板 E_mail: cany_999@163.com"};
27 /*****************************************
28 Fucntion: delay10US(char x)
29 Description: delay for 10 us
30 Parameter: x
31 *****************************************/
32 void delay10US(uchar x)
33 {
34 1 uchar k;
35 1 for(k=0;k<x;k++);
36 1
37 1 }
38 /*****************************************
39 Fucntion: delay1MS(char x)
40 Description: delay for 10 us
41 Parameter: x delay for 1MS
42 *****************************************/
43 void delay1MS(uchar x)
44 {
45 1 uchar k,j;
46 1 x=x<<1;
47 1 for(k=0;k<x;k++)
48 1 for(j=0;j<255;j++)_nop_();
49 1 }
50 /********************************************************************/
51 void SendByteLCD(uchar WLCDData)
52 {
53 1 uchar i;
54 1 for(i=0;i<8;i++)
55 1 {
C51 COMPILER V7.07 12864_7920 11/07/2007 11:24:18 PAGE 2
56 2 if((WLCDData<<i)&0x80)SID=1;
57 2 else SID=0;
58 2 SCLK=0;
59 2 _nop_();
60 2 _nop_();
61 2 _nop_();
62 2 _nop_();
63 2 SCLK=1;
64 2 }
65 1 }
66 /**********************************************************************/
67
68 void SPIWR(uchar Wdata,uchar RS)
69 {
70 1 SendByteLCD(0xf8+(RS<<1));
71 1 SendByteLCD(Wdata&0xf0);
72 1 SendByteLCD((Wdata<<4)&0xf0);
73 1 }
74
75 /********************************************************************/
76 void SendCMD(uchar CMD)
77 {
78 1 SPIWR(CMD,0);
79 1 delay10US(90);
80 1 }
81
82 /********************************************************************/
83
84 void SendData(uchar Data)
85 {
86 1 SPIWR(Data,1);
87 1 }
88 /********************************************************************/
89 void LCDInit(void)
90 {
91 1 RST=0;
92 1 delay1MS(50);
93 1 RST=1;
94 1 SendCMD(0x30); //功能设置,一次送8位数据,基本指令集
95 1 SendCMD(0x0C); //0000,1100 整体显示,游标off,游标位置off
96 1 SendCMD(0x01); //0000,0001 清DDRAM
97 1 SendCMD(0x02); //0000,0010 DDRAM地址归位
98 1 SendCMD(0x80); //1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC//
99 1 SendCMD(0x04); //点设定,显示字符/光标从左到右移位,DDRAM地址加 一//
100 1 SendCMD(0x0C); //显示设定,开显示,显示光标,当前显示位反白闪动
101 1 }
102
103
104 /***************************************************************************************
105 发送字符串
106 ***************************************************************************************/
107 void PutStr(uchar row,uchar col,uchar *puts)
108 {
109 1 SendCMD(0x30); //8BitMCU,基本指令集合
110 1 SendCMD(AC_TABLE[8*row+col]); //起始位置
111 1 while(*puts != '\0') //判断字符串是否显示完毕
112 1 {
113 2 if(col==8) //判断换行
114 2 { //若不判断,则自动从第一行到第三行
115 3 col=0;
116 3 row++;
117 3 }
C51 COMPILER V7.07 12864_7920 11/07/2007 11:24:18 PAGE 3
118 2 if(row==4) row=0; //一屏显示完,回到屏左上角
119 2 SendCMD(AC_TABLE[8*row+col]);
120 2 SendData(*puts); //一个汉字要写两次
121 2 puts++;
122 2 SendData(*puts);
123 2 puts++;
124 2 col++;
125 2 }
126 1 }
127 /*******************************************************************************/
128
129 void ClearScreen(void)
130 {
131 1 uchar i,j,x,y;
132 1 LCDInit();
133 1 SendCMD(0x3e); // ;RE=1 扩展指令选择 G=1 开图形显示
134 1 x=0x80;
135 1 y=0x80;
136 1 for(j=0;j<64;j++)
137 1 {
138 2 y=0x80;
139 2 SendCMD(x);
140 2 SendCMD(y);
141 2 for(i=0;i<32;i++){SendData(0x00);}
142 2 x=x+1;
143 2 }
144 1
145 1 }
146
147 /********************************************************************************/
148 void Sendint(uint dd)
149 {
150 1 SendData(dd>>8);
151 1 SendData(dd);
152 1 }
153
154 /*******************************************************************************
155 打点 x=0:128; y=0:64;
156 ********************************************************************************/
157 void Gra(uchar x,uchar y)
158 {
159 1 uchar xx,yy;
160 1 SendCMD(0x34);
161 1 SendCMD(0x36);
162 1 xx=x/16;
163 1 yy=63-y;
164 1 if(yy>=32){xx=xx+8;yy-=32;}
165 1 SendCMD(0x80+yy);
166 1 SendCMD(0x80+xx);
167 1 Sendint(0x8000>>(x%16));
168 1 }
169
170
171 /********************************************************************************/
172 uchar code IBM[]=
173 {
174 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
175 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xFE,
176 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
177 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
178 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xF0,0x00,0x1F,0xFF,0xFE,
179 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
C51 COMPILER V7.07 12864_7920 11/07/2007 11:24:18 PAGE 4
180 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
181 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
182 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
183 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xF8,0x00,0x3F,0xFF,0xFE,
184 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
185 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
186 0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
187 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
188 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
189 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
190 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
191 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
192 0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFE,0x01,0xFF,0xFF,0x00,
193 0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x01,0xFF,0xFF,0x00,
194 0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x03,0xFF,0xFF,0x00,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -