欢迎来到天天文库
浏览记录
ID:55293965
大小:34.00 KB
页数:11页
时间:2020-05-09
《角度传感器ADXL345程序代码(AVR).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/************************************************************角度传感器ADXL345程序代码****************************************************************/#include#include#include#includetypedefunsignedcharuchar;typedefunsignedintuint;/*LCD引脚定义*/#defineCS_setPORTD
2、=BIT(6)#
3、defineCS_clrPORTD&=~BIT(6)#defineSID_setPORTD
4、=BIT(7)#defineSID_clrPORTD&=~BIT(7)#defineSCLK_setPORTB
5、=BIT(0)#defineSCLK_clrPORTB&=~BIT(0)/*ADXL345角度传感器端口定义*/#defineSDA_setPORTC
6、=(1<<4)#defineSDA_clrPORTC&=~(1<<4)#defineSDA_inDDRC&=~(1<<4)#defineSDA_outDDRC
7、=(1<<4)#defineSDA_RPINC&(1<<4)#defineS
8、CL_setPORTC
9、=(1<<5)#defineSCL_clrPORTC&=~(1<<5)#defineSCL_outDDRC
10、=(1<<5)#defineSlaveAddress0xA6//器件地址ucharRe_data[6];intDis_data;floatTemp_x,Temp_y,Temp_z;floatAngle;/*延时*/voidDelay(uintt){while(t--){}}/*LCD12232端口初始化*/voidPORT_Init(void){DDRD
11、=BIT(6);PORTD
12、=BIT(6);DDRD
13、=BIT(7);PORTD
14、=BIT(7);DD
15、RB
16、=BIT(0);PORTB
17、=BIT(0);}/*LCD12232写指令*/voidSend_COM(ucharCOM){uchari,Order;CS_clr;Order=0xf8;SCLK_clr;CS_set;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_set;Order<<=1;}Order=COM;Order&=0xf0;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_set;Order<<=1;}Ord
18、er=COM;Order<<=4;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_clr;SCLK_set;Order<<=1;}CS_clr;Delay(20);}/*LCD12232写数据*/voidSend_DATA(ucharData){uchari,Order;CS_clr;Order=0xfa;SCLK_clr;CS_set;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_set;Order<<=1;}Order
19、=Data;Order&=0xf0;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_set;Order<<=1;}Order=Data;Order<<=4;for(i=0;i<8;i++){if(Order&0x80)SID_set;elseSID_clr;SCLK_clr;SCLK_set;Order<<=1;}CS_clr;Delay(20);}/*显示一字符串*/voidDis_str(ucharAddr,uchar*str){Send_COM(Addr);Delay(100);while(*str
20、!=' '){Send_DATA(*str);str++;Delay(20);}}/*LCD12232初始化*/voidInit_LCD(void){Delay(2000);Send_COM(0x06);Delay(200);Send_COM(0x02);Delay(200);Send_COM(0x0c);Delay(200);Send_COM(0x80);Delay(200);Send_COM(0x30);Delay(200);Send_C
此文档下载收益归作者所有