標(biāo)題: 使用帶參數(shù)的宏定義進(jìn)行計(jì)算 [打印本頁]

作者: liuda    時(shí)間: 2015-1-21 22:45
標(biāo)題: 使用帶參數(shù)的宏定義進(jìn)行計(jì)算
是用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. #define S(a,b) (a-b)*3
  5. uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  6. sbit D=P3^6;
  7. sbit V=P3^7;
  8. //========================
  9.   void delay(uint k)
  10. {
  11. uint i,j;
  12. for(i=0;i<k;i++){
  13. for(j=0;j<121;j++)
  14. {;}}
  15. }
  16. //==================
  17. void main(void)
  18. {
  19.    uchar out;
  20.    out=S(100,50);
  21.    while(1)
  22.    {
  23.   D=1;
  24. P0=SEG7[out/100];
  25. D=0;
  26. P0=0xff;
  27. V=1;
  28. P0=0xfe;
  29. V=0;
  30. delay(1);
  31.   D=1;
  32. P0=SEG7[(out%100)/10];
  33. D=0;
  34. P0=0xff;
  35. V=1;
  36. P0=0xfd;
  37. V=0;
  38. delay(1);
  39.   D=1;
  40. P0=SEG7[out%10];
  41. D=0;
  42. P0=0xff;
  43. V=1;
  44. P0=0xfb;
  45. V=0;
  46. delay(1);
  47.   }
  48. }
復(fù)制代碼







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