標(biāo)題: 閱覽室風(fēng)機節(jié)能系統(tǒng) 單片機程序 [打印本頁]

作者: 2924889822    時間: 2021-6-22 21:09
標(biāo)題: 閱覽室風(fēng)機節(jié)能系統(tǒng) 單片機程序
這是我做的電子設(shè)計,用了兩個星期。和C語言代碼。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include<regx51.h>
  2. #define uint unsigned  int
  3. #define uchar unsigned char
  4. #define LED P0
  5. sbit CS2 = P2^2;
  6. sbit CS1 = P2^1;
  7. uchar count;
  8. uchar counth,countl;
  9. const uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
  10. unsigned int temp;
  11. unsigned int fin;
  12. void delayms()//延時函數(shù)
  13. {
  14.         uint i;
  15.         for(i=0; i<130; i++);
  16. }

  17. void it0(void) interrupt 0 using 1
  18. {
  19.         
  20.         if(temp==1&&count!=0&&fin==0){
  21.                 count--;
  22.                 temp=0;
  23.         }else{
  24.                 temp=1;
  25.         }
  26.         fin=1;
  27. }
  28. void it2(void) interrupt 2 using 2
  29. {
  30.         if(temp==1&&count<99&&fin==1){
  31.                 fin=0;
  32.                 count++;
  33.                 temp=0;
  34.         }else{
  35.                 temp=1;
  36.         }
  37.         fin=0;
  38. }
  39. void main(void)
  40. {
  41.         IT0=1;
  42.         IT1=1;
  43.         EA=1;
  44.         EX0=1;
  45.         EX1=1;
  46.         PX1=1;
  47.         fin=1;
  48.         while(1){
  49.                 counth=count/10;
  50.                 countl=count%10;
  51.                 LED= tab[countl];
  52.                 CS2=1;
  53.                 delayms();
  54.                 CS2=0;
  55.                 LED=tab[counth];
  56.                 CS1=1;
  57.                 delayms();
  58.                 CS1=0;        
  59.         }
  60. }
復(fù)制代碼
由于我是新手以上資料肯定存在一些錯誤,歡迎大家批評指正,一起學(xué)習(xí) 提高技術(shù)(僅供參考 切勿照搬)





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