標(biāo)題: 51單片機(jī)串口發(fā)送0-9數(shù)碼管顯示程序Proteus仿真圖 [打印本頁]

作者: 懶得說了    時間: 2022-1-28 19:07
標(biāo)題: 51單片機(jī)串口發(fā)送0-9數(shù)碼管顯示程序Proteus仿真圖
串口發(fā)送數(shù)字,數(shù)碼管顯示對應(yīng)數(shù)字,只是個位數(shù)字


單片機(jī)源程序如下:
  1. #include         "reg52.h" //包含頭文件

  2. #define          uchar         unsigned char
  3. #define          uint          unsigned int

  4. #define         DM             P0
  5. #define         WM             P2

  6. uchar           code           SMG_DM[]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  7. uchar           code           SMG_WM[]={1,2,4,8};

  8. uchar           dis[4];

  9. uchar            dat = 0;

  10. //-------------------------------------------------------------------------------------
  11. void     delay(uint t)
  12. {
  13. while(t--);
  14. }
  15. //-------------------------------------------------------------------------------------
  16. void     Uart_Int_Init()
  17. {
  18.         SCON=0x40;
  19.         TMOD=0x20;
  20.         TH1=TL1=0xFD;
  21.         TR1=1;
  22.         EA=1; //開總中斷
  23.         ES=1; //開串口中斷        
  24.         REN=1; //打開接收
  25. }        
  26. //=====================================================================================
  27. void     main()    //主函數(shù)
  28. {                    
  29.         Uart_Int_Init();
  30.         delay(1000);

  31.         WM = SMG_WM[0];
  32.         
  33.         while(1)
  34.         {
  35.                 DM=SMG_DM[dat];
  36.         }         
  37. }
  38. //=====================================================================
  39. void     uart_isr(void) interrupt 4
  40. {
  41. RI=0;  //數(shù)據(jù)接收完成標(biāo)志位
  42.         
  43. dat=SBUF;
  44. dat-='0';
  45.         if(dat>41)
  46.                 dat=dat-41+2;
  47. }
復(fù)制代碼
Keil代碼與Proteus仿真下載:
串口發(fā)送0~9,SMG顯示(解壓打開).zip (62 KB, 下載次數(shù): 48)









歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1