proteus 仿真AD5241程序。。8位数字电位计
#include
#include
#include
#include "skey.c"
#define uchar unsigned char
#define uint unsigned int
#define START 0X08
#define MT_SLA_ACK 0X18
#define MT_SLA_NOACK 0X20
#define MT_DATA_ACK 0X28
#define MT_DATA_NOACK 0X30
#define Start() (TWCR=(1 void twi_init() void main()
#define SetACK() (TWCR|=(1
{
TWBR=0X20;
TWSR=0;
TWCR=0X44;//时能twi应答。twi使能
}
//手册172页
uchar AD5241_writeB(uchar devadd,uchar cmd,uchar rdata)
{
Start();
Wait();
if(TestACK()!=START)
return 0;
Writebyte(devadd);
Wait();
if(TestACK()!=MT_SLA_ACK)
return 0;
Writebyte(cmd);
Wait();
if(TestACK()!=MT_DATA_ACK)
return 0;
Writebyte(rdata);
Wait();
if(TestACK()!=MT_DATA_ACK)
return 0;
Stop();
delay(10);
return 1;
}
{
uchar i,data=128;
twi_init();
AD5241_writeB(0x58,0x10,0);
delay(10);
AD5241_writeB(0x58,0x10,data);//
while(1)
{
if(key_press())
{
i=key_scan();
switch(i)
{
case 0:
data-=16;break;
case 1:
data+=16;break;
case 2:
data=0;break;
case 3:
data=255;break;
}
}
AD5241_writeB(0x58,0,data);
}
}
proteusAD5241程序数字电位 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)