ok史上最帅青年 ok史上最帅青年
不用为逝者流泪。死亡,是一首所有人都会听到的歌曲。
关注数: 15 粉丝数: 67 发帖数: 1,747 关注贴吧数: 35
哪位大神帮忙看一下,这样EEPROM为什么总是寄存不了? #include <reg51.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int sfr ISP_DATA = 0xe2; sfr ISP_ADDRH = 0xe3; sfr ISP_ADDRL = 0xe4; sfr ISP_CMD = 0xe5; sfr ISP_TRIG = 0xe6; sfr ISP_CONTR = 0xe7; sbit key = P3^2; sbit key2 = P3^3; sbit key3 = P3^4; sbit key4 = P3^5; sbit motoA= P1^1; sbit motoB= P1^2; sbit motoC= P1^3; sbit motoD= P1^4; int a,b,c; int x,y,z; void erasure(uint addr); void write(uint addr,uchar dat); uchar read(uint addr); void Q0(); void motor1(uint dir); void motor2(uint rollove); void delay(uchar i); void main(void) { uint keystate = 0 ; char dirstate = 0; uint condition = 0; char rollove = 0; b = read(0x2002); c = read(0x2003); a = c | b<<8; y = read(0x2004); z = read(0x2005); x = z | y<<8; while(1) { if(key==0) { delay(5); if(key==0) { keystate =~ keystate ; while(!key); erasure(0x2000); write(0x2002,a); write(0x2003,a>>8); write(0x2004,x); write(0x2005,x>>8); } } if(key2==0) { delay(5); if(key2==0) { dirstate ^= 0x01 ; while(!key2); } } if(keystate) { if( (a >= 21950 && dirstate== 1) || (a <= 0 && dirstate== 0) || (a < 21950 && a > 0)) { if( (a >= 21950 && dirstate== 1) || (a <= 0 && dirstate== 0) || (a < 21950 && a > 0)) { motor1(dirstate); } } } if(key3==0) { delay(5); if(key3==0) { condition =~ condition ; while(!key3); erasure(0x2000); write(0x2002,a); write(0x2003,a>>8); write(0x2004,x); write(0x2005,x>>8); } } if(key4==0) { delay(5); if(key4==0) { rollove ^= 0x01 ; while(!key4); } } if( (a >= 21950 && rollove== 1) || (a <= 0 && rollove== 0) || (a < 21950 && a > 0)) { if( (x >= 21950 && rollove == 0) || (x <= 0 && rollove== 1) || (x < 21950 && x > 0)) { if(condition) motor2(rollove); } } } } void erasure(uint addr) { ISP_CONTR = 0x81; ISP_CMD = 0x03; ISP_ADDRL = addr; ISP_ADDRH = addr>>8; EA =0; ISP_TRIG = 0x46; ISP_TRIG = 0xB9; _nop_(); Q0(); } void write(uint addr,uchar dat) { ISP_CONTR = 0x81; ISP_CMD = 0x02; ISP_ADDRL = addr; ISP_ADDRH = addr>>8; ISP_DATA = dat; EA = 0; ISP_TRIG = 0x46; ISP_TRIG = 0xB9; _nop_(); Q0(); } uchar read(uint addr) { uchar dat; ISP_CONTR = 0x81; ISP_CMD = 0x01; ISP_ADDRL = addr; ISP_ADDRH = addr>>8; EA = 0; ISP_TRIG = 0x46; ISP_TRIG = 0xB9; _nop_(); dat = ISP_DATA; Q0(); return dat; } void Q0() { ISP_CONTR = 0; ISP_CMD = 0; ISP_TRIG = 0; } void motor1(uint dir) { if(dir) { motoA = 0; motoC = 0; delay(10); motoA = 1; motoC = 1; delay(10); motoB = 1; motoD = 1; a--; x--; } else { motoA = 0; motoC = 0; delay(10); motoA = 1; motoC = 1; delay(10); motoB = 0; motoD = 0; a++; x++; } } void motor2(uint rollove) { if(rollove) { motoA = 0; motoC = 0; delay(10); motoA = 1; motoC = 1; delay(10); motoB = 1; motoD = 0; a--; x++; } else { motoA = 0; motoC = 0; delay(10); motoA = 1; motoC = 1; delay(10); motoB = 0; motoD = 1; a++; x--; } } void delay(uchar i) { while(i--); } 源程序如上。 用途是用来控制两只二相四线电机,里面的motor都是控制电机的引脚。然后想设计一个能寄存每次转到的位置,可就是断电后有问题。请问是哪里出了错误? 用的是STC89C52RC 也有STC90C52RC的,都不行
1 下一页