[PIC®/AVR®/dsPIC®产品] 功夫不负有心人,找到了一些官方的8051例子

[复制链接]
 楼主| xixi2017 发表于 2023-8-16 15:30 | 显示全部楼层 |阅读模式
https://www.keil.com/download/list/c51.htm

这些都是针对AT89系列51单片机的。非常棒的入门资料。
以前Atmel官网有很多,现在官网被合并了,已经找不到代码文件了,只有PDF的了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| xixi2017 发表于 2023-8-16 15:32 | 显示全部楼层
  1. /*---------------------------------------------------------
  2. ---------------------------------------------------------*/
  3. #include <reg52.h>
  4. #include <stdio.h>

  5. /*---------------------------------------------------------
  6. Timer 0 Overflow Interrupt
  7. ---------------------------------------------------------*/
  8. unsigned int T0_ISR_count = 0;

  9. void T0_ISR (void) interrupt 1
  10. {
  11. T0_ISR_count++;
  12. TF0 = 0;                        // Reset the interrupt request
  13. }


  14. /*---------------------------------------------------------
  15. MAIN C function
  16. ---------------------------------------------------------*/
  17. void main (void)
  18. {
  19. /*--------------------------------------
  20. Set serial port for 9600 baud at
  21. 11.0592 MHz.  Note that we use Timer 1
  22. for the baud rate generator.
  23. --------------------------------------*/
  24. SCON  = 0x50;
  25. TMOD |= 0x20;
  26. TH1   = 0xFA;
  27. TR1   = 1;
  28. TI    = 1;
  29. PCON |= 0x80;

  30. printf ("\nPulse Width Example Program\n\n");

  31. /*--------------------------------------
  32. Enable interrupts for timer 0.
  33. --------------------------------------*/
  34. ET0 = 1;
  35. EA = 1;

  36. /*--------------------------------------
  37. Set Timer0 for 16-bit interval timer
  38. mode.
  39. --------------------------------------*/
  40. TMOD = (TMOD & 0xF0) | 0x09;

  41. while (1)
  42.   {
  43. /*--------------------------------------
  44. Clear the timer overflow counter and
  45. the timer low and high registers.  Then,
  46. start the timer.
  47. --------------------------------------*/
  48.   T0_ISR_count = 0;
  49.   TH0 = 0;
  50.   TL0 = 0;

  51.   TR0 = 1;

  52.   printf ("\nStart a pulse.\n");

  53. /*--------------------------------------
  54. Wait for the pulse to start.
  55. Then, wait for the pulse to end.
  56. --------------------------------------*/
  57.   while (!INT0);
  58.   while (INT0);

  59. /*--------------------------------------
  60. Compute the width of the pulse -- one
  61. clock cycle is 1us for a standard 8051
  62. and display it.
  63. --------------------------------------*/
  64.   printf ("The width pulse is: %ld uSec\n",
  65.           (unsigned long)((TH0 << 8) | TL0 | ((unsigned long)T0_ISR_count << 16)));
  66.   }
  67. }

  68. /*---------------------------------------------------------
  69. ---------------------------------------------------------*/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

144

主题

2006

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

144

主题

2006

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部