标题: 四位数秒器陈序及电路图,有点简陋 [打印本页]

作者: 醉孤辰    时间: 2017-4-25 20:03
标题: 四位数秒器陈序及电路图,有点简陋


  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code SegCode[]=
  5. {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
  6. uchar code BitCode[]={0xfe,0xfd,0xfb,0xf7};
  7. uchar DispBuf[4];
  8. uint Count;
  9. void DelayMs(uchar n)
  10. {
  11. uchar j;
  12. while(n--)
  13. {
  14. for(j=0;j<113;j++);
  15. }}
  16. void NumToBuf(void)
  17. {
  18. DispBuf[3]=Count/1000;
  19. DispBuf[2]=Count/100%10;
  20. DispBuf[1]=Count/10%10;
  21. DispBuf[0]=Count%10;
  22. }
  23. void BufToSeg(void)
  24. {
  25. uchar i;
  26. for(i=0;i<4;i++)
  27. {
  28. P0=SegCode[DispBuf[i]];
  29. P2=BitCode[i];
  30. DelayMs(2);
  31. P2|=0x0F;
  32. }}
  33. void main(void)
  34. {
  35. uint k;
  36. while(1)
  37. {
  38. if(++k==220)
  39. {
  40. k=0;
  41. if(++Count==10000)Count=0;
  42. }
  43. NumToBuf();
  44. BufToSeg();
  45. }}
复制代码





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1