johnwattcorp
Joined: 26 Jan 2006 Posts: 1
|
Useful mcp41010 and ad8400 driver for beginners |
Posted: Fri Jan 19, 2007 8:57 am |
|
|
This driver is new version of mcp41010.c
Code: | #define CS PIN_B4
#define SCLK PIN_B5
#define SI PIN_B6
void set_pot (int data) {
BYTE i;
BYTE cmd[2];
cmd[0] = data;
cmd[1] = 0x11;
setup_pot();
output_high(CS);
output_low(SCLK);
delay_ms(1);
output_low(CS);
output_low(SCLK);
delay_ms(1);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
delay_us(2);
output_low(SCLK);
}
output_high(CS);
output_low(SI);
output_low(SCLK);
}
void shutdown_pot () {
BYTE i;
BYTE cmd[2];
cmd[0] = 0;
cmd[1] = 0x21;
output_low(SCLK);
output_low(CS);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}
void setup_pot() {
delay_ms(1);
output_low(CS);
delay_cycles(1);
output_high(CS);
delay_cycles(1);
} |
|
|