|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機 | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
做過x5045或?qū)?045的進來救個火…… |
| 作者:曉勇 欄目:單片機 |
我用網(wǎng)友提供的X5045的51子程序調(diào)試X5045,程序編譯都過了,可是寫完狀態(tài)寄存器后,卻始終讀不到WIP位清零,而SO線上一直為高電平,有哪位DX知道的指點一下,程序如下,謝謝! #include <REG52.H> #include <INTRINS.H> #define byte unsigned CHAR #define word unsigned int #define nop() _nop_();_nop_(); //-----------X25045指令-----------------// /*#define WREN 0x06 //寫允許 #define WRDI 0x04 //寫禁止 #define RDSR 0x05 //讀狀態(tài)寄存器 #define WRSR 0x01 //寫狀態(tài)寄存器 #define READ 0x03 //讀書據(jù) #define WRITE 0x02 //寫數(shù)據(jù) */ //-----------SPI通訊接口-----------------// sbit SPI_SI=P2^3; sbit SPI_CLK=P2^5; sbit SPI_SO=P2^7; sbit X5045_CS=P2^6; byte code WREN_INST=0X06; /* Write enable latch instruction (WREN)*/ byte code WRDI_INST=0X04; /* Write disable latch instruction (WRDI)*/ byte code WRSR_INST=0X01; /* Write status register instruction (WRSR)*/ byte code RDSR_INST=0X05; /* Read status register instruction (RDSR)*/ byte code WRITE_INST=0X02; /* Write MEMORY instruction (WRITE)*/ /*寫入25045的先導(dǎo)字,應(yīng)當(dāng)為0000A010,其中的A為寫入25045的高位地址 將此WRITE_INST和寫入高位地址相或后即為正確的寫先導(dǎo)字*/ byte code READ_INST=0X03; /* Read MEMORY instruction (READ)*/ /*讀出25045的先導(dǎo)字,應(yīng)當(dāng)為0000A011,其中的A為讀出25045的高位地址 將此READ_INST和讀出高位地址相或后即為正確的讀先導(dǎo)字*/ word code BYTE_ADDR=0X55; /* MEMORY address for byte mode operations*/ byte code BYTE_DATA=0X11; /*Data byte for byte write operation*/ word code PAGE_ADDR=0X1F; /* MEMORY address for page mode operations*/ /*頁面寫入的其始地址*/ byte code PAGE_DATA1=0X22; /* 1st data byte for page write operation*/ byte code PAGE_DATA2=0X33; /* 2nd data byte for page write operation*/ byte code PAGE_DATA3=0X44; /* 3rd data byte for page write operation*/ byte code STATUS_REG=0X00; /* Status register,調(diào)試中先設(shè)置DOG為禁止,無寫保護*/ /*這是狀態(tài)寄存器的值,他的意義在于第5,第4位為WDI1,WDI0代表DOG的時間,00為1.4秒,01為600毫秒,10為200毫秒,00為disabled 第3位和第2位為BL1,BL0,是寫保護設(shè)置位,00為無保護,01為保護180-1FF,10為保護100-1FF,11為保護000-1FF.第1位為WEL, 當(dāng)他為1時代表已經(jīng)"寫使能"設(shè)置了,現(xiàn)在可以寫了,只讀位.第0位為WIP,當(dāng)他為1時代表正在進行寫操作,是只讀*/ byte code MAX_POLL=0x99; /* Maximum NUMBER of polls*/ /*最大寫過程時間,確定25045的最大的寫入過程的時間*/ byte code INIT_STATE=0x09; /* Initialization VALUE for CONTROL ports*/ word code SLIC=0x30; /* Address location of SLIC*/ void wren_cmd(void);/*寫使能子程序*/ void wrdi_cmd(void);/*寫使能復(fù)位*/ void wrsr_cmd(void);/*復(fù)位時間位和數(shù)據(jù)保護位寫入狀態(tài)寄存器*/ byte rdsr_cmd(void);/*讀狀態(tài)寄存器*/ void byte_write(byte aa,word dd);/*字節(jié)寫入,aa為寫入的數(shù)據(jù),dd為寫入的地址*/ byte byte_read(word dd);/*字節(jié)讀出,dd為讀出的地址,返回讀出的數(shù)據(jù)*/ void page_write(byte aa1,byte aa2,byte aa3,byte aa4,word dd);/*頁寫入*/ void sequ_read(void);/*連續(xù)讀出*/ void rst_wdog(void);/*DOG復(fù)位*/ void outbyte(byte aa);/*輸出一個字節(jié)到25045中,不包括先導(dǎo)字等*/ byte inputbyte();/*由25045輸入一個字節(jié),不包括先導(dǎo)字等額外的東西*/ void wip_poll(void);/*檢查寫入過程是否結(jié)束*/ /*25045操作子程序集*/ /*;******************************************************************************************* * ;* NAME: WREN_CMD ;* DESCRIPTION: Set write enable latch ;* Function: This routine sends the command to enable writes to the EEPROM MEMORY array or ;* status register ;* Calls: outbyte ;* Input: None ;* Outputs: None ;* Register Usage: A ;******************************************************************************************* */ /*寫使能子程序*/ void wren_cmd(void) { //byte aa; SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=0;/* Bring /X5045_CS low */ //aa=WREN_INST; outbyte(WREN_INST);/* Send WREN instruction */ SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=1;/* Bring /X5045_CS high */ } /*;******************************************************************************************* * ;* NAME: WRDI_CMD ;* DESCRIPTION: Reset write enable latch ;* Function: This routine sends the command to disable writes to the EEPROM MEMORY array or ;* status register ;* Calls: outbyte ;* Input: None ;* Outputs: None ;* Register Usage: A ;******************************************************************************************* */ /*寫使能復(fù)位子程序*/ void wrdi_cmd(void) { //byte aa; SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=0;/* Bring /X5045_CS low */ //aa=WRDI_INST; outbyte(WRDI_INST);/* Send WRDI instruction */ SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=1;/* Bring /X5045_CS high */ } /*;******************************************************************************************* * ;* NAME: WRSR_CMD ;* DESCRIPTION: Write Status Register ;* Function: This routine sends the command to write the WD0, WD1, BP0 and BP0 EEPROM ;* bits in the status register ;* Calls: outbyte, wip_poll ;* Input: None ;* Outputs: None ;* Register Usage: A ;******************************************************************************************* */ /*寫狀態(tài)寄存器子程序*/ void wrsr_cmd(void) { //byte aa; wren_cmd(); //寫狀態(tài)寄存器得先置寫使能鎖存器 SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=0;/* Bring /X5045_CS low */ //aa=WRSR_INST; outbyte(WRSR_INST) ;/* Send WRSR instruction */ //aa=STATUS_REG; outbyte(STATUS_REG);/* Send status register */ //_nop_(); //SPI_CLK=0;/* Bring SPI_CLK low */ X5045_CS=1;/* Bring /X5045_CS high */ wip_poll();/* Poll for completion of write cycle */ } /*;******************************************************************************************* * ;* NAME: RDSR_CMD ;* DESCRIPTION: Read Status Register ;* Function: This routine sends the command to read the status register ;* Calls: outbyte, inputbyte ;* Input: None ;* Outputs: A = status registerXicor Application Note AN21 ;* Register Usage: A ;******************************************************************************************* */ /*讀狀態(tài)寄存器,讀出的數(shù)據(jù)放入到aa中*/ byte rdsr_cmd (void) { byte aa; SPI_CLK=0; X5045_CS=0; //aa=RDSR_INST; outbyte(RDSR_INST); aa=inputbyte(); SPI_CLK=0; X5045_CS=1; return aa; } /*;******************************************************************************************* * ;* NAME: BYTE_WRITE ;* DESCRIPTION: SINGLE Byte Write ;* Function: This routine sends the command to write a SINGLE byte to the EEPROM MEMORY array ;* Calls: outbyte, wip_poll ;* Input: None ;* Outputs: None ;* Register Usage: A, B ;******************************************************************************************* */ /*字節(jié)寫入,aa為寫入的數(shù)據(jù),dd為寫入的地址,對于25045而言為000-1FF*/ void byte_write(byte aa,word dd) //byte aa; //word dd; { wren_cmd(); //寫存儲器得先置寫使能鎖存器 SPI_CLK=0; X5045_CS=0; outbyte((((byte)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including MSB of address */ /*將高位地址左移3位與寫入先導(dǎo)字相或,得到正確的先導(dǎo)字寫入25045*/ outbyte((byte)(dd)); /*輸出低位地址到25045*/ outbyte(aa); /*寫入數(shù)據(jù)到25045的對應(yīng)單元*/ SPI_CLK=0; X5045_CS=1; wip_poll(); /*檢測是否寫完*/ } /*;************************************************************* |
| 2樓: | >>參與討論 |
| 作者: hotpower 于 2005/12/4 22:14:00 發(fā)布:
搞得如此復(fù)雜肯定不是自己想的 |
|
| 3樓: | >>參與討論 |
| 作者: 曉勇 于 2005/12/4 22:29:00 發(fā)布:
??? 程序是網(wǎng)友給的,我也就是要做個調(diào)試,看能否對X5045讀寫,可惜不成功,幫忙解決一下吧,X5045輸出線SO沒有變化是什么原因呢? |
|
| 4樓: | >>參與討論 |
| 作者: 曉勇 于 2005/12/4 23:53:00 發(fā)布:
怎么沒有人幫忙啊? |
|
| 5樓: | >>參與討論 |
| 作者: hotpower 于 2005/12/5 0:10:00 發(fā)布:
自己學(xué)就應(yīng)該先搞清協(xié)議及時序 給你等于害你...搞清原理比拿來就用強百倍!!! |
|
| 6樓: | >>參與討論 |
| 作者: sharks 于 2005/12/5 18:38:00 發(fā)布:
火勢太大。沒法救了…… |
|
| 7樓: | >>參與討論 |
| 作者: miaoxun206 于 2005/12/5 19:44:00 發(fā)布:
自己寫程序 仔細(xì)看資料 |
|
| 8樓: | >>參與討論 |
| 作者: fly1974 于 2005/12/6 11:35:00 發(fā)布:
try it bdata uchar Command _at_ 0x29; sbit Command_7 = Command^7; sbit Command_6 = Command^6; sbit Command_5 = Command^5; sbit Command_4 = Command^4; sbit Command_3 = Command^3; sbit Command_2 = Command^2; sbit Command_1 = Command^1; sbit Command_0 = Command^0; sbit Sio = P1^0; //串行設(shè)備接口數(shù)據(jù)線緩沖位 sbit Sck = P1^1; //串行設(shè)備接口時鐘線緩沖位 sbit X5045Cs = P1^3; //X5045使能端緩沖位 //------------------------------讀寫X5045子程序------------------------------------ void WatchDog(void) //喂狗 { nop; X5045Cs=0; nop; X5045Cs=1; } void Write_byte5045(void) //寫字節(jié)5045命令(與KA120比較有改動) { uchar k; for(k=0;k<8;k++) { Sck=0; nop; Sio=Command_7; nop; Sck=1; nop; Command<<=1; } Sio=1; feeddog=1; } void Write_en5045(void) //寫使能 { X5045Cs =0; Command=0x06; Write_byte5045(); X5045Cs =1; } void Write_dis5045(void) { X5045Cs=0; Command=0x04; Write_byte5045(); X5045Cs =1; } void Write_5045(uchar Length, bit High_address, uchar Low_address) //根據(jù)參數(shù)寫5045 { uchar i; X5045Cs = 0; //5045使能 if(High_address) //判斷是否需要最高位地址 Command=0x0a; else Command=0x02; Write_byte5045(); Command=Low_address; Write_byte5045(); //寫入起始地址 for(i=0;i<Length;i++) //寫入數(shù)據(jù) { Command=Data1_buffer[i]; Write_byte5045(); } X5045Cs =1; Ddelay(20,1); } void DogEnable(void) //寫5045狀態(tài)寄存器 { X5045Cs=0; Command=0x01; Write_byte5045(); Command=0; Write_byte5045(); X5045Cs=1; } void DogDisable(void) //寫5045狀態(tài)寄存器 { X5045Cs=0; Command=0x01; Write_byte5045(); Command=0x30; Write_byte5045(); X5045Cs=1; } void Read_byte5045(void) //讀字節(jié)5045命令 (與KA120比較有改動) { uchar k; for(k=0;k<8;k++) { Command<<=1; Sck=1; nop; Sck=0; Command_0=Sio; } Sck=1; } void Read_5045(uchar Length, bit High_address, uchar Low_address) //根據(jù)參數(shù)讀5045 { uchar i; X5045Cs = 0; //5045使能 if(High_address) Command=0x0b; else Command=0x03; Write_byte5045(); Command=Low_address; Write_byte5045(); for(i=0;i<Length;i++) { Read_byte5045(); Data1_buffer[i]=Command; } X5045Cs =1; } //------------------------------讀寫X5045子程序------------------------------------ |
|
|
|
| 免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 www.udpf.com.cn 浙ICP證030469號 |