📄 test1_main.lst
字号:
C51 COMPILER V7.06 TEST1_MAIN 03/06/2010 17:37:25 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TEST1_MAIN
OBJECT MODULE PLACED IN test1_main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe test1_main.c DB OE BR LARGE
stmt level source
1 /*by xzp21st 2009.5 Email:tyter1223@163.com*/
2
3 #include "c8051f340.h"
4 #include "spi.h"
5 #include "uart.h"
6 #include "sd.h"
7 #include "mcu_init.h"
8 #include "diskio.h"
9 #include "ff.h"
*** WARNING C322 IN LINE 364 OF ff.h: unknown identifier
*** WARNING C322 IN LINE 419 OF ff.h: unknown identifier
10
11 BYTE buff[1024]; /*working buffer*/
12
13 DWORD get_fattime (void)
14 {
15 1 DWORD tmr = 0;
16 1 return tmr;
17 1 }
18
19 /*测试函数*/
20 void test_readSingleBlock(unsigned long);
21 void test_writeSingleBlock(unsigned long);
22 void test_readMultipleBlock(unsigned long, unsigned char);
23 void test_writeMultipleBlock(unsigned long, unsigned char);
24 void test_FileWR();
25 void test_FileWRTXT();
26
27 /*------------------------------------------------------------------------------------*/
28 /*main*/
29 int main(void)
30 {
31 1 PCA0MD &= ~0x40; /*关内部看门狗*/
32 1
33 1 Init_Devices();
34 1
35 1 CLS;/*windows超级终端清屏*/
36 1
37 1 transmitString("***********************************\r\n");
38 1 transmitString(" xzp21st's microSD Card Testing..\r\n");
39 1 transmitString("***********************************\r\n");
40 1
41 1 if(disk_initialize(0))
42 1 transmitString("\r\nSD card init fail!\r\n");
43 1 else
44 1 {
45 2 transmitString("\r\nSD card init success!\r\n");
46 2
47 2 //单块读写和多块读写会破坏文件系统
48 2 /*单块读写测试*/
49 2 //test_writeSingleBlock(0);
50 2 //test_readSingleBlock(0);
51 2
52 2
53 2 /*多块读写测试*/
C51 COMPILER V7.06 TEST1_MAIN 03/06/2010 17:37:25 PAGE 2
54 2 //test_readMultipleBlock(0, 2);
55 2 //test_writeMultipleBlock(10000, 2);
56 2
57 2 //读写测试,卡必须是经过格式化,不能经过SD单独操作
58 2 /*文件读写测试*/
59 2 test_FileWR();
60 2 //test_FileWRTXT();
61 2 }
62 1 transmitString("|/-\\\r");
63 1 delay(1000);
64 1 transmitString("/-\\|\r");
65 1 delay(1000);
66 1 transmitString("-\\|/\r");
67 1 delay(1000);
68 1 transmitString("\\|/-\r");
69 1 delay(1000);
70 1 transmitString("|/-\\\r");
71 1 delay(1000);
72 1 while(1)
73 1 {
74 2 ;
75 2 }
76 1
77 1 return 0;
78 1 }
79
80 /*------------------------------------------------------------------------------------*/
81 /*for test*/
82
83 /*测试单块读操作*/
84 void test_readSingleBlock(unsigned long block_addr)
85 {
86 1 if(disk_read(0, buff, block_addr, 1)) /*读第block_addr块*/
87 1 transmitString("\r\nRead single block operation fail!!!\r\n");
88 1 else
89 1 {
90 2 transmitString("\r\nRead single block operation success~~~\r\n");
91 2 transmitString("\r\nPress any key to display the data~~~\r\n");
92 2 receiveByte();
93 2 CLS;
94 2 displayData(buff, 512);
95 2 }
96 1 }
97
98 /*测试单块写操作*/
99 void test_writeSingleBlock(unsigned long block_addr)
100 {
101 1 int i = 0;
102 1 for(i=0; i<512; i++)
103 1 {
104 2 buff[i] = i+2;
105 2 }
106 1
107 1 if(disk_write(0, buff, block_addr, 1)) /*向第block_addr块写数据*/
108 1 transmitString("\r\nWrite single block operation fail!!!\r\n");
109 1 else /*写成功*/
110 1 {
111 2 transmitString("\r\nWrite single block operation success~~~\r\n");
112 2 test_readSingleBlock(block_addr);
113 2 }
114 1 }
115
C51 COMPILER V7.06 TEST1_MAIN 03/06/2010 17:37:25 PAGE 3
116 /*测试多块读操作*/
117 void test_readMultipleBlock(unsigned long block_addr, unsigned char count)
118 {
119 1 if(disk_read(0, buff, block_addr, count)) /*读从第num块开始的两个块*/
120 1 transmitString("\r\nRead multiple blocks operation fail!!!\r\n");
121 1 else /*读多块成功*/
122 1 {
123 2 transmitString("\r\nRead multiple blocks operation success~~~\r\n");
124 2 transmitString("\r\nPress any key to display the data~~~\r\n");
125 2 receiveByte();
126 2 CLS;
127 2 displayData(buff, 1024);
128 2 }
129 1 }
130
131 /*测试多块写操作*/
132 void test_writeMultipleBlock(unsigned long block_addr, unsigned char count)
133 {
134 1 int i = 0;
135 1 for(i=0; i<1024; i++)
136 1 {
137 2 buff[i] = i+1;
138 2 }
139 1
140 1 if(disk_write(0, buff, block_addr, count))
141 1 transmitString("\r\nWrite multiple blocks operation fail!!!\r\n");
142 1 else /*写多块成功*/
143 1 {
144 2 transmitString("\r\nWrite multiple blocks operation success~~~\r\n");
145 2 test_readMultipleBlock(block_addr, count);
146 2 }
147 1 }
148 /*测试文件TXT读写操作,文件大小为512字节*/
149
150 void test_FileWRTXT()
151 {
152 1 FATFS fs; //Work area (file system object) for logical drive
153 1 FIL file; //file objects
154 1 //UINT bw, br; //File R/W count
155 1
156 1
157 1 int i = 0;
158 1 for(i=0; i<512; i++)
159 1 {
160 2 buff[i] = i+1;//i-16位,buff-8位
161 2 }
162 1 //Register a work area for logical drive 0
163 1 f_mount(0, &fs);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -