savvej
Member
In the following code I am trying to send 6 bits of data serially(synchronously) ,with data to be latched on the peripheral on falling edge of clock.
I am using atmega8 with internal oscillator of 1MHz.Using win-avr compiler library and optimization O2 in AVR studio(4.18).
The following is the function:
void Send_Command(unsigned char command)
{
unsigned char i,temp=0;
//setting DATA PIN as OUTPUT
CRTL_PORT_DIR|=(1<<DATA);
for(i=0;i<6;i++)
{
//~~~Changing Data~~~
CRTL_PORT|=(1<<CLOCK);//clock=1
temp=((command>>i) & 0x01);//on DATA(PD0) pin
if(temp)
CRTL_PORT|=(1<<0);
else
CRTL_PORT&=~(1<<0);
_delay_us(1);
CRTL_PORT&=~(1<<CLOCK);//clock=0
_delay_us(1);
}
}
Now when i send "command=0b00000010" ans argument,and simulate the function in Proteus ,I get increasing delay in consecutive clock cycles which is not understandable by me.
I have attached the "Digital Analysis " snapshot with the post. also my c code(which is actually partially complete code to program PIC16f628A).
I am using atmega8 with internal oscillator of 1MHz.Using win-avr compiler library and optimization O2 in AVR studio(4.18).
The following is the function:
void Send_Command(unsigned char command)
{
unsigned char i,temp=0;
//setting DATA PIN as OUTPUT
CRTL_PORT_DIR|=(1<<DATA);
for(i=0;i<6;i++)
{
//~~~Changing Data~~~
CRTL_PORT|=(1<<CLOCK);//clock=1
temp=((command>>i) & 0x01);//on DATA(PD0) pin
if(temp)
CRTL_PORT|=(1<<0);
else
CRTL_PORT&=~(1<<0);
_delay_us(1);
CRTL_PORT&=~(1<<CLOCK);//clock=0
_delay_us(1);
}
}
Now when i send "command=0b00000010" ans argument,and simulate the function in Proteus ,I get increasing delay in consecutive clock cycles which is not understandable by me.
I have attached the "Digital Analysis " snapshot with the post. also my c code(which is actually partially complete code to program PIC16f628A).