No.84531 作者:hypee 邮件:stephen.hu@usbdisk.com ID:14598 登陆:9次 文章数:5篇 最后登陆IP:222.66.124.130 最后登陆:2007/4/19 16:51:01 注册:2003/8/26 19:25:25 财富:132 发帖时间:2005/10/9 10:43:21 发贴者IP:202.109.109.146 标题:hypee:对发flash 的0000~ffff 地址读写 摘要:No.84531对发flash 的0000~ffff 地址读写 //*********************************************************************// // // file: mcu2flash.c // // AUTHOR: stephen lg // // E_mail: yohu@sst.com // // ABSTRACT: control the flash via the mcu and serial with debug soft // // MODIFICATION HISTORY: // MODIFICATION HISTORY: //***********************************************************************// #include <REG51.H> #include <string.h> #include <cmd.h> #include <flash_cmd.h> #define uchar unsigned char // 8bit3 #define uint unsigned int // 16bit #define ulong unsigned long // 32bit #define EBYTE ((unsigned char volatile xdata *) 0) #define cmd_len 3 #define tol_len 2 #define data_len 17 uchar idata cmd_buff[cmd_len]; //store the cmd data uchar idata len_buff[tol_len]; //store the data total length uchar idata data_buff[data_len]; // sotre the data uchar idata count1 ; // count1 for low byte uchar idata count2 ; // count2 for high byte uint idata n; // write the data to external ram; for counter uint idata k; // read/verify the data for external ram; uchar idata count; // counter bit send_flag; // finished received, set this flag bit pass_error; // imply the pc, the received data right or error bit rec_cmd; // receive cmd flag bit rec_len; // receive len flag bit rec_data; // receive data flag sbit P36=P3^6; // write sbit P37=P3^7; // read sbit P13=P1^3; // chip enable sbit P21=P2^1; // A9 for erase void init_serialcom(void) { SCON|=0x50; // serial: model 2 TMOD|=0x20; // time1: model 2 PCON|=0x00; // SMOD : 0 TH1|=0x0f3; // 24M 4800 bps TR1=1; // start the time1 } void delay_100(void) // delay 20ms { uchar idata i=0; uchar idata j=0; for(i=0;i <=200;i=i+1) // 20 ms { while(j <=200) // (1/24) * 12 = 0.5 us * 200 = 100 us {j=j+1;} } } // send one byte void send_byte(uchar in_byte) { SBUF=in_byte; while (TI==0); TI=0; } // send the string in read/verify void send_string(uchar *str,uchar strlen) { uchar k=0; do { send_byte(*(str+k)); k=k+1; }while(k <strlen); } //*************************************************************// void serial_int() interrupt 4 using 1 { EA=0; ES=0; if(RI){ uchar idata m; // write counter for each time uchar idata rec; // receive data for temp if(rec_cmd) // receive command { RI=0; rec=SBUF; P1=SBUF; cmd_buff[count]=rec; count=count+1; if(count==cmd_len) { count=0; rec_cmd=0; send_flag=1; } else { rec_cmd=1; send_flag=0; } } else if(rec_len) // receive data length { RI=0; rec=SBUF; P1=SBUF; len_buff[count]=rec; count=count+1; if(count==tol_len) { count=0; rec_len=0; rec_data=1; send_byte(ACK); } else { rec_len=1; } } else if(rec_data) // receive data flow { RI=0; rec=SBUF; // count1 low P1=SBUF; // count2 high data_buff[count]=rec; if(count==0); else count1=count1+1; count=count+1; if((count2==len_buff[1])&&(count1==len_buff[0])) { if(data_buff[0]==count-1) { send_byte(PASS); // **************************** // // add the flash operat: write // **************************** // P13=0;P37=1;P36=0; for(m=1;m <count;m=m+1) { EBYTE[n]=data_buff[m]; n=n+1; k=n; } P13=1;P37=1;P36=0; n=0; //****************** end *********************// rec_cmd=1; rec_len=0; rec_da ......
>>返回讨论的主题
|