欢迎来到天天文库
浏览记录
ID:55955560
大小:35.00 KB
页数:15页
时间:2020-06-18
《stm32内部AD采样程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、//stm32内部AD采样程序。运行通过的请大家放心使用。//有缺陷的地方请大家多多指教。本人才刚刚起步,还有劳各位大侠带一把呀!/*Includes------------------------------------------------------------------*/#include"stm32f10x_lib.h"#include"stdio.h"/*Privatetypedef-----------------------------------------------------------*//*Private
2、define------------------------------------------------------------*/#defineADC1_DR_Address((u32)0x4001244C)intAD_value;/*Privatemacro-------------------------------------------------------------*//*Privatevariables---------------------------------------------------------
3、*/ADC_InitTypeDefADC_InitStructure;vu16ADC_ConvertedValue;ErrorStatusHSEStartUpStatus;/*Privatefunctionprototypes-----------------------------------------------*/voidRCC_Configuration(void);voidGPIO_Configuration(void);voidSysTick_Configuration(void);voidSetupClock(void)
4、;#defineLED1ONGPIO_SetBits(GPIOF,GPIO_Pin_0)#defineLED1OFFGPIO_ResetBits(GPIOF,GPIO_Pin_0)//片选cs#defineLED2ONGPIO_SetBits(GPIOF,GPIO_Pin_1)#defineLED2OFFGPIO_ResetBits(GPIOF,GPIO_Pin_1)//复位rest#defineLED3ONGPIO_SetBits(GPIOF,GPIO_Pin_2)#defineLED3OFFGPIO_ResetBits(GPIOF,
5、GPIO_Pin_2)//数据sdata#defineLED4ONGPIO_SetBits(GPIOF,GPIO_Pin_3)#defineLED4OFFGPIO_ResetBits(GPIOF,GPIO_Pin_3)//时钟sclkunsignedcharVer='A';//驱动版本,默认为A版本,一共4个版本voiddelayms(unsignedintii)//1ms延时函数{unsignedinti,x;for(x=0;x6、ue,unsignedcharcd)//写8位数据{unsignedchari,dt;LED1OFF;LED4OFF;if(cd==0)LED3OFF;elseLED3ON;LED4ON;dt=value;for(i=0;i<8;i++){LED4OFF;if(dt&0x80)LED3ON;elseLED3OFF;dt=dt<<1;LED4ON;}LED1ON;//cs=1;}voidreaddata()//读数据{unsignedchari,j;unsignedcharch[6];send(0x09,0);//读数据LED1OFF;/7、/cs=0;LED4OFF;//sclk=0;for(i=0;i<6;i++){ch[i]=0;for(j=0;j<8;j++){LED4ON;//sclk=1;if(!(GPIO_ReadOutputDataBit(GPIOF,GPIO_Pin_2)))//sdata==0){ch[i]=ch[i]8、(1<<(7-j));}LED4OFF;//sclk=0;}}switch(ch[0]){case255:Ver='A';break;case127:Ver='B';break;case0:if(ch[1]+ch[2]+ch[3]==0)9、{Ver='D';}else{Ver='C';}break;}LED1ON;//cs=1;}voidLCD_Initialize()//LCD初始化{unsignedchari;LED2ON;//rest=
6、ue,unsignedcharcd)//写8位数据{unsignedchari,dt;LED1OFF;LED4OFF;if(cd==0)LED3OFF;elseLED3ON;LED4ON;dt=value;for(i=0;i<8;i++){LED4OFF;if(dt&0x80)LED3ON;elseLED3OFF;dt=dt<<1;LED4ON;}LED1ON;//cs=1;}voidreaddata()//读数据{unsignedchari,j;unsignedcharch[6];send(0x09,0);//读数据LED1OFF;/
7、/cs=0;LED4OFF;//sclk=0;for(i=0;i<6;i++){ch[i]=0;for(j=0;j<8;j++){LED4ON;//sclk=1;if(!(GPIO_ReadOutputDataBit(GPIOF,GPIO_Pin_2)))//sdata==0){ch[i]=ch[i]
8、(1<<(7-j));}LED4OFF;//sclk=0;}}switch(ch[0]){case255:Ver='A';break;case127:Ver='B';break;case0:if(ch[1]+ch[2]+ch[3]==0)
9、{Ver='D';}else{Ver='C';}break;}LED1ON;//cs=1;}voidLCD_Initialize()//LCD初始化{unsignedchari;LED2ON;//rest=
此文档下载收益归作者所有