CMOS智能投影仪设计和图像采集(硬件、程序源码、论文):
智能投影仪功能概述:
将摄像头采集到的白板上的触摸物体的位置信息通过USB线传给开发板,开发板做相应的图像处理,并把处理结果传给投影仪显示到白板上,最终实现触摸白板即操作开发板的效果。
利用开发板实现完整的图像采集及处理系统,即主系统A。主从摄像头将采集到的数据全部交给主系统来处理计算出白板上触控笔映射到电脑屏幕上的位置信息。硬件上由大面积白板、摄像头、微处理器、FPGA等部分组成,软件上实现几个图像处理算法。
如截图所示:
CMOS摄像头采集智能投影仪系统设计创新:
利用SRAM实现图像数据的存储与调配,从硬件上提高系统的实时性 几种关键图像算法的实现: 利用汇编语言实现图像接收,提高接收速度; 目标识别与目标定位算法准确有效地判断出了触摸物体的位置信息; 将白板枚举成USB设备,实现了白板的即插即用; 计算摄像头参数与映射系数算法实现了白板系统的准确校准、白板平面与PC机屏幕坐标系的高度契合
毕业设计中含有视频播放地址
程序:
- /******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
- * File Name : main.c
- * Author : MCD Application Team
- * Version : V3.1.0RC1
- * Date : 09/28/2009
- * Description : Joystick Mouse demo main file
- ********************************************************************************
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
- * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
- * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
- * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
- * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *******************************************************************************/
-
- /* Includes ------------------------------------------------------------------*/
- #include "math.h"
- #include "stdio.h"
- #include "stm32f10x_conf.h "
- #include "stm32f10x.h"
- #include "usb_lib.h"
- #include "hw_config.h"
- #include "usb_pwr.h"
- #include "usb_conf.h"
- //#include "parameters.h"
- #include "main.h"
- #include "FlashHandle.h"
-
-
- #define SET_L GPIO_WriteBit(GPIOB, GPIO_Pin_5, (BitAction)0x00); //用于表示单片机处理完可切换存储器至摄像头的信号
- #define SET_H GPIO_WriteBit(GPIOB, GPIO_Pin_5, (BitAction)0x01);
- #define ObSize 6528 ;
-
- void IWDG_Configuration(void);
- void Delay(__IO uint32_t nCount);
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void USART2_Configuration(void);
- void USART1_Configuration(void);
- void NVIC_Configuration(void);
- void TIMER_Configuration(void) ;
- void Init_All_Periph(void);
-
- /*private define*/
- // uint8_t Receive_Buffer[9];
- volatile unsigned int ObjectFlag=0;
- char flag_int=0;
- char f1=1,f2=1,t1=1,t2=0;
- unsigned char d1_sub=255,d2_sub=255,t1_sub=0,t2_sub=0;
-
- /*
- volatile unsigned char t_sub,tt_sub;
- volatile unsigned int d2_main[2];
- volatile int t_main[2],tt_main;
- extern volatile int d_main,d_sub;
- extern int screen_x,screen_y;
- */
- volatile unsigned char t_sub,tt_sub;
- volatile unsigned int d2_main[2];
- volatile unsigned char t_main[2],tt_main;
- extern volatile unsigned int d_main,d_sub;
- extern volatile int screen_x,screen_y;
- volatile int screen_prex=0,screen_prey=0;
- int screen_datax[5]={0,0,0,0,0};
- int screen_datay[5]={0,0,0,0,0};
- unsigned char d_x[7]={0};
- unsigned char d_y[7]={0};
- int screen_dx[2];
- int screen_dy[2];
- unsigned char dx;
- unsigned char dy;
- extern unsigned char object[6528];
- //unsigned char back[12][544];
- extern unsigned char back[6528];
- extern signed char diff[600];
-
- signed char pre_maxim[2];
- unsigned int zhenshu;
- unsigned int zhenshu1;
-
-
- void dc_config(void);
- unsigned int get_x(void);
-
- void bd_to_screen(void) ;
-
-
- /
- int fputc(int ch, FILE *f)
-
- {
- USART_SendData(USART1, (unsigned char) ch);// USART1 可以换成 USART2 等
-
- while (!(USART1->SR & USART_FLAG_TXE));
-
- return (ch);
-
- }
-
- /*******************************************************************************
- * Function Name : read from sram
- *******************************************************************************/
- /* */
- __asm void ReadSram(unsigned char *p) //软件复位 自己添加
- {
- MOV R2,R0 //将数组的起始地址赋给r2
- MOV R3,#0x0000
- MOVW R4,#0x0c08 //输入数据
- MOVT R4,#0x4001
- MOVW R5,#0x100C //取数据地址
- MOVT R5,#0x4001
- loop
- STR R3,[R5] //r3赋值地址给r5
- LDR R0,[R4] //将GPIOB->IDR的值赋给r0
- LSR R0,R0,#8
- STRH R0,[R2,R3] //将r0的值赋给定义数组
- ADDS R3,R3,#0x01 //SUBS r3,r3,#0x01 r3++
- STR R3,[R5] //将idx的值赋给GPIOC->ODR(地址)
- CMP R3,#0x1980
- BNE loop //跳转到循环开始;否则结束
- BX LR //返回主程序
- }
-
- /*
- __asm void ReadSramChar(unsigned char *p,int i)
- {
-
- MOV R2,R0 //将地址赋给r2
- MOV R3,R1 //将取数据的地址赋给r3
- MOVW R4,#0x0c08 //输入数据
- MOVT R4,#0x4001
- MOVW R5,#0x100C //取数据地址
- MOVT R5,#0x4001
-
- STRB R3,[R5] //r3赋值地址给r5
- LDR R0,[R4] //将GPIOB->IDR的值赋给r0
- LSR R0,R0,#8
- STRB R0,[R2] //将r0的值赋给定义数组
- }
- */
-
-
-
- /*
- void ReadSram(unsigned char *p)//,(unsigned int)ObSize)
- {
- u16 Adr;
- char i;
- u16 j;
- GPIO_ResetBits(GPIOA, GPIO_Pin_5);
- for(Adr=0x0000;Adr<6528;Adr++)
- //for(Adr=0x0000;;Adr++)
- {
- GPIOC->ODR=Adr;
- for(i=0;i<5;i++)
- j=GPIOB->IDR;
- j=(j&0xff00)>>8;
- *p=(char)j;
- p++;
- // GPIOC->BSRR = 0X00000000;
- }
- GPIO_SetBits(GPIOA, GPIO_Pin_5);
- }
- */
- void ReadSramChar(unsigned char *p,u16 Adr)
- {
- char i;
- unsigned int j=0;
- GPIO_ResetBits(GPIOA, GPIO_Pin_5);
- GPIOC->ODR=Adr;
- for(i=0;i<5;i++)
- j=GPIOB->IDR;
- j=(j&0xff00)>>8;
- *p=(unsigned char)j;
- // GPIOC->BSRR = 0X00000000;
- GPIO_SetBits(GPIOA, GPIO_Pin_5);
- }
-
-
-
-
- void USART2_IRQHandler(void)
- {unsigned char data_f_0;
- if(USART_GetITStatus(USART2,USART_IT_RXNE)!=RESET) //判断发生接收中断
- {
- USART_ClearITPendingBit(USART2, USART_IT_RXNE); //清除中断标志
- //GPIO_WriteBit(GPIOB,GPIO_Pin_10,(BitAction)0x01); //开始传输
- data_f_0=USART_ReceiveData(USART2);
- while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE)== 1);
- if(flag_int==0)
- {
- if(f1!=0) //判断接收数据是否为第一个坐标信息
- {
- d1_sub=data_f_0; //将接收到的从坐标低八位存入d1_sub[4]
- f1=0; //将标志接收数据为从坐标低八位的寄存器清零。为0代表已接收。
- f2=1;
- t1=1;
- t2=1;
- }
- else //判断接收数据是否为第二个坐标信息
- if(f2!=0)
- {
- d2_sub=data_f_0; //将接收到的从坐标高八位存入d2_sub[4]
- f1=0;
- f2=0; //将标志接收数据为从坐标高八位的寄存器清零。为0代表已接收。
- t1=1;
- t2=1;
- }
- else
- if(t1!=0) //判断接收数据是否为时间信息
- {
- t1_sub=data_f_0; //将接收到的从时间存入t1_sub[4]
- f1=0;
- f2=0;
- t1=0;
- t2=1; //清零标志接收从时间的寄存器。为0代表已接受从时间。
- }
- else
- if(t2!=0) //判断接收数据是否为时间信息
- {
- t2_sub=data_f_0; //将接收到的从时间存入t1_sub[4]
- f1=1;
- f2=1;
- t1=1;
- t2=0; //清零标志接收从时间的寄存器。为0代表已接受从时间。
- }
- }
- }
- /*if(USART_GetITStatus(USART2,USART_IT_TXE)!=RESET)
- { USART_ClearITPendingBit(USART2, USART_IT_TXE) ;
- USART_SendData(USART2, 0xDD);
- while(USART_GetFlagStatus(USART2, USART_FLAG_TXE)== 0);
- USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
-
- } */
- }
-
- void move(void)
- {
- unsigned char i;
- unsigned int j;
-
- for (i=0;i<12;i++)
- {for (j=0;j<544;j++)
- {
- back[i*544+j] = object[i*544+j];
- }
- }
-
- }
-
- void judge(void)
- {
- unsigned int p1,p2,m1,m2;
- unsigned char p;
- char flag1=0;
-
- for(p=0;p<2;p++)
- {
- if(t_sub==t_main[p])
- {
- d_main=d2_main[p];
- flag1=1;
- break;
- }
- }
- if(flag1==1)
- {
- if(t_main[1]>t_main[0])
- {
- if(t_sub<t_main[1]&&t_sub>t_main[0])
- {
- m2=t_main[1];
- m1=t_main[0];
- p2=d2_main[1];
- p1=d2_main[0];
- //d_main=(p2-p1)*(t_sub-m1)/(m2-m1)+p1;
- /**/if(p2>p1)
- d_main=(p2-p1)*(t_sub-m1)/(m2-m1)+p1;
- else
- d_main=p1-(p1-p2)*(t_sub-m1)/(m2-m1);
-
-
-
- }
- }
- else if(t_main[1]<t_main[0])
- {
- if(t_sub>t_main[1])
- {
- m2=t_main[1]+tt_main;
- m1=t_main[0];
- p2=d2_main[1];
- p1=d2_main[0];
- //d_main=(p2-p1)*(t_sub-m1)/(m2-m1)+p1;
- /**/if(p2>p1)
- d_main=(p2-p1)*(t_sub-m1)/(m2-m1)+p1;
- else
- d_main=p1-(p1-p2)*(t_sub-m1)/(m2-m1);
-
- }
- else if(t_sub<t_main[1])
- {
- m2=t_main[1];
- m1=tt_main-t_main[0];
- p2=d2_main[1];
- p1=d2_main[0];
- //d_main=(p2-p1)*(t_sub+m1)/(m2+m1)+p1;
- /**/if(p2>p1)
- d_main=(p2-p1)*(t_sub+m1)/(m2+m1)+p1;
- else
- d_main=p1-(p1-p2)*(t_sub+m1)/(m2+m1);
-
- }
- }
- flag1=0;
- }
- }
-
-
- int main(void)
- {
-
- // unsigned int Time_Adr;//u=0,
- unsigned char *p1,*p2,*p3;
- unsigned char k;
- // unsigned char m;
- char flag;
- unsigned int j;
-
- // u32 TimCounter=0;
- // int u;
-
- Init_All_Periph(); //系统初始化
- ReadFromFlash(); //从flash读取参数
-
- for(k=0;k<30;k++)
- for(j=0;j<65535;j++);
- dc_config(); //配置摄像头
- for(k=0;k<30;k++)
- for(j=0;j<65535;j++);
-
- for (k=110;k>0;k--);
- SET_L; //为conv切换进行初始化 SET=0
- SET_H; //SET=1
- for (k=60;k>0;k--);
- for(j=0;j<65535;j++);
- SET_L; //SET=0
- k=0;
-
- zhenshu=0;
- zhenshu1=0;
- pre_maxim[0]=0;
- pre_maxim[1]=0;
-
- GPIO_SetBits(GPIOA, GPIO_Pin_4);
- GPIO_SetBits(GPIOA, GPIO_Pin_5);
-
- while((GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0))==1); //等待,直到conv变为0
- //TIM2->CNT=0;
- flag=1;
- while (1)
- {
- //if(k<20)
- {
-
- if((GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0))!=RESET)//查询conv是否为1,SRAM是否与单片机相连
- {
-
- /* TIM2->CNT=0; //打开计时器,清零开始计时
- TimCounter= TIM2->CNT ;
- USART_SendData(USART1, TimCounter);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== 0);
- USART_SendData(USART1, TimCounter>>8);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TXE)== 0);*/
-
-
-
- GPIO_ResetBits(GPIOA, GPIO_Pin_5);
- ReadSram(object);
- GPIO_SetBits(GPIOA, GPIO_Pin_5); // SET OE;
-
- if(flag==1)
- {
- move(); //将第一幅图像存到背景图像存储区内
- flag=0;
- }
- else
- {
-
- /等待将中断接收d1_sub,d2_sub,t1_sub,t2_sub导出,避免使用途中更新/
- while(t2!=0);
-
- flag_int=1;
- p1 = (unsigned char*)&d_sub ;
- *p1= d1_sub;
- *(p1+1)= d2_sub;
-
- p2 = (unsigned char*)&t_sub ;
- *p2 = t1_sub;
- p3 = (unsigned char*)&tt_sub ;
- *p3 =t2_sub;
-
- flag_int=0;
-
-
- d2_main[0]=d2_main[1];
-
- d_main=get_x();
-
- d2_main[1]=d_main;
- ///保存新参数到flash
- if(WriteParaToFlash==2)
- {
- RCC_Disable();
- WriteToFlash();
- WriteParaToFlash=0;
- RCC_Enable();
- }
-
-
- /* USART_SendData(USART1, d_main);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC)== 0); //等待,直到发送标志被清除,发送完成
- USART_SendData(USART1, d_main>>8);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC)== 0);
- USART_SendData(USART1, 1);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC)== 0); //等待,直到发送标志标志被清除,发送完成
- USART_SendData(USART1, screen_y>>8);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC)== 0); */
-
-
- //windows xp///
- if(Sys_Mode==0)
- {
-
- if((d_main!=0x00)&&(d_sub!=0x00)) //判断是否有目标物体
- {
- ObjectFlag=0; //为0代表有目标
-
- bd_to_screen();
- screen_prex=screen_x;
- screen_prey=screen_y;
-
-
- ///SendFlag=1为校准模式
- if(SendFlag==1)
- HID_SendPix(d_main,d_sub) ;
-
- else //正常工作
- {
- if(RightFlag==1) //如果发送了一次菜单,接着发送空的左键,然后才发送点下的左键
- {
- Joystick_Send_0(screen_x,screen_y);
- RightFlag=0;
- }
- else
- Joystick_Send(screen_x,screen_y);
- }
-
- }
- else
- {
-
- ObjectFlag++;
- RightFlag=0; //目标拿开后右键标志清零
- MenuFlag =0;
-
- if((ObjectFlag<3)&&(SendFlag!=1))
- Joystick_Send_0(screen_prex,screen_prey); //无目标,只发送一次空左键
- else if(ObjectFlag>3000) ///发送一次空左键后ObjectFlag一直置为5,直到再次有目标后清0
- ObjectFlag=5;
-
-
-
-
- for(j=0;j<5;j++)
- {
- screen_datax[j]=0;
- screen_datay[j]=0;
-
- }
- }
- } //case0?
- else
- {
- if((d_main!=0x00)&&(d_sub!=0x00)) //判断是否有目标物体
- {
- ObjectFlag=0; //为0代表有目标
-
- bd_to_screen();
- screen_prex=screen_x;
- screen_prey=screen_y;
-
- ///SendFlag=1为校准模式
- if(SendFlag==1)
- HID_SendPix(d_main,d_sub) ;
-
- else //正常工作
- {
- SingleTouch(screen_x,screen_y);
- // HID_SendPix(d_main,d_sub) ;
- }
-
-
- }
- else
- {
- ObjectFlag++;
- RightFlag=0; //目标拿开后右键标志清零
- MenuFlag =0;
-
- if((ObjectFlag<3)&&(SendFlag!=1)) ///发送一次空左键后ObjectFlag一直置为5,直到再次有目标后清0
- SingleTouch_0(screen_prex,screen_prey); //无目标,只发送一次空左键
- else if(ObjectFlag>3000) ///发送一次空左键后ObjectFlag一直置为5,直到再次有目标后清0
- ObjectFlag=5;
-
- for(j=0;j<5;j++)
- {
- screen_datax[j]=0;
- screen_datay[j]=0;
-
- }
- }
-
- }
-
-
-
- }
-
- IWDG_ReloadCounter();
-
- SET_H; //计算完成后发送短复位脉冲
-
- while((GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0))==SET);
-
- SET_L;
-
-
- }
- }
-
- }
- }
-
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- SystemInit();
-
- RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
-
- /* Enable the USB clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
-
- /* Enable USART2, GPIOA, GPIOx and AFIO clocks */
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
- RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
-
- /* Enable USART2 clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- /* Enable USART1 clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
-
- /* Enable TIM2 clock*/
- // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
- }
-
- /*******************************************************************************
- * Function Name : GPIO_Configuration
- * Description : Configures the different GPIO ports.
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /*-----------------------CONV--------------------------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /*------------------------SET--------------------------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /*---------------------SCCB_STO_D----------------------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /*---------------------SCCB_STO_C-----------------------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* Configure USART2 Tx (PA.02) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* Configure USART2 Rx (PA.03) as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Configure USART1 Tx (PA.9) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* Configure USART1 Rx (PA.10) as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /**/ //Configure USB D- (PA.11) as alternate function push-pull
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- // Configure USB D+ (PA.12) as function push-pull
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /*GPIOC Configuration: THIS GPIOC IS USED AS THE ADDRESS */
- GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0 |GPIO_Pin_1|GPIO_Pin_2 |GPIO_Pin_3 |
- GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6 |GPIO_Pin_7 |
- GPIO_Pin_8 |GPIO_Pin_9|GPIO_Pin_10 |GPIO_Pin_11 |
- GPIO_Pin_12 |GPIO_Pin_13|GPIO_Pin_14 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7;
- //GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /*GPIOB Configuration: GPIOB 8 TO 15 ARE USED AS DATA*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9|GPIO_Pin_10 |GPIO_Pin_11 |
- GPIO_Pin_12 |GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//???
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /*GPIOA Configuration: THIS GPIOC IS USED AS THE control signal*/
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_Init(GPIOA, &GPIO_InitStructure); //oe,we;
-
-
- }
-
- /*******************************************************************************
- * Function Name : USART2_Configuration
- * Description : Configures the USART2 controller.
- *******************************************************************************/
- void USART2_Configuration(void)
- {
- USART_InitTypeDef USART_InitStructure;
- USART_InitStructure.USART_BaudRate = 115200 ;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART2, &USART_InitStructure);
- USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
-
- USART_Cmd(USART2, ENABLE);
-
- }
- /*******************************************************************************
- * Function Name : USART1_Configuration
- * Description : Configures the USART1 controller.
- *******************************************************************************/
- void USART1_Configuration(void)
- {
- USART_InitTypeDef USART_InitStructure;
- USART_InitStructure.USART_BaudRate = 115200 ;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART1, &USART_InitStructure);
-
-
- USART_Cmd(USART1, ENABLE);
-
- }
- /*******************************************************************************
- * Function Name : NVIC_Configuration
- * Description : Configures the NVTC controller.
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Configure the NVIC Preemption Priority Bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- /* Enable the USARTy Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Enable the USB interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /* Enable the USB Wake-up interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_Init(&NVIC_InitStructure);
-
-
- }
- /******************************************************************************
- * Function Name : TIMER configuration
- * Description : Configures the SysTick controller.
- *******************************************************************************/
- void TIMER_Configuration(void)
-
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
-
- TIM_TimeBaseStructure.TIM_Period =10000; //计数值
- TIM_TimeBaseStructure.TIM_Prescaler =7200-1; //预分频,此值+1为分频的除数
- TIM_TimeBaseStructure.TIM_ClockDivision =0x0; //设置时钟分割
- TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up; //向上计数
- TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM2, ENABLE); //打开定时器
- }
-
- /*********************看门狗初始化********************************/
- void IWDG_Configuration(void)
- {
- /* 写入0x5555,用于允许狗狗寄存器写入功能 */
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
-
- /* 狗狗时钟分频,40K/256=156HZ(6.4ms)*/
- IWDG_SetPrescaler(IWDG_Prescaler_256);
-
- /* 喂狗时间 5s/6.4MS=781 .注意不能大于0xfff*/
- IWDG_SetReload(300);
-
- /* 喂狗*/
- IWDG_ReloadCounter();
-
- /* 使能狗狗*/
- IWDG_Enable();
- }
- /*******************************************************************************
- * Function Name : Delay
- * Description : Inserts a delay time.
- * Input : nCount: specifies the delay time length.
- * Output : None
- * Return : None
- ******************************************************************************
- void Delay(__IO uint32_t nCount)
- {
- for (; nCount != 0;nCount--);
- } */
- /*******************************************************************************
- * Function Name : ALL_Periph_Configuration
- * Description : initionalize all periph
- *******************************************************************************/
- void Init_All_Periph(void)
- {
- RCC_Configuration();
- // Delay(100);
- GPIO_Configuration();
- // Delay(100);
- USART2_Configuration();
- // Delay(100);
- USART1_Configuration();
- // Delay(100);
- NVIC_Configuration();
- // Delay(100);
- TIMER_Configuration();
- // Delay(100);
- USB_Init();
- IWDG_Configuration();
- }
-
-
- #ifdef USE_FULL_ASSERT
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None
- * Return : None
- *******************************************************************************/
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
-
- /* Infinite loop */
- while (1)
- {}
- }
- #endif
-
- /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
-
复制代码
|