what is bit-banging ?
bit banging in simple world would be sending bit by bit on one port or more than 2 ports .
eg. to send 0x01 we need to send 0000,0001 serially on one port. same as in usart/spi/twi
just that we need to create clock and send-recieve data on software basis
here is an example i wrote to interface with adns-2610 but its not working i idk y
'
#include <avr/io.h>
#include <mrlcd.h>
#include <stdlib.h>
#include <util/delay.h>
#define Delta_y 0x02
#define CLK 0
#define DATA 1
void init_adns2610()
{ // toggle clk from high to low to high
DDRB|=(1<<CLK);
PORTB|=(1<<CLK);
_delay_us(5);
PORTB &=~(1<<CLK);
_delay_us(1);
PORTB|=(1<<CLK);
GotoMrLCDsLocation(1,2);
Send_A_String("R");
_delay_ms(90); // wait for atleast 90ms for timer to timeout
// for resync
}
uint8_t read_byte(uint8_t address)
{
DDRB = (1<<CLK)|(1 << DATA); // data line and clk as output
uint8_t mask = 0x80;
_delay_ms(1);
for (mask=0x80; mask; mask>>1)
{
PORTB &= ~(1 << CLK); // set clock line low
_delay_us(4);
if (address & mask)
{
PORTB |= (1 << DATA);
}
else
{
PORTB &= ~(1 << DATA);
}
_delay_us(4);
PORTB |= (1 << CLK); // clock the bit out
}
uint8_t input=0x00;
Send_A_String("rud");
_delay_us(100); // time period between read and write
mask=0x00;
DDRB &=~(1<<DATA);
for (mask=0x80; mask; mask>>1)
{
if (PINB & (1 << DATA))
{
input |= mask;
}
_delay_us(4);
PORTB &= ~(1 << CLK); // clock the bit low
_delay_us(4);
PORTB = (1 << CLK); // set clock line high
}
_delay_us(100);
return input;
}
int main(void)
{ init_adns2610();
char x1[10];
while (1)
{
uint8_t x=read_byte(Delta_y); //give address of Delta y register
GotoMrLCDsLocation(1,2);
Send_A_String("RUDRESH");
itoa (x,x1,10);
GotoMrLCDsLocation(1,1);
Send_A_String(x1);
_delay_ms(10);
}
}
'
now the problem with this program i don knw where the problem is
but there's nothing in the program that should stop it from working (i assume so :mrgreen:)
plz have a look on the program and datasheet and please point out where is the mistake
may be some in timing the clock
