12.07.2015 Views

MPLAB® C18 C 编译器函数库

MPLAB® C18 C 编译器函数库

MPLAB® C18 C 编译器函数库

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

硬 件 外 设 函 数2.6.2 使 用 示 例下 面 是 一 个 简 单 的 代 码 示 例 , 举 例 说 明 了 SSP 模 块 与 Microchip 93LC66 Microwire 电可 擦 除 存 储 器 之 间 的 通 讯 。#include "p18cxxx.h"#include "mwire.h"// 93LC66 x 8// FUNCTION Prototypesvoid main(void);void ew_enable(void);void erase_all(void);void busy_poll(void);void write_all(unsigned char data);void byte_read(unsigned char address);void read_mult(unsigned char address,unsigned char *rdptr,unsigned char length);void write_byte(unsigned char address,unsigned char data);// VARIABLE Definitionsunsigned char arrayrd[20];unsigned char var;// DEFINE 93LC66 MACROS -- see datasheet for details#define READ 0x0C#define WRITE 0x0A#define ERASE 0x0E#define EWEN1 0x09#define EWEN2 0x80#define ERAL1 0x09#define ERAL2 0x00#define WRAL1 0x08#define WRAL2 0x80#define EWDS1 0x08#define EWDS2 0x00#define W_CS LATCbits.LATC2void main(void){TRISCbits.TRISC2 = 0;W_CS = 0;//ensure CS is negatedOpenMwire(MWIRE_FOSC_16); //enable SSP peripheralew_enable();//send erase/write enablewrite_byte(0x13, 0x34); //write byte (address, data)busy_poll();Nop();byte_read(0x13); //read single byte (address)read_mult(0x10, arrayrd, 10); //read multiple byteserase_all();//erase entire arrayCloseMwire();//disable SSP peripheral}© 2004 Microchip Technology Inc. DS51297C_CN 第 37 页

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!