?? 1.lst
字號:
C51 COMPILER V8.02 1 02/26/2009 21:33:17 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE 1
OBJECT MODULE PLACED IN 1.OBJ
COMPILER INVOKED BY: E:\應用軟件\Keil\C51\BIN\C51.EXE 1.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<reg52.h>
2 #include <intrins.h>
3
4 #define uchar unsigned char
5 #define uint unsigned int
6 #define ulong unsigned long
7 ///////////引腳定義
8 sbit SCLK =P2^7;
9 sbit MISO =P2^6;
10 sbit MISI =P2^5;
11 sbit CS =P2^4;
12
13 sbit lcden=P0^2;
14 sbit lcdrs=P0^0;
15 sbit rw=P0^1;
16
17
18 uchar dat[10]={1,2,3,4,5,6,7,8,9,1};
19 uchar add[3]={1,0,1};
20 uchar R_dat[10];
21 uchar code table0[]="成都信息工程學院";
22 uint num;
23
24 void Flash_init() ; /* 程序功能: 用來將時鐘線初始化為低. 必須在將設備設置為模式0之前調用*/
25 void Flash_WRSR(uchar byte) ;//寫狀態(tài)寄存器
26 uchar Flash_Read_Status_Register(void); //讀狀態(tài)寄存器的值
27 void Flash_WREN_Check(void) ; /* 功能: 檢查擦寫操作前WEL位是否為1 */
28 void Flash_WREN(void) ; //寫使能命令
29 void Flash_Sector_Erase(ulong Dst) ; /* 功能: Sector Erases the Chip. 4K */
30 void Flash_Wait_Busy(void) ;//等待 FLASH空閑
31 void Flash_Chip_Erase(void) ; /* 功能: 擦除整個芯片 */
32 void Flash_Block_Erase_32K(ulong Dst) ; /* 功能: Block Erases 32 KByte of the Chip. */
33 void Flash_Block_Erase_64K(ulong Dst) ;
34 void Flash_EWSR(void) ; //;使能改寫狀態(tài)寄存器
35 void Flash_WRDI(void) ;// 禁止寫使能
36
37 void Flash_Send_Byte(uchar dat) ;//發(fā)送一個數(shù)據(jù)char 型 的 從51到FLASH
38 uchar Flash_Get_Byte(void);// 接收一個char型的數(shù)據(jù) 51接收
39 uchar Flash_Read(ulong Dst);//讀取一個措定地址內的一個數(shù)據(jù) 作為函數(shù)返回值
40 void Flash_Write(ulong Dst,uchar dat); //向flash 內的一個地址內寫入一個數(shù)據(jù)
41
42 void Flash_Write_data(uchar add[],uchar dat[],uchar size); //向flash 內的一個基地址 add[3],add[0]放地址高
-八位 內寫入size個數(shù)據(jù)。
43
44 //向從flash 內的一個基地址 add[3],add[0]放地址高八位 內讀出size個數(shù)據(jù)。 放到dat[]中
45 void Flash_Read_data(uchar add[],uchar R_dat[],uchar size);
46
47 //向從flash 內的一個基地址 add, 內讀出size個數(shù)據(jù)。 放到dat[]中
48 void Flash_Read_data_add(ulong Dst,uchar R_dat[],uchar size);
49 void Flash_Write_data_add(ulong Dst,uchar dat[],uchar size);//向flash 內的一個基地址 add
50
51
52 delay(uint z)
53 {
54 1 uint x,y;
C51 COMPILER V8.02 1 02/26/2009 21:33:17 PAGE 2
55 1 for(x=z;x>0;x--)
56 1 for(y=110;y>0;y--);
57 1 }
58 void write_com(uchar com)
59 {
60 1 lcdrs=0;
61 1 P1=com;
62 1 delay(5);
63 1 lcden=1;
64 1 delay(5);
65 1 lcden=0;
66 1 }
67
68 void write_data(uchar date)
69 {
70 1 lcdrs=1;
71 1 P1=date;
72 1 delay(5);
73 1 lcden=1;
74 1 delay(5);
75 1 lcden=0;
76 1 }
77 void init()
78 {
79 1 lcden=0;
80 1 rw=0;
81 1 write_com(0x38);
82 1 write_com(0x0c);
83 1 write_com(0x06);
84 1 write_com(0x80);
85 1 }
86 /*------------------顯示字符串--------------------------*/
87 void write(unsigned char *s)
88 { while(*s>0)
89 1 {
90 2 write_data(*s);
91 2 s++;
92 2 delay(30);
93 2 }
94 1 }
95
96
97
98
99 ////////////////////////////////////SPI讀寫驅動///////////////////////////////////////////////////////////
-/////////////////////
100 void Flash_Send_Byte(uchar dat) //發(fā)送一個數(shù)據(jù)char 型 的 從51到FLASH
101 {
102 1 uchar i;
103 1 SCLK=0;
104 1 CS=0;
105 1 for(i=0;i<8;i++)
106 1 {
107 2 if(dat & 0x80)
108 2 {
109 3 MISI=1;
110 3 }
111 2 else
112 2 MISI=0;
113 2 dat<<=1;
114 2 SCLK=1; //信號拉高讀進數(shù)據(jù)
115 2 _nop_();
C51 COMPILER V8.02 1 02/26/2009 21:33:17 PAGE 3
116 2
117 2 SCLK=0; //將信號拉低
118 2 _nop_();
119 2 }
120 1 SCLK=0;
121 1 }
122
123 uchar Flash_Get_Byte(void) //接收一個char型的數(shù)據(jù)
124 {
125 1 uchar i;
126 1 uchar one_data=0;
127 1 CS=0;
128 1 // SCLK=1;
129 1 for(i=0;i<8;i++)
130 1 {
131 2 one_data=one_data<<1;
132 2 SCLK=0;
133 2 _nop_();
134 2 _nop_();
135 2 if(MISO==1)
136 2 {
137 3 one_data=one_data | 0x01;
138 3 }
139 2 SCLK=1;
140 2 _nop_();
141 2 }
142 1 SCLK=0;
143 1 //CS=1;
144 1 return one_data;
145 1 }
146
147 /************************************************************************/
148 /* 名稱: Read */
149 /* 功能: 讀取一個地址內一個字節(jié)的數(shù)據(jù).返回讀取的數(shù)據(jù)*/
150 /* 輸入: Dst: Destination Address 000000H - 1FFFFFH */
151 /* 返回: byte */
152 /************************************************************************/
153 uchar Flash_Read(ulong Dst)
154 {
155 1 uchar byte = 0;
156 1
157 1 SCLK=1;
158 1 CS =0;
159 1 /* enable device */
160 1 Flash_Send_Byte(0x03); /* read command */
161 1 Flash_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
162 1 Flash_Send_Byte(((Dst & 0xFFFF) >> 8));
163 1 Flash_Send_Byte(Dst & 0xFF);
164 1 byte = Flash_Get_Byte();
165 1 CS =1; /* disable device */
166 1 return byte; /* return one byte read */
167 1 }
168 ////////////////////////////////////////////////////////////////////////////////////////////////
169 void Flash_Write(ulong Dst,uchar dat) //向flash 內的一個地址內寫入一個數(shù)據(jù)。
170 {
171 1 CS=0;
172 1 Flash_Send_Byte(0x02); /* read command */
173 1 Flash_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
174 1 Flash_Send_Byte(((Dst & 0xFFFF) >> 8));
175 1 Flash_Send_Byte(Dst & 0xFF);
176 1 Flash_Send_Byte(dat);///secd data to flash
177 1 CS=1;
C51 COMPILER V8.02 1 02/26/2009 21:33:17 PAGE 4
178 1
179 1 }
180
181 void Flash_Write_data(uchar add[],uchar dat[],uchar size) //向flash 內的一個基地址 add[3],add[0]放地址高
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -