標(biāo)題: 89s52定時(shí)器怎么不行 [打印本頁(yè)]

作者: hanwu1206    時(shí)間: 2012-2-24 22:33
標(biāo)題: 89s52定時(shí)器怎么不行

我想用定時(shí)器定時(shí)數(shù)碼管每隔1s顯示0——9

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar a,s1;
uchar code s[10]={0xc0,0xf9,0xa4,0xb0,
     0x99,0x92,0x82,0xf8,
       0x80,0x90,};


void main(){
 TMOD=0x05;
 EA=1;
 ET0=1;
 TR0=1;
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
  if(a==20){  
  a=0;
  P2=0xfe;
  for(s1=0;s1<10;s1++) {
   P0=s[s1];
  s1=s1++; 
  if(s1==10)
  s1=0;
}} } 

void dsq() interrupt 1{
  a=a++;  }
 
  
  

 

  

 


作者: chalcegood    時(shí)間: 2012-2-26 12:17

1.你的是使用定時(shí)器計(jì)數(shù)方式,最好是改成中斷方式;

2.中斷程序中應(yīng)當(dāng)重裝初值;

3.判斷是不是到了一秒的時(shí)間的程序最好也放到中斷程序里;

4.主程序進(jìn)行顯示,建議用個(gè)while語(yǔ)句就行。






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