ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:19.10KB ,
资源ID:6074920      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6074920.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(F32xSPI0EEPROMPolledMode.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

F32xSPI0EEPROMPolledMode.docx

1、F32xSPI0EEPROMPolledMode/-/ F32x_SPI0_EEPROM_Polled_Mode.c/-/ Copyright 2006 Silicon Laboratories, Inc./ / Program Description:/ This program accesses a SPI EEPROM using polled mode access. The F32x MCU / is configured in 4-wire Single Master Mode, and the EEPROM is the only / slave device connected

2、 to the SPI bus. The read/write operations are / tailored to access a Microchip 4 kB EEPROM 25LC320. The relevant hardware / connections of the F32x MCU are shown here:/ / P0.0 - SPI SCK (digital output, push-pull)/ P0.1 - SPI MISO (digital input, open-drain)/ P0.2 - SPI MOSI (digital output, push-p

3、ull)/ P0.3 - SPI NSS (digital output, push-pull)/ P0.4 - UART TXD (digital output, push-pull)/ P0.5 - UART RXD (digital input, open-drain)/ P2.2 - LED (digital output, push-pull)/ How To Test:/ Method1:/ 1) Download the code to a F32x device that is connected as above./ 2) Run the code. The LED will

4、 blink fast during the write/read/verify / operations./ 3) If the verification passes, the LED will blink slowly. If it fails,/ the LED will be OFF./ Method2 (optional):/ 1) Download code to a F32x device that is connected as above, and / also connected to a RS232 transceiver./ 2) Connect a straight

5、 serial cable from the RS232 transceiver to a PC./ 3) On the PC, open HyperTerminal (or any other terminal program) and connect/ to the COM port at and 8-N-1/ 4) HyperTerminal will print the progress of the write/read operation, and in / the end will print the test result as pass or fail. Additional

6、ly, if the / verification passes, the LED will blink slowly. If it fails, the LED will / be OFF./ Target: C8051F320/1/ Tool chain: Keil C51 7.50 / Keil EVAL C51/ Command Line: None/ Release 1.0/ -Initial Revision (PKC)/ -18 MAY 2006/-/ Includes/-#include / SFR declarations#include / printf is declar

7、ed here/-/ 16-bit SFR Definitions for the F32x/-sfr16 TMR2 = 0xCC; / Timer2 low and high bytes together/-/ User-defined types, structures, unions etc/-#ifndef BYTE#define BYTE unsigned char#endif#ifndef UINT#define UINT unsigned int#endif/-/ Global Constants/-#define BAUDRATE 115200 / Baud rate of U

8、ART in bps#define SYSCLK 24000000 / Internal oscillator frequency in Hz/ Microchip 25AA320 Slave EEPROM Parameters#define F_SCK_MAX 2000000 / Max SCK freq (Hz)#define T_NSS_DISABLE_MIN 500 / Min NSS disable time (ns)#define EEPROM_CAPACITY 4096 / EEPROM capacity (bytes)/ EEPROM Instruction Set#defin

9、e EEPROM_CMD_READ 0x03 / Read Command#define EEPROM_CMD_WRITE 0x02 / Write Command#define EEPROM_CMD_WRDI 0x04 / Reset Write Enable Latch Command#define EEPROM_CMD_WREN 0x06 / Set Write Enable Latch Command#define EEPROM_CMD_RDSR 0x05 / Read Status Register Command#define EEPROM_CMD_WRSR 0x01 / Writ

10、e Status Register Commandsbit LED = P22; / LED=1 means ON/-/ Function Prototypes/-void PCA0_Init (void);void OSCILLATOR_Init (void);void PORT_Init (void);void TIMER2_Init (void);void UART0_Init (void);void SPI0_Init (void);void Init_Device (void);void Delay_us (BYTE time_us);void Delay_ms (BYTE time

11、_ms);void EEPROM_Write (UINT address, BYTE value);BYTE EEPROM_Read (UINT address);/-/ main() Routine/-void main (void) UINT address; / EEPROM address BYTE test_byte; / Used as a temporary variable Init_Device (); / Initializes hardware peripherals / The following code will test the EEPROM by perform

