|
求幫忙指點一下 謝謝大家
程序寫出來后仿真功能一直不實現
PA5也莫名其妙的是低電平
中斷前000-999遞增計數
中斷后顯示6個數字
6c7308f2fe80e528b320b0a89660635.png (40.82 KB, 下載次數: 28)
下載附件
2022-4-27 15:23 上傳
用proteus8.9以上打開
單片機源程序如下:
- #include "stm32f10x.h"
- #define GPIO_InitStructure g
- uint16_t table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- uint16_t wei[]={0x0fe,0x0fd,0x0fb,0x0f7,0x0ef,0x0df,0xff,0xff};
- uint16_t xuehao[]={0x7d,0x4f,0x3f,0x5b,0x5b,0x6f};
- u16 i;
- u8 ssec,sec,min; //毫秒,秒,分
- u8 DisplayData[3];
- uint8_t flag_led_bling=1;
- void EXTI0_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
- {
- flag_led_bling=1-flag_led_bling;
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- }
- /**
- * @簡介:NVIC初始化
- * @參數: 無
- * @返回值:無
- */
- void NVIC_Configure(void)
- {
- /* 定義NVIC結構體 */
- NVIC_InitTypeDef NVIC_InitStructure;
- /* 選擇中斷分組 */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- /* 配置P[A|B|C|D|E]0為中斷源 */
- /* 選擇中斷通道 */
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- /* 設置搶占優先級 */
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- /* 設置響應優先級 */
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- /* 中斷使能 */
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- /* 調用NVIC_Init()完成中斷配置 */
- NVIC_Init(&NVIC_InitStructure);
- }
- /**
- * @簡介:按鍵初始化,帶中斷
- * @參數: 無
- * @返回值:無
- */
- void KEY_Configure(void)
- {
- /* 定義GPIO初始化結構體 */
- GPIO_InitTypeDef GPIO_InitStructure;
- /* 定義EXTI初始化結構體 */
- EXTI_InitTypeDef EXTI_InitStructure;
-
- /* 打開GPIOA和AFIO時鐘 */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
- /* 配置PA0為上拉輸入 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
-
- /* 完成配置 */
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* 選擇中斷管腳 */
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
- /* 選擇中斷線路 */
- EXTI_InitStructure.EXTI_Line = EXTI_Line0;
- /* 設置為中斷請求 */
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- /* 設置中斷觸發方式:雙邊沿觸發 */
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- /* 中斷線使能 */
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- /* 調用EXTI_Init()函數完成中斷初始化 */
- EXTI_Init(&EXTI_InitStructure);
- }
- /**
- * @簡介:按鍵狀態
- * @參數: 無
- * @返回值:按鍵狀態,0-按下,1-松開
- */
- uint8_t KEY_Down_Up(void)
- {
- return GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);
- }
- void SEG_Init(void)
- {
- GPIO_InitTypeDef g;
- //使能GPIOC時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);
- g.GPIO_Pin = 0x00ff; //PC0-PC7引腳配置
- g.GPIO_Mode = GPIO_Mode_Out_PP; //配置為推挽輸出
- g.GPIO_Speed = GPIO_Speed_50MHz; //GPIOC速度為50MHz
- GPIO_Init(GPIOC, &g); //初始化PC0-PC7
- g.GPIO_Pin = 0x003f; //PB0-PC5引腳配置
- g.GPIO_Mode = GPIO_Mode_Out_PP; //配置為推挽輸出
- g.GPIO_Speed = GPIO_Speed_50MHz; //GPIOB速度為50MHz
- GPIO_Init(GPIOB, &g); //初始化PB0-PB5
-
- }
- void delay(u16 i)
- {
- while(i--);
- }
- void DigDisplay()
- {
- u8 i;
- for(i=0;i<4;i++)
- {
- switch(i) //位選,選擇點亮的數碼管,
- {
-
- case(0):
- GPIO_Write(GPIOB,wei[0]); break;//顯示第2位
- case(1):
- GPIO_Write(GPIOB,wei[1]); break;//顯示第1位
- case(2):
- GPIO_Write(GPIOB,wei[2]); break;//顯示第0位
- }
- GPIO_Write(GPIOC,DisplayData[i]);//發送段碼
- delay(65535); //間隔一段時間掃描
- GPIO_Write(GPIOC,0x000);//消隱
- delay(10);
- }
- }
- void datapros()
- {
-
- DisplayData[2]=table[sec%10];
-
- DisplayData[1]=table[ssec/10];
- DisplayData[0]=table[ssec%10];
- }
- int main()
- {
-
- SEG_Init();
- NVIC_Configure();//NVIC 配置
- KEY_Configure();//KEY 配置
-
- if(flag_led_bling)
- {
- for(i=0;i<1000;i++)
- {
- ssec++;
- if(ssec==100)
- {sec++; ssec=0;}
- datapros();
- DigDisplay();
- }
- }
-
- else{
- while(1)
- {
- for(i=1;i<7;i++)
- {
- GPIO_Write(GPIOB,wei[i-1]);
- GPIO_Write(GPIOC,xuehao[i-1]);
-
- delay(2300);
- GPIO_Write(GPIOB,0x0ff);
- delay(2300);
- }
- }
- }
- }
復制代碼
求各位大佬幫忙指點一下
|
|