標(biāo)題: 單片機(jī)for語句實(shí)驗(yàn) [打印本頁]

作者: liuda    時(shí)間: 2015-1-21 23:01
標(biāo)題: 單片機(jī)for語句實(shí)驗(yàn)
是用51hei單片機(jī)開發(fā)板 電路圖詳見:http://www.torrancerestoration.com/f/51hei-5.pdf  的數(shù)碼管部分, 用2個(gè)74hc573 鎖存,p0口作為數(shù)據(jù)口 ,p3.6和p3.7分別是段和位的鎖存端口.

  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  5. sbit D=P3^6;
  6. sbit V=P3^7;
  7. //==================
  8. void delay(uint k)
  9. {
  10. uint i,j;
  11. for(i=0;i<k;i++){
  12. for(j=0;j<121;j++)
  13. {;}}
  14. }
  15. //================
  16. void main(void)
  17. {
  18. uint s,sum;
  19. for(s=50;s<=100;s=s+2)
  20. {sum=sum+s;}
  21. //==================
  22. while(1)
  23. {
  24. D=1;P0=SEG7[sum%10];D=0;P0=0xff;V=1;P0=0xf7;V=0;delay(5);
  25. D=1;P0=SEG7[(sum%100)/10];D=0;P0=0xff;V=1;P0=0xfb;V=0;delay(5);
  26. D=1;P0=SEG7[(sum/100)%10];D=0;P0=0xff;V=1;P0=0xfd;V=0;delay(5);
  27. D=1;P0=SEG7[sum/1000];D=0;P0=0xff;V=1;P0=0xfe;V=0;delay(5);
  28.     }
  29. }
復(fù)制代碼







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