一,打開文件(可以隨文下載放置在文檔中打開)。(如下圖1所示) 圖1 二,調整虛擬器件,另存工程文件。(如下圖2,3所示) 圖2 圖3 三,點擊Source Code標簽。(如下圖4所示) 圖4 四,編輯main.c, iwdg.c,iwdg.h,key.c, key.h,led.c, led.h 代碼如Proteus8.9 仿真STM32407ZGT6系列001(如下圖5所示) 圖5 五,Main.c 代碼: #include "stm32f4xx_conf.h" #include "sys.h" #include "delay.h" #include "usart.h" #include "led.h" #include "key.h" #include "iwdg.h" int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); delay_init(168); LED_Init(); KEY_Init(); delay_ms(500); IWDG_Init(4,1000); LED0=0; LED1=1; while(1) { if(KEY0 ==1) { IWDG_Feed(); } delay_ms(10); }; } iwdg.c代碼: #include "iwdg.h" #include "led.h" ////////////////////////////////////////////////////////////////////////////////// void IWDG_Init(u8 prer,u16 rlr) { IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); IWDG_SetPrescaler(prer); IWDG_SetReload(rlr); IWDG_ReloadCounter();//reload IWDG_Enable(); } void IWDG_Feed(void) { LED0=~PBin(6); LED1=0; IWDG_ReloadCounter();//reload } iwdg.h代碼: #ifndef _IWDG_H #define _IWDG_H #include "sys.h" ////////////////////////////////////////////////////////////////////////////////// void IWDG_Init(u8 prer,u16 rlr); void IWDG_Feed(void); #endif led.c代碼: #include "led.h" void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);//使能GPIOB時鐘 //GPIOF9,F10初始化設置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6| GPIO_Pin_8;//LED對應引腳 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通輸出模式 GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;//推挽輸出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 GPIO_Init(GPIOB,&GPIO_InitStructure);//初始化 } led.h代碼: #ifndef __LED_H #define __LED_H #include "sys.h" //LED端口定義 #define LED0 PBout(6) // LED0 #define LED1 PBout(8) // LED1 void LED_Init(void);//初始化 #endif key.c代碼: #include "key.h" #include "delay.h" void KEY_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);//使能GPIOB時鐘 GPIO_InitStructure.GPIO_Pin= GPIO_Pin_3; //KEY0 對應引腳 GPIO_InitStructure.GPIO_Mode= GPIO_Mode_IN;//普通輸入模式 GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;//100M GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_DOWN ;//下拉 GPIO_Init(GPIOB,&GPIO_InitStructure);//初始化GPIOE4 } key.h代碼: #ifndef __KEY_H #define __KEY_H #include "sys.h" #define KEY0 PBin(3) //PB3 void KEY_Init(void); //IO初始化 #endif 六,點擊構建工程按鈕,編譯工程。(如下圖6所示) 圖6 七,點擊窗口左下方仿真按鈕,可見黃燈點亮仿真,按下按鈕,進行喂狗,開始跳閃仿真。 (如下圖7,8,9所示) 圖7 圖8 圖9 八,選擇release,點擊構建工程按鈕,編譯工程生成Hex文件。(如下圖10所示) 圖10 九, 系列的001-003虛擬仿真與開發板對應已證明:虛擬仿真程序對于開發板有效,之后不再➕上下載到開發板的介紹。 需要進一步了解,請加入QQ群:976235464
|