No.95124 作者:alone6230 邮件:alone6230@sina.com ID:56102 登陆:1次 文章数:1篇 最后登陆IP:221.216.9.229 最后登陆:2006/6/30 13:19:33 注册:2006/6/28 14:21:16 财富:105 发帖时间:2006/6/28 14:32:11 发贴者IP:221.218.68.79 标题:alone6230:请教关于MEGA16L和AT24C512通信的问题 摘要:No.95124请教关于MEGA16L和AT24C512通信的问题 我初学MEGA16 一下代码运行到函数“stop()"的时候就出错了——估计是#define stop 0X30 有问题 可是我也不知道应该值是多少。 我的本意是向AT24C512写入数组 data[8], 再读入MEGA16,然后求数组的和; 写入前和为0 读出后和不为0. 能否请高手帮忙看看问题出在什么地方! #include <mega16.h> #include <iom16v.h> #include <macros.h> #define START 0x08 #define MT_SLA_ACK 0x18 #define MR_SLA_ACK 0x40 #define STOP 0x30 void start_i() //initialise Mega16 start { while (!(TWCR & (1 < <TWINT))) TWCR=(1 < <TWINT)|(1 < <TWSTA)|(1 < <TWEN); if ((TWSR & 0XF8)!= START) ERROR_l(); } //following function sends a "start" byte to AT24C512, //including device address and a read state code(the last 1) void read_a() { while (!(TWCR & (1 < <TWINT))) { TWDR=0XA1; TWCR=(1 < <TWINT)|(1 < <TWEN); if ((TWSR &0XF8)!=MR_SLA_ACK ) ERROR_l(); } } //following function read one bit and save it in data_r int read_b () { int data_r=0; while (!(TWCR & (1 < <TWINT))) { data_r=TWDR; TWCR=(1 < <TWINT)|(1 < <TWEN); if ((TWSR &0XF8)!=MR_SLA_ACK ) ERROR_l(); return data_r; } } //following function sends a "start" byte to AT24C512, //including device address and a write state code(the last 0) void write_d_a() { while (!(TWCR & (1 < <TWINT))) { TWDR=0XA0; TWCR=(1 < <TWINT)|(1 < <TWEN); if ((TWSR &0XF8)!=MT_SLA_ACK ) ERROR_l(); } } void write_w_a(int a,int b) { while (!(TWCR & ( ......
>>返回讨论的主题
|