|
目前遇到一個(gè)問題,求組論壇大神:
要求:
前8個(gè)LED左右來回一次后,第九個(gè)LED翻轉(zhuǎn)一下,同時(shí)數(shù)碼管顯示循環(huán)次數(shù)
已實(shí)現(xiàn):
8個(gè)LED左右來回一次后,第九個(gè)LED翻轉(zhuǎn)一下
問題:
數(shù)碼管的顯示循環(huán)次數(shù),不能一直保持顯示
【補(bǔ)充說明,我的目標(biāo)是:當(dāng)新的一輪LED循環(huán)時(shí),數(shù)碼管能一直保持上一次的數(shù)據(jù)
只有當(dāng)新的一輪LED循環(huán)結(jié)束后 ,第九個(gè)LED翻轉(zhuǎn),數(shù)碼管再更新數(shù)據(jù)】
如果,保持位選一直開著,則會(huì)在顯示當(dāng)前次數(shù)后,變成顯示0;
如果,位選關(guān)閉,則會(huì)出現(xiàn)一閃一閃;
單片機(jī)源程序如下:- /*
- * File: Main.c
- * Author: 12618
- *
- * Created on 2022年9月30日, 上午9:53
- */
- /* Includes:主函數(shù) ------------------------------------------------------------------*/
- #include <Main.h>
- /* Private define:個(gè)人定義變量 host變量 (字符常量)-------------------------------------------------------------*/
- /* Private variables:個(gè)人綁定變量----------------------------------------------------------*/
- /* Public variables:公共綁定變量-----------------------------------------------------------*/
- /* Private function prototypes:個(gè)人功能函數(shù)------------------------------------------------*/
- /*
- * @name main
- * @brief 主函數(shù)
- * @param None
- * @retval None
- */
- int main()
- {
-
- Sys.Sys_Init();
-
-
-
- //系統(tǒng)主循環(huán)
- while(1)
- {
- //Isr.Timer0_ISR();中斷查詢法
- SMG1.SumLed_SMG();
-
- }
-
-
-
- }
- /********************************************************
- End Of File
- ********************************************************/
- /*
- * File: SMG.c
- * Author: Administrator
- *
- * Created on 2022年9月20日, 下午4:27
- */
- #include <Main.h>
- /* Private define-------------------------------------------------------------*/
- u16_int ge;
- u16_int shi;
- u16_int bai;
- u16_int qian;
- const u8_word LED[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //段碼表
- /* Private variables----------------------------------------------------------*/
- static void SMG_SumLed(void); //適用輸入輸出端口初始化
- /* Public variables-----------------------------------------------------------*/
- //結(jié)構(gòu)體定義對應(yīng).h的結(jié)構(gòu)體類型
- SMG_t SMG1 =
- {
- 0, //定義數(shù)碼管計(jì)數(shù)初值為0
- SMG_SumLed,
- };
- /* Private function prototypes------------------------------------------------*/
- /*
- * @name SMG_SumLed()
- * @brief 數(shù)碼管函數(shù)
- * @param None
- * @retval None
- */
- ///// 查詢法,需要放入while(1)//////
- static void SMG_SumLed()
- {
- Run_LED.LED_Flash();
- COUNT_LED = !COUNT_LED;
- SMG1.Flash_count = ++SMG1.Flash_count;
-
-
-
- ge = SMG1.Flash_count % 10;
- shi = SMG1.Flash_count % 100 / 10;
- bai = SMG1.Flash_count % 1000 / 100;
- qian = SMG1.Flash_count / 1000;
-
- u16_int i = 2;
-
- while( i--)
- {
- PORTBbits.RB3 = 0; //選擇個(gè)位數(shù)碼管
- PORTD = LED[ge]; //獲取個(gè)位值
- Delay_timer.Delay_1us(5); //十延時(shí)
- //PORTD = 0xFF; //清數(shù)碼管顯示
- //PORTBbits.RB3 = 1; //關(guān)數(shù)碼管
- PORTBbits.RB2 = 0; //選擇十位數(shù)碼管
- PORTD = LED[shi]; //獲取十位值
- Delay_timer.Delay_1us(5); //延時(shí)
- // PORTD = 0xFF; //清數(shù)碼管顯示
- //PORTBbits.RB2 = 1; //關(guān)數(shù)碼管*/
- PORTBbits.RB1 = 0; //選擇百位數(shù)碼管
- PORTD =LED[bai]; //獲取百位值
- Delay_timer.Delay_1us(5); //延時(shí)
- // PORTD = 0xFF; //清數(shù)碼管顯示
- //PORTBbits.RB1 = 1; //關(guān)數(shù)碼管
- PORTBbits.RB0 = 0; //選擇千位數(shù)碼管
- PORTD = LED[qian]; //獲取千位值
- Delay_timer.Delay_1us(5); //延時(shí)
- //PORTD = 0xFF; //清數(shù)碼管顯示
- //PORTBbits.RB0 = 1; //關(guān)數(shù)碼管
-
- }
-
- }
復(fù)制代碼 |
-
-
Desktop.zip
2022-9-27 11:07 上傳
點(diǎn)擊文件名下載附件
1.12 MB, 下載次數(shù): 6
兩種現(xiàn)象
|