阅读:998回复:0
帮我看看93c46的程序
我现在有一份vc下的93c46读写程序,现在还没有调试通过大家帮我看看啊
// 1.cpp : Defines the entry point for the console application. // #include <conio.h> #include "stdafx.h" #include <windows.h> #include <stdio.h> #include "winio.h" #define DATA 0x378 #define STATUS 0x379 int _outp( unsigned short add,int val) { if (SetPortVal(add,val,1))return 1; return 0; } int inport(unsigned short add) { unsigned long val; GetPortVal(add,&val,1); return val; } void delay(int time)//延时 { for(int i=0;i<10*time;i++); } /***********void i2cstart()***********/ void i2cstart() { //_outp(0x378,0xff);/*scl 1, sda 1*/ BYTE outvalue; outvalue=0; /*低电平*/ _outp(DATA,1); delay(1);/**/ outvalue=1; /*高电平*/ _outp(DATA,0); delay(1); } /***********void i2cstop()***********/ void i2cstop() { BYTE outvalue; outvalue=1; /*高电平*/ _outp(DATA,0); delay(1);/**/ outvalue=0; /*低电平*/ _outp(DATA,1); delay(1);/***/ } /***********writebyte()***********/ writebyte(char s) { short int a=7; char d,e; BYTE DI,DO; _outp(DATA,DI);/*scl 0, sda 0*/ delay(1);/***/ while(a>=0) { d=s>>a; d=d<<7; if (d=='x80')/*****"1"***/ { _outp(DATA,DO);/*scl 0, sda 1*/ delay(1);/***/ _outp(DATA,DO);/*scl 1, sda 1*/ } else { _outp(DATA,DI);/*scl 0, sda 0*/ delay(1);/***/ _outp(DATA,DI);/*scl 1, sda 0*/ } a=(a-1); } /**ask**/ delay(1);/***/ _outp(DATA,DO);/*scl 0, sda 1*/ delay(1);/***/ _outp(DATA,DO);/*scl 1, sda 1*/ delay(1);/***/ _outp(DATA,DO);/*scl 0, sda 1*/ delay(1);/***/ e=_inp(0x379); d=e>>4; d=d<<7; if (d=='x0') return 0; else printf("not acknowledge!n"); return 1; } /***********readbyte()***************/ char readbyte() { unsigned short a=8; char d,e,f='x0'; while(a>0) { delay(1);/***/ _outp(0x378,DO);/*scl 0, sda 1*/ delay(1);/***/ _outp(DATA,DO);/*scl 1, sda 1*/ delay(1);/***/ e=_inp(0x379); d=e>>4; d=d<<7; if(d=='x80') d='x1'; f=f<<1; f=(f+d); a=(a-1); _outp(DATA,DO);/*scl 0, sda 1*/ delay(1);/***/ } return f; } /************mainask()*****************/ void mainask() { delay(1);/**/ _outp(DATA,DI);/*scl 0, sda 0*/ delay(1);/**/ _outp(DATA,DI);/*scl 1, sda 0*/ delay(1); _outp(DATA,DI);/*scl 0, sda 0*/ } /*************************************/ int main(int argc, char* argv[]) { DWORD dwPortVal; DWORD dwMemVal; bool bResult; HANDLE hPhysicalMemory; PBYTE pbLinAddr; // Call InitializeWinIo to initialize the WinIo library. bResult = InitializeWinIo(); if (bResult) { // Under Windows NT/2000/XP, after calling InitializeWinIo, // you can call _inp/_outp instead of using GetPortVal/SetPortVal SetPortVal(0x378,127, 1); GetPortVal(0x378, &dwPortVal, 1); unsigned short a,b,c,g; char d,e,f; //textcolor(2); //clrscr(); printf("press 'r' or 'w' :"); scanf("%c",&f); if(f=='w') { /************ W 256 BYTES ****/ e='x0'; c=32; /* 24lc02: 32=256/8 */ while(c>0) { i2cstart();/*****start****/ writebyte('xa0');/***send contbyte***/ writebyte(e);/***send start address***/ /************W 8 bytes****/ b=8; d='x0'; /* num */ while(b>0) { if ((writebyte(d))==1) exit(0);/***send a byte***/ b=(b-1);d=(d+1); } i2cstop(); delay(40); /****writer delay****/ c=(c-1);e=(e+8); } printf("please import write address:"); scanf("%x",&b); exit(0); } if(f=='r') { /****** read ***********************************/ printf("please import start address:"); scanf("%x",&b); a=(256-b); c=(a%8); a=(a/8); while(a>0) { g=8; i2cstart();/*****start****/ writebyte('xa0');/***send contbyte***/ d=(char)b;/****/ writebyte(d);/***send start address***/ i2cstart();/*****start****/ writebyte('xa1');/***send contbyte***/ while(g>0){ d=readbyte(); if(d=='xff') printf(" FF"); else printf(" %.2X",d); g=(g-1); if(g>0) mainask(); b=(b+1); } i2cstop(); a=(a-1); } while(c>0){ i2cstart();/*****start****/ writebyte('xa0');/***send contbyte***/ d=(char)b;/****/ writebyte(d);/***send start address***/ i2cstart();/*****start****/ writebyte('xa1');/***send contbyte***/ d=readbyte(); if(d=='xff') printf(" FF"); else printf(" %.2X",d); c=(c-1); if(c>0) mainask(); } printf("nREAD OK!n"); exit(0); } else {printf("nCommand Error!!!"); exit(0);} ShutdownWinIo(); } else { printf("Error during initialization of WinIo.n"); exit(1); } } |
|