English
Language : 

N40P112 Datasheet, PDF (10/34 Pages) ams AG – Push button feature
EasyPointTM N40P112
Datasheet - Using the N40P112 Module
8.3 C Source Code Example
8.3.1 Initialization
void EasyPoint_init (void)
{
unsigned char Reset_status = 0;
RESETn = 0;Delay_ms(1);// RESETn pulse after power up
RESETn = 1; Delay_ms(1);
while (Reset_status != 0xF0)// Check the reset has been done
{
Reset_status = I2C_Read8(0x40, 0x0F) & 0xFE;
}
I2C_Write8(0x40, 0x2d, 0x0D); // Scaling factor for N40 (1.0mm knob travel)
}
8.3.2 Offset Calibration
void Offset_Calibrate (void)
{
char i;
int x_cal=0, y_cal=0;
EA = 0;// Disable the MCU interrupts
I2C_Write8(0x40, 0x0F, 0x00);// Low Power Mode 20ms
Delay_ms(1);
I2C_Read8(0x40, 0x11); // Flush an unused Y_reg to reset the interrupt
for (i=0; i<16; i++)// Read 16 times the coordinates and then average
{
while (INTn);// Wait until next interrupt (new coordinates)
x_cal += (signed char) I2C_Read8(0x40, 0x10); // Read X position
y_cal += (signed char) I2C_Read8(0x40, 0x11); // Read Y position
}
// offset_X and offset_Y are global variables, used for each coordinate readout
in the interrupt routine
offset_X = -(x_cal>>4); // Average X: divide by 16
offset_Y = -(y_cal>>4); // Average Y: divide by 16
EA = 1; // Enable the MCU interrupts
}
www.austriamicrosystems.com/N40P112
Revision 1.1
10 - 34