資源簡(jiǎn)介
通過ATTINY24A 芯片,IIC作為slave 接收數(shù)據(jù)并控制直流電機(jī)程序,親自測(cè)試好用

代碼片段和文件信息
#include?
#include?“ioavr.h“
#include?“inavr.h“
#include?“USI_TWI_Slave.h“
extern?uint8_t?TWI_RxBuf[TWI_RX_BUFFER_SIZE];
extern??unsigned?char?TWI_slaveAddress;
extern?unsigned?char?data?;
unsigned?char?RX_data[4];
unsigned?char?i?=0;
void?DC_Motor_Set(unsigned?char?Indexunsigned?char?Dirunsigned?short?Speed)
{??
???unsigned?short?pwm?=Speed*255/100;
???switch(Index)
?????{
?????case?0:??if(Dir==1){
??????????????????
??????????????????PORTA|=BIT(2);?PORTA&=~BIT(3);
???????????????????PORTA|=BIT(1);?PORTA&=~BIT(0);
?????????????????}
??????????????else{
??????????????????PORTA|=BIT(0);?PORTA&=~BIT(1);
??????????????????PORTA|=BIT(3);?PORTA&=~BIT(2);
??????????????}
??????????????OCR0A?=?pwm;
??????????????OCR0B?=?pwm;
??????????????break;
?????case?1:??
??????????????if(Dir==1)
?????????????????{
????????????????????PORTA|=BIT(1);?PORTA&=~BIT(0);
?????????????????}
??????????????else?
?????????????????{
????????????????????
????????????????????PORTA|=BIT(0);?PORTA&=~BIT(1);
?????????????????}
???????????????
??????????????OCR0A?=?pwm;
??????????????break;
?????case?2:??if(Dir==1)
?????????????????{
???????????????????PORTA|=BIT(2);?PORTA&=~BIT(3);
?????????????????}
??????????????else?
?????????????????{
???????????????????PORTA|=BIT(3);?PORTA&=~BIT(2);
?????????????????}
??????????????OCR0B?=?pwm;?
??????????????break;
?????default:?OCR0B?=?0x00;
??????????????OCR0A?=?0x00;?
??????????????break;
?????
?????}
}
void?main(void)
{?
??unsigned?char?TWI_slaveAddress=0;
??CLKPR?=?0x80;//配置內(nèi)部時(shí)鐘??????8M晶振
??DDRA?|=BIT(0);DDRA?|=BIT(1);DDRA?|=BIT(2);DDRA?|=BIT(3);
??DDRB?|=BIT(2);DDRA?|=BIT(7);
??PORTA|=BIT(3);?PORTA&=~BIT(2);
??PORTA|=BIT(1);?PORTA&=~BIT(0);
??
??
??TCCR0A?=?0XA3;TCCR0B?=?0X01;OCR0B??=?0;?OCR0A??=?0;
??TWI_slaveAddress?=?0x50;
??USI_TWI_Slave_Initialise(?TWI_slaveAddress?);
??__enable_interrupt();
??while(1)
??{???
??????if(?USI_TWI_Data_In_Receive_Buffer()?)
??????????{
?????????????RX_data[i++]??=?USI_TWI_Receive_Byte();
?????????????if(RX_data[0]==0xA3&&i==4)
??????????????{
????????????????i=0;
????????????????DC_Motor_Set(RX_data[1]RX_data[2]RX_data[3]);
??????????????}
?????????}
??}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2493??2018-03-19?17:08??Ex_DCMotor\Debug\Exe\Ultransic.hex
?????文件???????4008??2018-03-19?17:08??Ex_DCMotor\Debug\Exe\Ultransic.sym
?????文件?????105374??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\main.pbi
?????文件??????10826??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\main.pbi.cout
?????文件??????19836??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\main.r90
?????文件?????110454??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\Ultransic.pbd
?????文件?????110454??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\Ultransic.pbd.browse
?????文件?????103821??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\USI_TWI_Slave.pbi
?????文件??????10835??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\USI_TWI_Slave.pbi.cout
?????文件??????25837??2018-03-19?17:08??Ex_DCMotor\Debug\Obj\USI_TWI_Slave.r90
?????文件??????88958??2011-09-04?18:01??Ex_DCMotor\Debug\progisp172\config.xm
?????文件????????417??2009-12-30?10:06??Ex_DCMotor\Debug\progisp172\eng\93c46.xm
?????文件???????1283??2010-02-09?11:29??Ex_DCMotor\Debug\progisp172\eng\A25L40P.xm
?????文件???????1029??2009-03-29?09:16??Ex_DCMotor\Debug\progisp172\eng\AT1358.xm
?????文件????????391??2008-11-11?21:21??Ex_DCMotor\Debug\progisp172\eng\AT24C01.xm
?????文件????????559??2010-02-09?11:34??Ex_DCMotor\Debug\progisp172\eng\AT25DF021.xm
?????文件???????1286??2010-02-09?11:32??Ex_DCMotor\Debug\progisp172\eng\AT25DF041A.xm
?????文件???????1286??2010-02-09?11:32??Ex_DCMotor\Debug\progisp172\eng\AT25DF081.xm
?????文件???????1286??2010-02-09?11:32??Ex_DCMotor\Debug\progisp172\eng\AT25DF161.xm
?????文件???????1286??2010-02-09?11:31??Ex_DCMotor\Debug\progisp172\eng\AT25DF321.xm
?????文件???????1287??2010-02-09?11:31??Ex_DCMotor\Debug\progisp172\eng\AT25DF321A.xm
?????文件???????1286??2010-02-09?11:31??Ex_DCMotor\Debug\progisp172\eng\AT25DF641.xm
?????文件????????553??2010-01-05?09:44??Ex_DCMotor\Debug\progisp172\eng\AT25DFxx.xm
?????文件???????1284??2010-02-09?11:31??Ex_DCMotor\Debug\progisp172\eng\AT25F512B.xm
?????文件???????1285??2010-02-09?11:31??Ex_DCMotor\Debug\progisp172\eng\AT25FS010.xm
?????文件???????1285??2010-02-09?11:30??Ex_DCMotor\Debug\progisp172\eng\AT25FS040.xm
?????文件???????1285??2010-02-09?11:30??Ex_DCMotor\Debug\progisp172\eng\AT26DF041.xm
?????文件???????1287??2010-02-09?11:30??Ex_DCMotor\Debug\progisp172\eng\AT26DF081A.xm
?????文件???????1286??2010-02-09?11:30??Ex_DCMotor\Debug\progisp172\eng\AT26DF161.xm
?????文件???????1287??2010-02-09?11:29??Ex_DCMotor\Debug\progisp172\eng\AT26DF161A.xm
............此處省略229個(gè)文件信息
- 上一篇:基于雙目立體視覺的三維重建
- 下一篇:STM32F103 多路ADC 采集
評(píng)論
共有 條評(píng)論