標(biāo)題: 單片機(jī)0-99計(jì)秒器程序 [打印本頁]

作者: 0.0.    時(shí)間: 2019-6-24 18:52
標(biāo)題: 單片機(jī)0-99計(jì)秒器程序
這個(gè)程序非常簡單,用這個(gè)來發(fā)帖試試,如果有錯(cuò)誤的話請指正
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code segcode []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90} ; //定義段碼
  5. uchar code bitcode []={0xf7,0xfb};//定義位碼
  6. uchar dispbuf[2];
  7. uint count;
  8. void DelayMs (uint n)
  9. {
  10. uchar j;
  11. while (n--)
  12. {
  13. for (j=0;j<113;j++);
  14. }
  15. } //延時(shí)0.5秒
  16. void numtobuf(void)
  17. {
  18. dispbuf[1]=count/10%10;
  19. dispbuf[0]=count%10;
  20. }
  21. void buftoseg(void)
  22. {
  23. uchar i;
  24. for(i=0;i<2;i++)
  25. {
  26. P0=segcode[dispbuf[i]];
  27. P2=bitcode[i];
  28. DelayMs(1);
  29. }
  30. }
  31. void main (void)
  32. {
  33. uint k;
  34. while(1)
  35. {
  36. if(++k==220)
  37. {
  38. k=0;
  39. if(++count==100)count=0;
  40. }
  41. numtobuf();
  42. buftoseg();
  43. }
  44. }



復(fù)制代碼


0-99計(jì)秒器.zip

18.59 KB, 下載次數(shù): 3, 下載積分: 黑幣 -5






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