不废话直接上程序了,大家帮忙看看还有什么大错小错,我明天去实验室测试下,做好这个还要做上机程序呢
谢谢指点
#include "regx51.h"
unsigned char h,r,i; unsigned char a,b,c,d; unsigned char code diaplay[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09};
long counter=0; //旋转编码器的脉冲计数值 void main() { TMOD=0x22; TH0=(65536-10000)/256; TL0=(65536-10000)%256; TR0=1; ET0=1; TH1=(65536-4000)/256; TL1=(65536-4000)%256; TR1=1; ET1=1; IT1 = 1; //外部中断1为边沿触发 EX1 = 1; //使能外部中断1 EA = 1; //使能中断 while(1) {if(P3_6==1) { P1_0=0; } else P1_1=0; a=r%10; b=(r/10)%10; c=(r/100)%10; d=(r/1000)%10;
} }
void int1() interrupt 1 { counter++; } void t0_() interrupt 2 using 1 { TH0=(65536-10000)/256; TL0=(65536-10000)%256; h++; if(h==100) { h=0; r=60*counter/500; }
} void t1_() interrupt 3 using 1 { TH1=(65536-4000)/256; TL1=(65536-4000)%256; if(i==0) {P2=display[d]; P0_3=0;} if(i==1) {P2=display[c]; P0_2=0;} if(i==2) {P2=display; P0_1=0;} if(i==3) {P2=display[a]; P0_2=0;} if(i==4) {i=0;} i++;
} |