資源簡介
利用pca9685驅動板驅動9個舵機 甚至更多舵機。

代碼片段和文件信息
#include???????????
#include???
#include?
#include?
typedef??unsigned?char??uchar;????????
typedef??unsigned?int???uint;????????
unsigned?char?buf;
sbit?scl=P2^6;??????????????????????
sbit?sda=P2^7;??????????????????
#define?PCA9685_adrr?0x80//??1+A5+A4+A3+A2+A1+A0+w/r?
#define?PCA9685_SUBADR1?0x2
#define?PCA9685_SUBADR2?0x3
#define?PCA9685_SUBADR3?0x4
#define?PCA9685_MODE1?0x0
#define?PCA9685_PRESCALE?0xFE
#define?LED0_ON_L?0x6
#define?LED0_ON_H?0x7
#define?LED0_OFF_L?0x8
#define?LED0_OFF_H?0x9
#define?ALLLED_ON_L?0xFA
#define?ALLLED_ON_H?0xFB
#define?ALLLED_OFF_L?0xFC
#define?ALLLED_OFF_H?0xFD
#define?SERVOMIN??115?//?this?is?the?‘minimum‘?pulse?length?count?(out?of?4096)
#define?SERVOMAX??590?//?this?is?the?‘maximum‘?pulse?length?count?(out?of?4096)
#define?SERVO000??130?//0度
#define?SERVO180??520?//180度
#define?SERVO80???284?//80度
#define?SERVO110??340//110度
void?delayms(uint?z)
{
??uint?xy;
??for(x=z;x>0;x--)
??????for(y=148;y>0;y--);
}
void?delayus()??//大于4.7us
{
??????????_nop_();?????????
????????????????_nop_();
????????????????_nop_();
????????????????_nop_();
????????????????_nop_();
}
/*---------------------------------------------------------------
?????????????????IIC初始化?
----------------------------------------------------------------*/
void?init()
{
????sda=1;????????????????//sda?scl使用前被拉高
????delayus();
????scl=1;
????delayus();
}
/*---------------------------------------------------------------
?????????????????IIC????????
----------------------------------------------------------------*/
void?start()
{
????sda=1;
????delayus();
????scl=1;???????//scl高?sda拉低?????IIC啟動
????delayus();
????sda=0;
????delayus();
scl=0;
delayus();
}
/*---------------------------------------------------------------
?????????????????IIC停止
----------------------------------------------------------------*/
void?stop()
{
????sda=0;
????delayus();
????scl=1;?????????????????????????//scl????sda????????????IIC??
????delayus();
????sda=1;???????????????????
????delayus();
}
/*---------------------------------------------------------------
?????????????????IIC應答
----------------------------------------------------------------*/
void?ACK()
{
????uchar?i;
????scl=1;
????delayus();
????while((sda=1)&&(i<255))?????????
????????????????i++;????????????????????????????????????????
????scl=0;??????????????????????????????????
????delayus();
}
/*---------------------------------------------------------------
??????????????寫字節
----------------------------------------------------------------*/
void?write_byte(uchar?byte)
{
????uchar?itemp;
????temp=byte;
????for(i=0;i<8;i++)
????{
????????temp=temp<<1;??
????????scl=0;??????????????????
????????????????????????????????delayus();
????????????????????????????????sda=CY;?????????????????
????????????????????????????????delayus();
???????????????????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-24?13:40??pca9685驅動板驅動9個舵機\
?????文件????????6376??2012-12-10?10:20??pca9685驅動板驅動9個舵機\STARTUP.A51
?????文件???????14054??2014-05-11?11:27??pca9685驅動板驅動9個舵機\STARTUP.LST
?????文件?????????749??2014-05-11?11:27??pca9685驅動板驅動9個舵機\STARTUP.OBJ
?????文件???????17477??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo
?????文件?????????971??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.build_log.htm
?????文件????????9127??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.c
?????文件????????6184??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.hex
?????文件??????????45??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.lnp
?????文件???????14768??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.LST
?????文件???????19144??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.M51
?????文件???????18241??2017-09-24?11:50??pca9685驅動板驅動9個舵機\yidengshanshuo.OBJ
?????文件?????????993??2017-09-24?13:40??pca9685驅動板驅動9個舵機\yidengshanshuo.Opt
?????文件?????????197??2015-08-15?12:15??pca9685驅動板驅動9個舵機\yidengshanshuo.plg
?????文件????????2161??2017-09-11?00:49??pca9685驅動板驅動9個舵機\yidengshanshuo.Uv2
?????文件?????????993??2017-09-24?11:40??pca9685驅動板驅動9個舵機\yidengshanshuo_Opt.Bak
?????文件????????2166??2015-04-26?22:55??pca9685驅動板驅動9個舵機\yidengshanshuo_Uv2.Bak
- 上一篇:中山大學數電實驗大作業
- 下一篇:弱密碼字典**弱密碼字典
評論
共有 條評論