//mcp41010.c#includeavr/io.h#definer_full9340#definecs_ddrDDRA#definecs_portPORTA#definesck_ddrDDRA#definesck_portPORTA#definesi_ddrDDRA#definesi_portPORTA#definecs0x01#definesck0x02#definesi0x04voidr_io_init(void){cs_ddr|=cs;sck_ddr|=sck;si_ddr|=si;cs_port|=cs;sck_port&=~sck;si_port&=~si;}voidwrite_r(unsignedcharcmd,unsignedchardat)//cmd=0x11:writedata;cmd=0x31:cutoff{unsignedcharcount=0;sck_port&=~sck;si_port&=~si;cs_port&=~cs;sck_port|=sck;//0sck_port&=~sck;sck_port|=sck;//1sck_port&=~sck;if(cmd&0x20)si_port|=si;elsesi_port&=~si;sck_port|=sck;//2sck_port&=~sck;if(cmd&0x10)si_port|=si;elsesi_port&=~si;sck_port|=sck;//3sck_port&=~sck;si_port&=~si;sck_port|=sck;//4sck_port&=~sck;sck_port|=sck;//5sck_port&=~sck;if(cmd&0x02)si_port|=si;elsesi_port&=~si;sck_port|=sck;//6sck_port&=~sck;if(cmd&0x01)si_port|=si;elsesi_port&=~si;sck_port|=sck;//7sck_port&=~sck;for(count=0;count8;count++){if(dat&0x80)si_port|=si;elsesi_port&=~si;sck_port|=sck;sck_port&=~sck;dat=dat1;}cs_port|=cs;}voidr_init(void){r_io_init();write_r(0x11,0x7f);}voidset_r(unsignedintr){floatbuf0=0;unsignedcharbuf1=0;buf0=r_full/255;buf0=r/buf0;buf1=(unsignedchar)buf0;write_r(0x11,buf1);}//main.c#includeavr/io.hintmain(void){r_init();while(1){//set_r(4800);}}