?? function.lst
字號:
C51 COMPILER V7.06 FUNCTION 10/29/2006 14:35:12 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE FUNCTION
OBJECT MODULE PLACED IN Function.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Function.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <./Atmel/at89x52.h>
2 #include <stdio.h>
3 #include <absacc.h>
4 #include <intrins.h>
5 #include <string.h>
6 #include "source.h"
7 #define FSUCCESS 0
8 #define FERROR 1
9 #define FDOVER 2
10 bit TDBdata_over;
11 unsigned char dst_buf[DST_LEN];/*為數據傳輸口的發送緩沖區.*/
12 unsigned char dst_head; /*為目前要發送數據存儲的位置*/
13 unsigned char dst_tail; /*為真正發送數據存儲的位置,當head和tail相等時表明發送數據緩沖區無數據*/
14 unsigned char dsr_buf[DSR_LEN];/*接收數據緩沖區*/
15 unsigned char dsr_head; /*從串口接收到的數據存儲的位置*/
16 unsigned char dsr_tail; /*從串口接收緩沖區讀取數據的位置,當tail和head相等時間標兵接收緩沖區無數據*
-/
17 void delay_macnine_ncircle(unsigned char cnt){//11+6*cnt machin circle.
18 1 while(cnt--);
19 1 }
20 void delay_10us(unsigned char tus){/*在C51時鐘的頻率為18.432MHZ時,延時10微秒*/
21 1 tus--;
22 1 while(tus--){
23 2 _nop_();_nop_();_nop_();
24 2 _nop_();_nop_();_nop_();
25 2 _nop_();_nop_();_nop_();
26 2 }
27 1 }
28 void print_sbuf(unsigned char c){/*向串口發送緩沖區中寫數據*/
29 1 dst_buf[dst_head]=c;
30 1 dst_head ++;
31 1 dst_head %=DST_LEN;
32 1 }
33 #define REPLAY_LEN 9
34 void reply_dwn(unsigned char flag,unsigned char *rbuf){/*rbuf 是下載的數據的指針,此函數是對下載的數據進行
-應答*/
35 1 unsigned char reply[REPLAY_LEN];
36 1 struct yushi rply_crc;
37 1 unsigned char i;
38 1 reply[0]=FDWN_FHD;
39 1 reply[1]=flag;
40 1 reply[2]=rbuf[2];
41 1 reply[3]=rbuf[3];
42 1 reply[4]=rbuf[4];
43 1 reply[5]=0x00;
44 1 reply[6]=0x00;
45 1 init_crccheck(&rply_crc);
46 1 for(i=0;i<7;i++){
47 2 crccheck(reply[i],&rply_crc);
48 2 }
49 1 reply[7]=rply_crc.h;
50 1 reply[8]=rply_crc.l;
51 1 for(i=0;i<REPLAY_LEN;i++){
52 2 print_sbuf(*(reply+i));
53 2 }
C51 COMPILER V7.06 FUNCTION 10/29/2006 14:35:12 PAGE 2
54 1 TI=1;
55 1 }
56 #define ERASE_SECTOR
57 void flash_download(void){/*數據下載,等在數據下載完畢后此函數才退出*/
58 1 union SFADD dwn_adres;
59 1 unsigned char fdata[FDWN_LEN];
60 1 unsigned char fsm_fdl;
61 1 unsigned char cnt;
62 1 unsigned char erase_sec=0;
63 1 unsigned int sector_section=0;
64 1 unsigned char temp;
65 1 struct yushi fcrc;
66 1 fsm_fdl=0;
67 1 while(1){/*進入死循環,只有計算機把所有的數據下載完畢才推出*/
68 2 if(dsr_tail!=dsr_head){/*串口接收緩沖區中有數據*/
69 3 if(fsm_fdl==0){/*串口接收在尋找幀頭(0X7E)的狀態*/
70 4 if(dsr_buf[dsr_tail]==FDWN_FHD){/*串口接收的數據是幀頭*/
71 5 fsm_fdl=1;/*把串口接收的狀態設置為接收數據*/
72 5 fdata[0]=FDWN_FHD;/*把接收到的字節存儲在接收的數據中*/
73 5 cnt=1;
74 5 }
75 4 }
76 3 else if(fsm_fdl==1){/*串口的狀態在接受數據狀態*/
77 4 if(cnt<FDWN_LEN-1){/*135個字節的幀還沒有接收完畢*/
78 5 fdata[cnt]=dsr_buf[dsr_tail];
79 5 cnt++;
80 5 }
81 4 else{/*一幀數據接收完畢*/
82 5 fdata[cnt]=dsr_buf[dsr_tail];
83 5 if(1){//mult_crccheck(fdata,FDWN_LEN,struct &fcrc)==0){/*由于串口出錯的概率比較小,沒有進行CRC效驗*/
84 6 dwn_adres.c[1]=fdata[2];/*提取出要寫到flash的地址字節*/
85 6 dwn_adres.c[2]=fdata[3];
86 6 dwn_adres.c[3]=fdata[4];
87 6 #ifdef ERASE_SECTOR
88 6 sector_section=dwn_adres.c[1];/*把地址字節轉化為扇區地址*/
89 6 sector_section <<=8;
90 6 sector_section &=0xff00;
91 6 sector_section |=dwn_adres.c[2];
92 6 sector_section >>=5;
93 6 if(((dwn_adres.c[2]&0x1f)==0x00)&&(dwn_adres.c[3]==0x00)){/*如果A0~A11為0,那么就表明要寫的數據跨越
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -