CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Driver for the ADNS 2051

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
milops3



Joined: 10 May 2012
Posts: 3

View user's profile Send private message

Driver for the ADNS 2051
PostPosted: Fri May 11, 2012 9:24 am     Reply with quote

This is a driver for Avago ADNS 2051, reads the current frame 16x16 pixel.
Code:

//       name      ADNS_2051.c
//    

/*
  Set_serial();      seting I/O for communication
  init_ADNS2051 ();      chip initialization,return product id 0x02
  dumpFrame();          reads actual picture, 16x16 pixels in frame[]
//***************************************************

#define    SCLK    PIN_B0         < in def_ADNS2051.h
#define    SDIO    PIN_B1         <
#define    PD    PIN_B2         <
               
static unsigned int frame[255];      <
*/
//***************************************************
#define REG_PRODUCT_ID 0x00
#define REG_REVISION_ID 0x01
#define REG_MOTION 0x02
#define REG_DELTA_X 0x03
#define REG_DELTA_Y 0x04
#define REG_SQUAL 0x05
#define REG_AVERAGE_PIXEL 0x06
#define REG_MAXIMUM_PIXEL 0x07
#define REG_CONFIG_BITS 0x0A
#define REG_DATA_OUT_LOWER 0x0C
#define REG_DATA_OUT_UPPER 0x0D
#define REG_SHUTTER_LOWER 0x0E
#define REG_SHUTTER_UPPER 0x0F
#define REG_FRAME_PERIOD_LOWER 0x10
#define REG_FRAME_PERIOD_UPPER 0x11
//***************************************************
void Set_serial()
{
 OUTPUT_HIGH(SCLK);
 OUTPUT_FLOAT(SDIO);
 OUTPUT_HIGH(PD);
 delay_us(1);
 OUTPUT_LOW(PD);
}
//***************************************************
void Write_ADNS2051(int8 adr,int8 data)   
{
unsigned char i;
 adr|= 0x80;
 for(i=0;i<8;i++)
   {
   output_low (SCLK); if (adr&128)  output_high(SDIO); else output_low(SDIO);adr=adr<<1; output_high (SCLK);
   }
 for(i=0;i<8;i++)
   {
   output_low (SCLK); if (data&128)  output_high(SDIO); else output_low(SDIO); data=data<<1;output_high (SCLK);
   }
 OUTPUT_FLOAT(SDIO);
}
//***************************************************
unsigned char Read_ADNS2051(int8 adr)   //
{
unsigned char data=0,i;
 for(i=0;i<8;i++)
   {
   output_low (SCLK); if (adr&128)  output_high(SDIO); else output_low(SDIO); adr=adr<<1;output_high (SCLK);
   }
 
 OUTPUT_FLOAT(SDIO);
 delay_us(100);


 for(i=128; i >0 ; i >>= 1)
   {
   output_low (SCLK);output_high (SCLK); output_toggle (PIN_B3);if (input(SDIO)==1) data|= i;
   }

 return data;
}
//***************************************************
unsigned int init_ADNS2051 ()
{
unsigned int datain,P_ID;

 P_ID=Read_ADNS2051(REG_PRODUCT_ID);
 datain=Read_ADNS2051(REG_REVISION_ID);
 datain=Read_ADNS2051(REG_CONFIG_BITS);
 datain |= 0x80;
 Write_ADNS2051(REG_CONFIG_BITS, datain);
 return P_ID;
}
//***************************************************
/*
void dumpDelta()
{
 signed int dx,dy;
 Read_ADNS2051(REG_MOTION);
 dx = Read_ADNS2051(REG_DELTA_X);
 dy = Read_ADNS2051(REG_DELTA_Y);
 // printf("DELTA:");
 printf(" %d",dx);
 printf(" %d",dy); 
 putc(0x0d);
 putc(0x0a);
}
*/
//***************************************************
void dumpFrame()
{
 unsigned int datain,count = 0,dumpWidth = 255;

  datain = Read_ADNS2051(REG_CONFIG_BITS);
  datain |= 0x01;
  Write_ADNS2051(REG_CONFIG_BITS, datain);

  datain = Read_ADNS2051(REG_CONFIG_BITS);
  datain |= 0x08;
  Write_ADNS2051(REG_CONFIG_BITS, datain);

  do
   {
       //pix = Read_ADNS2051(REG_DATA_OUT_UPPER);
       datain = Read_ADNS2051(REG_DATA_OUT_LOWER);
       if( (datain & 0x80) == 0 ) { // Data is valid
            frame[count++] = datain;
          }
     }
  while (count != dumpWidth);



  datain = Read_ADNS2051(REG_CONFIG_BITS);
  datain &= 0xE0;
  Write_ADNS2051(REG_CONFIG_BITS, datain);

}
//***************************************************

an example, view the current images on the LCD Nokia 3310
Code:


#include <18F2320.h>
#include <def_ADNS2051.h>

#device adc=8
 
#FUSES NOWDT                   
#FUSES WDT128                   
#FUSES INTRC                   
#FUSES PUT                     
#FUSES NOBROWNOUT               
#FUSES NOLVP                   
#fuses MCLR
#fuses FCMEN

#use delay(oscillator=8Mhz)
//#use rs232(baud=38400,xmit=PIN_C6,rcv=PIN_C7)

#include <N_3310_DISPLAY.c>      //by Michel Bavin
#include <ADNS_2051.c>
//*************************************************************
//static unsigned int frame[255];      < in def_ADNS2051.h
//*************************************************************
void main()
{
unsigned int p,f,i;
unsigned long t;

 setup_oscillator(OSC_8MHZ);
 OUTPUT_HIGH(pin_A0);
 Set_serial();
 delay_ms (100);
 init_ADNS2051 ();
 nokia_init(1);            //vertikalne - vertical addressing
 nokia_clear_screen();


while(true)
{
 OUTPUT_toggle(pin_A0);       
 dumpFrame();
 nokia_gotoxy(0,0);
 f=0;
 for(p=0;p<32;p++)
   {
   if(frame[f++]<0x1b) pixel[p]|=1;      //0x1b
   if(frame[f++]<0x1b) pixel[p]|=2;
   if(frame[f++]<0x1b) pixel[p]|=4;
   if(frame[f++]<0x1b) pixel[p]|=8;
   if(frame[f++]<0x1b) pixel[p]|=16;
   if(frame[f++]<0x1b) pixel[p]|=32;
   if(frame[f++]<0x1b) pixel[p]|=64;
   if(frame[f++]<0x1b) pixel[p]|=128;
   }
 p=0;
 for(i=0;i<15;i++)
   {
   nokia_write_data(pixel[p]);
   pixel[p]=0;
   p++;

   nokia_write_data(pixel[p]);
   pixel[p]=0;
   p++;
   nokia_gotoxy(i,0);
   }
}

//**********
}

videos
Code:
http://www.youtube.com/watch?v=mVHUqZME2Cc&feature=g-upl
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group