12、ing write/read/verify / operations. The first test will write 0xFFs to the EEPROM, and the / second test will write the LSBs of the EEPROM addresses. / Fill EEPROM with 0xFFs LED = 1; printf(Filling with 0xFFs.n); for (address = 0; address EEPROM_CAPACITY; address+) test_byte = 0xFF; EEPROM_Write (a

13、ddress, test_byte); / Print status to UART0 if (address % 16) = 0) printf (nWriting 0x%04x: %02x , address, (UINT)test_byte); LED = LED; else printf (%02x , (UINT)test_byte); / Verify EEPROM with 0xFFs printf(nnVerifying 0xFFs.n); for (address = 0; address EEPROM_CAPACITY; address+) test_byte = EEPR

14、OM_Read (address); / Print status to UART0 if (address % 16) = 0) printf (nVerifying 0x%04x: %02x , address, (UINT)test_byte); LED = LED; else printf (%02x , (UINT)test_byte); if (test_byte != 0xFF) LED = 0; printf (Error at %un, address); while (1); / Stop here on error (for debugging) / Fill EEPRO

15、M with LSB of EEPROM addresses printf(nnFilling with LSB of EEPROM addresses.n); for (address = 0; address EEPROM_CAPACITY; address+) test_byte = address & 0xFF; EEPROM_Write (address, test_byte); / Print status to UART0 if (address % 16) = 0) printf (nWriting 0x%04x: %02x , address, (UINT)test_byte

16、); LED = LED; else printf (%02x , (UINT)test_byte); / Verify EEPROM with LSB of EEPROM addresses printf(nnVerifying LSB of EEPROM addresses.n); for (address = 0; address clkmul/2)./-void OSCILLATOR_Init (void) int i = 0; CLKMUL = 0x80; for (i = 0; i 20; i+); / Wait 5us for initialization CLKMUL |= 0

17、xC0; while (CLKMUL & 0x20) = 0); CLKSEL = 0x02; OSCICN = 0x83;/-/ PORT_Init/-/ Return Value : None/ Parameters : None/ This function configures the crossbar and GPIO ports./ P0.0 - SCK (SPI0), Push-Pull, Digital/ P0.1 - MISO (SPI0), Open-Drain, Digital/ P0.2 - MOSI (SPI0), Push-Pull, Digital/ P0.3 -

18、 NSS (SPI0), Push-Pull, Digital/ P0.4 - TX0 (UART0), Push-Pull, Digital/ P0.5 - RX0 (UART0), Open-Drain, Digital/ P0.6 - Unassigned, Open-Drain, Digital/ P0.7 - Unassigned, Open-Drain, Digital/ P1.0 - Unassigned, Open-Drain, Digital/ P1.1 - Unassigned, Open-Drain, Digital/ P1.2 - Unassigned, Open-Dr

19、ain, Digital/ P1.3 - Unassigned, Open-Drain, Digital/ P1.4 - Unassigned, Open-Drain, Digital/ P1.5 - Unassigned, Open-Drain, Digital/ P1.6 - Unassigned, Open-Drain, Digital/ P1.7 - Unassigned, Open-Drain, Digital/ P2.0 - Skipped, Open-Drain, Digital (Switch S2 on Target Board)/ P2.1 - Skipped, Open-

20、Drain, Digital (Switch S3 on Target Board)/ P2.2 - Skipped, Push-Pull, Digital (LED D4 on Target Board)/ P2.3 - Skipped, Push-Pull, Digital (LED D2 on Target Board)/-void PORT_Init (void) P0MDOUT = 0x1D; P2MDOUT = 0x0C; P2SKIP = 0x0F; XBR0 = 0x03; XBR1 = 0x40;/-/ TIMER2_Init/-/ Return Value : None/ Parameters : None/ Initializes Timer2 to be clocked by SYSCLK for use as a delay timer./-void TIMER2_Init (void) CKCO

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1