Chinaunix首页 | 论坛 | 博客
  • 博客访问: 415130
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-11 12:17
个人简介

www.vibexie.com vibexie@qq.com

文章分类

全部博文(121)

文章存档

2015年(55)

2014年(66)

我的朋友

分类: C/C++

2014-03-29 12:27:05


点击(此处)折叠或打开

  1. #include<reg52.h>
  2. #define uint unsigned int

  3. uint num=0;

  4. int main()
  5. {
  6.     P1=0x00;
  7.     TMOD=0x01;//set the timer 0,to be the runing model of 0x01
  8.     TH0=(65535-45872)/256;//assign 45872 to the crystal oscillator of 11.0592MHz to count 50ms
  9.     TH1=(65535-45872)%256;

  10.     EA=1;//enable the the general interrupt    
  11.     ET0=1;//enable the interrupt of timer 0
  12.     TR0=1;//run timer 0
  13.     
  14.     while(1);

  15.     return 0;
  16. }

  17. void T0_timer() interrupt 1
  18. {
  19.     TH0=(65535-45872)/256;//assign 45872 to the crystal oscillator of 11.0592MHz to count 50ms again
  20.     TH1=(65535-45872)%256;

  21.     num++;
  22.     if(num==20)
  23.     {
  24.         num=0;
  25.         P1=~P1;
  26.     }
  27. }

阅读(1483) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~