標(biāo)題: 做了一個(gè)單片機(jī)出租車(chē)計(jì)費(fèi)系統(tǒng)的Proteus仿真程序 [打印本頁(yè)]

作者: JSP_CLH    時(shí)間: 2021-5-8 20:38
標(biāo)題: 做了一個(gè)單片機(jī)出租車(chē)計(jì)費(fèi)系統(tǒng)的Proteus仿真程序
抄了“基于proteus和校企對(duì)接的單片機(jī)實(shí)驗(yàn)與綜合設(shè)計(jì)實(shí)例”上的“出租車(chē)計(jì)費(fèi)系統(tǒng)”的程序,想要的下。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include        <reg51.h>
  2. #define uchar unsigned char
  3. #define  uint unsigned int
  4. sbit        RESET                =        P3^7;
  5. int                Price                =        80,        Mileage                =        0;
  6. uchar        count                =        0;
  7. uchar code tab_d[10]                =        {0x3F,        0X06,        0X5B,        0X4F,        0X66,        0X6D,        0X7D,        0X07,        0X7F,        0X6F};
  8. uchar code tab_wei[8]                ={0x7f,        0xbf,        0xdf,        0xef,        0xf7,        0xfb,        0xfd,        0xfe};

  9. //延時(shí)函數(shù)ms
  10. void        delay(uint t)
  11. {
  12.         uchar                i                =        0;
  13.         while(t--)
  14.                 for        (i;        i<120;        i++);
  15. }

  16. //數(shù)碼管顯示函數(shù)
  17. /*
  18.   參數(shù)說(shuō)明:
  19.    d : 表示要顯示的值
  20.          x : 表示是否要顯示點(diǎn)(0x80 顯示 0不顯
  21.    w :顯示第幾位
  22. */
  23. void        disp(uchar d,        uchar x,        uchar w)
  24. {
  25.         P2                =        0XFF;
  26.         P2                =        tab_wei[w];
  27.         P0                =        0;
  28.         P0                =        tab_d[d]        | x;
  29.         delay        (100);
  30. }

  31. //刷新函數(shù)
  32. void        refresh()
  33. {
  34.         disp(Mileage%10,        0,        0);//公里
  35.         disp(Mileage/10%10,        0x80,        1);        
  36.         if        (Mileage >= 100)               
  37.                         disp(Mileage/100%10,        0,        2);               
  38.         if        (Mileage >= 1000)               
  39.                         disp(Mileage/1000%10,        0,        3);        
  40.         disp(Price%10,        0,        4);
  41.         disp(Price/10%10,        0x80,        5);        
  42.         if        (Price        >= 100)
  43.                 disp(Price/100%10,        0,        6);
  44.         if        (Price        >=        1000)
  45.                 disp(Price/1000%10,        0,        7);
  46. }
  47. void timer1        ()        interrupt 1
  48. {
  49.         count++;
  50.         Mileage +=        1;
  51.         if(        count        ==        5)
  52.         {
  53.                 count        =        0;
  54.                 if        (Mileage        >        30)
  55.                                 Price +=10;
  56.                 }
  57. }

  58. //系統(tǒng)初始化
  59. void init()
  60. {
  61.         P0                        =        0;
  62.         P2                        =        0XFF;
  63.         TMOD                =        0X0E;   //設(shè)置計(jì)數(shù)器模式
  64.         IT0                        =        1;                  //電平觸發(fā)        
  65.         TH0                        =        255;                //1個(gè)脈沖延時(shí)
  66.         TL0                        =        255;
  67.         TR0                        =        1;
  68.         IE                        =        0X82;
  69. }

  70. void        judgeReset()
  71. {
  72.         if(RESET        ==        0)
  73.         {
  74.                 Price                =        80;
  75.                 Mileage        =        0;
  76.         }
  77. }
  78. void        main()
  79. {
  80.                 init        ();                //系統(tǒng)初始化
  81.                 while        (1)
  82.                 {
  83.                         judgeReset        ();
  84.                         refresh                        ();
  85.                         }                        
  86. }
復(fù)制代碼


所有資料51hei提供下載:
出租車(chē)計(jì)費(fèi)系統(tǒng).rar (40.57 KB, 下載次數(shù): 42)





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