interfacing MMA7660FC with at89s52
Tue Mar 15 2011, 01:38 am
The flow of your program is not clear.
It probably crashes somewhere near..
I suggest you put your assembly start up code into a "C" function to get it
out of the way.
It probably crashes somewhere near..
mov r7,#98h // device address 0x98 mov r6,#00h // starting address mov r5,#99h // read mode call read_block mov a,r0 init: setb sda setb scl ret
I suggest you put your assembly start up code into a "C" function to get it
out of the way.
Wed Mar 16 2011, 12:47 pm
I do not know how you and your controller mma7660fc interface, can provide your schematic, so I can help you better?
Wed Mar 16 2011, 11:39 pm
still does not work.
#include<reg51.h> sbit SDA = P3^6; sbit SCL = P3^7; #define stepper P1 void motor_cw(unsigned int); void delay(); void i2c_acc(); void main(void) { unsigned int x_axis=0; i2c_acc(); if(ACC> =0x00 && ACC<=0x16) { x_axis=((((-149*ACC)/1000)*ACC-(64*ACC)/1000+78)*10)/72; motor_cw(x_axis); } else if(ACC> =0x2B && ACC<=0x3F) { x_axis=((((180*ACC)/1000)-(23*ACC)+824)*10)/72; motor_cw(x_axis); } } void i2c_acc(void) { #pragma asm mov scon,#0x50 // initilaizing serial port at 9600 @ 11.0592MHz mov tmod,#0x20 mov th1,#0xfd mov tl1,#0xfd setb tr1 acall init //active mode mov r7,#98h // device address 0x98 mov r6,#07h // write to mode reg mov r5,#01h // write mode reg to 00000001 acall write_byte // all is done in this function mov 0x41,#20 call delayms mov 0x41,#20 call delayms mov r7,#98h // device address 0x98 mov r6,#00h // starting address mov r5,#99h // read mode call read_block mov a,r0 init: setb sda setb scl ret read_block: call start jc x35 mov a,r7 call shout jc x34 mov a,r6 call shout jc x34 call start jc x34 mov a,r5 //read form mma7660 read addres 0x99 call shout jc x34 // read from register 0 call shin mov r0,a call ACK // read from register 1 call shin mov r1,a call ACK // read from register 2 call shin mov r2,a call ACK call NAK clr c x34: call stop x35: ret write_byte: call start jc x49 mov a,r7 call shout jc x48 mov a,r6 call shout jc x48 mov a,r5 call shout jc x48 clr c x48: call stop x49: ret start: setb SDA setb SCL jnb SDA, x40 jnb SCL, x40 nop clr SDA nop nop nop nop nop clr SCL clr c jmp x41 x40: setb c x41: ret stop: clr SCL clr SDA nop nop setb SCL nop nop nop nop nop setb SDA ret shout: mov b, #8 x42: rlc a mov SDA, c nop setb SCL nop nop nop nop clr SCL djnz b, x42 setb SDA nop nop setb SCL nop nop nop nop mov c, SDA clr SCL ret shin: setb SDA mov b, #8 x43: nop nop nop setb SCL nop nop mov c, SDA rlc a clr SCL djnz b, x43 ret ACK: clr SCL clr SDA nop nop setb SCL nop nop nop nop clr SCL ret NAK: clr SCL setb SDA nop nop setb SCL nop nop nop nop clr SCL ret delayms: mov 0x40,#230 d: nop nop djnz 0x40,d djnz 0x41,delayms ret #pragma endasm } void motor_cw(unsigned int cntrx) { unsigned int a; for(a=0;a<cntrx;a++) { stepper = 0x08; delay(); stepper = 0x0C; delay(); stepper = 0x04; delay(); stepper = 0x06; delay(); stepper = 0x02; delay(); stepper = 0x03; delay(); stepper = 0x01; delay(); stepper = 0x09; delay(); } } void delay() { unsigned char l,m,n; for(l=0;l<6;l++) for(m=0;m<255;m++) for(n=0;n<255;n++); }
Wed Mar 16 2011, 11:51 pm
when a source code is generated for this file it always shows a continuous loop even though the program is designed such that it must run once. can anyone comment on that. it is in the main: segment. there is a ret before end of main program. also the source code has essentially converted the lengthy if else condition and the formula in assembly level code. can somebody help me integrating that in the assembly code that is already working???? is it prudent to do so.....
Thu Mar 17 2011, 02:46 am
Now it crashes near
To run just once add a while loop..
Try a simpler test for now, such as
} else if(ACC> =0x2B && ACC<=0x3F) { x_axis=((((180*ACC)/1000)-(23*ACC)+824)*10)/72; motor_cw(x_axis); } } }
To run just once add a while loop..
} else if(ACC> =0x2B && ACC<=0x3F) { x_axis=((((180*ACC)/1000)-(23*ACC)+824)*10)/72; motor_cw(x_axis); } while(1); }
Try a simpler test for now, such as
if(ACC> =60) motor_cw(5); else motor_acw(5);
omega123 like this.
Sat Mar 19 2011, 07:06 pm
@experimenterUK i tried what u told....and for once it worked. i set the accelerometer in test mode, wrote the value 1 to the X axis register and then put the condition that
it worked.
if(x1==1) motor_cw(1); else motor_cw(2);
it worked.
Sun Mar 20 2011, 10:19 am
@ omega123
can u upload ur final project folder which u make now
i am trying to mixing asm and c as u try but in this manner some error comes
can u upload ur final project folder which u make now
i am trying to mixing asm and c as u try but in this manner some error comes
Powered by e107 Forum System