isp pdf

3 133 0
isp pdf

Đang tải... (xem toàn văn)

Thông tin tài liệu

#include <REGX51.H> #include <intrins.H> #define nop _nop_();_nop_();_nop_();_nop_(); sbit sck = P2^0; sbit swr = P2^1; sbit srd = P2^2; sbit cs = P2^3; unsigned char bdata wdata; //sfr wdata = 0xa0; sbit shift7 = wdata^7; void msdelay(unsigned int ms) { int i,j; for(i=0;i<=ms;i++) for(j=0;j<=122;j++); } void start() { cs = 1; nop; cs = 0; } void stop() { cs = 0; nop; cs = 1; } void write(char wdata) { unsigned char bit_count = 0; while(bit_count<8) { swr = shift7; sck=0; _nop_(); sck=1; _nop_(); wdata = wdata<<1; bit_count++; } for (bit_count = 0; bit_count < 8; bit_count++) { swr = ((wdata & 0x80) > 0) ? 1 : 0; sck = 0; _nop_(); sck = 1; wdata = wdata << 1; } } void main() { start(); write(0x06); // write enable command msdelay(10); stop(); msdelay(10); start(); write(0x01); // write enable command msdelay(10); write(0x00); // write enable command msdelay(10); stop(); msdelay(10); start(); write(0x06); // write enable command msdelay(10); stop(); msdelay(10); start(); write(0x02); // write command msdelay(10); write(0x00); // high byte address msdelay(10); stop(); msdelay(10); start(); write(0x02); msdelay(10); write(0x00); msdelay(10); write(0x40); // low byte address msdelay(10); write(0x3f); // data to write in spi eeprom msdelay(10); stop(); while(1); }

Ngày đăng: 27/06/2014, 04:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan