?? flash.lst
字號(hào):
C51 COMPILER V7.06 FLASH 09/26/2008 13:35:54 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE FLASH
OBJECT MODULE PLACED IN ..\OUT\Flash.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Source\Flash.c BROWSE DEBUG OBJECTEXTEND PRINT(..\OUT\Flash.lst) OBJECT(
-..\OUT\Flash.obj)
stmt level source
1 /*
2 *****************************************************************************************************
3 *
4 * File name: flash.c
5 *****************************************************************************************************
6 */
7
8 #include "..\head\includes.h"
9
10
11
12 /*
13 *****************************************************************************************************
14 *
15 *****************************************************************************************************
16 */
17 #ifdef _F_W_W_P
unsigned char flash_write_with_poll(volatile uchar xdata* addr, uchar dat)
{
unsigned char done;
unsigned char error;
unsigned char err;
unsigned char poll;
done = FALSE;
err = FALSE;
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0xA0; // write 0xA0 command to program
*(addr) = dat; // write byte to flash
dat = dat & NVM_DATA_POLL; // get bit DQ7 of original dat
do // now use dat polling method to verify successful write
{
poll = *(addr); // Read the location that was just programmed
error = poll & NVM_ERROR; // save timeout error bit at DQ5
poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
if (dat == poll) // compare DQ7
done = TRUE; // dat byte programmed into flash OK,
// indicate successful exit criteria
else if (error == NVM_ERROR ) // check for timeout error
err = TRUE; // indicate timeout error occurred
} while((done == FALSE) && (err == FALSE));
C51 COMPILER V7.06 FLASH 09/26/2008 13:35:54 PAGE 2
if (err == TRUE) // make sure timeout error and dat poll didn't
// occur simultaneously
{
poll = *(addr); // Read location in flash again
poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
if (dat == poll) // compare DQ7
done = TRUE; // dat byte programmed into flash OK at the same
// time timout error occured, indicate successful
// exit criteria
*(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
// now delay 3 msec per dat sheet
}
return(done); // a successful flash write returns 1, timeout error returns 0
}
#endif
77
78
79 /*
80 *****************************************************************************************************
81 *
82 *****************************************************************************************************
83 */
84 #ifdef _F_B_W_W_P
85
86 unsigned char flash_boot_write_with_poll(volatile unsigned char xdata* addr, unsigned char dat)
87 {
88 1 unsigned char done;
89 1 unsigned char error;
90 1 unsigned char err;
91 1 unsigned char poll;
92 1
93 1 done = FALSE;
94 1 err = FALSE;
95 1
96 1 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
97 1 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
98 1 *(FLASH_BOOT_X555) = 0xA0; // write 0xA0 command to program
99 1
100 1 *(addr) = dat; // write byte to flash
101 1
102 1 dat = dat & NVM_DATA_POLL; // get bit DQ7 of original dat
103 1
104 1 do // now use dat polling method to verify successful write
105 1 {
106 2
107 2 poll = *(addr); // Read the location that was just programmed
108 2
109 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
110 2
111 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
112 2
113 2 if (dat == poll) // compare DQ7
114 2
115 2 done = TRUE; // dat byte programmed into flash OK,
116 2 // indicate successful exit criteria
C51 COMPILER V7.06 FLASH 09/26/2008 13:35:54 PAGE 3
117 2
118 2 else if (error == NVM_ERROR ) // check for timeout error
119 2 err = TRUE; // indicate timeout error occurred
120 2
121 2 } while((done == FALSE) && (err == FALSE));
122 1
123 1
124 1 if (err == TRUE) // make sure timeout error and dat poll didn't
125 1 // occur simultaneously
126 1 {
127 2 poll = *(addr); // Read location in flash again
128 2
129 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
130 2
131 2 if (dat == poll) // compare DQ7
132 2
133 2 done = TRUE; // dat byte programmed into flash OK at the same
134 2 // time timout error occured, indicate successful
135 2 // exit criteria
136 2
137 2 *(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
138 2 // now delay 3 msec per dat sheet
139 2 }
140 1
141 1 return(done); // a successful flash write returns 1, timeout error returns 0
142 1 }
143 #endif
144
145
146 /*
147 *****************************************************************************************************
148 *
149 *****************************************************************************************************
150 */
151 #ifdef _F_W_W_T
unsigned char flash_write_with_toggle(addr,dat)
volatile unsigned char *addr;
unsigned char dat;
{
unsigned char done;
unsigned char error;
unsigned char err;
volatile unsigned char toggle_A;
volatile unsigned char toggle_B;
done = FALSE;
err = FALSE;
*(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_BOOT_X555) = 0xA0; // write 0xA0 command to program
*(addr) = dat; // write byte to flash
// now use toggling method to verify successful write
toggle_A = *(addr); // Read the location that was just programmed
toggle_A = toggle_A & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
C51 COMPILER V7.06 FLASH 09/26/2008 13:35:54 PAGE 4
do
{
toggle_B = *(addr); // Again read the location that was just programmed
error = toggle_B & NVM_ERROR; // save timeout error flag at DQ5
toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
if (toggle_A == toggle_B) // compare toggle bit DQ6
done = TRUE; // bit did not toggle, dat byte programmed into
// flash OK, indicate successful exit criteria
else
{
if (error == NVM_ERROR ) // check for timeout error
err = TRUE; // indicate timeout error occurred
toggle_A = toggle_B; // save most recent sample of toggle bit
// to compare with next sample
}
} while((done == FALSE) && (err == FALSE));
if (err == TRUE) // make sure timeout error and dat toggle didn't
// occur simultaneously
{
toggle_B = *(addr); // Read location in flash again
toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
if (toggle_A == toggle_B) // compare toggle bit DQ6
done = TRUE; // dat byte programmed into flash OK at the same
// time timout error occured, indicate successful
// exit criteria
*(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
// now delay 3 msec per dat sheet
}
return(done); // a successful flash write returns 1, timeout error returns 0
}
#endif
224
225
226
227 /*
228 *****************************************************************************************************
229 *
230 *****************************************************************************************************
231 */
232
233 #ifdef _F_E_B
unsigned char flash_erase_sector(
volatile unsigned char xdata* flash_bulk_erase_address)
{
unsigned char done;
unsigned char poll;
unsigned char error;
C51 COMPILER V7.06 FLASH 09/26/2008 13:35:54 PAGE 5
unsigned char err;
done = FALSE;
err = FALSE;
// Note: the following constants (FLASH_COMMON_XXXX)
// are declared type volatile in the header file
// so they are not optimized away by the compiler
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0x80; // write 0x80 command to erase entire chip
*(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -