我通过c51单片机计算出外加方波信号的频率,但是不知道如何将这个整形变量显示到液晶上,显示字符串倒还是可以。请问该如何修改程序啊。 我的程序如下: #include <at89x51.h> #include <stdlib.h>
#define uchar unsigned char unsigned long fre; unsigned int k=0; unsigned char ff; unsigned int cx; unsigned int start;
sbit rs=P2^7; sbit rw=P2^6; sbit e=P2^5;
delay(uchar time) { while(time--); }
enrw() { rs=0; rw=0; e=0; delay(250); e=1; }
write_data(uchar c) { P0=c; rs=1; rw=0; e=0; delay(250); e=1; }
init_lcd(void) { P0=0x01; enrw(); P0=0x38; enrw(); P0=0x0F; enrw(); P0=0x06; enrw(); }
write_cmd(uchar m) { P0=m; enrw(); }
position(uchar row,uchar column) { uchar p; if(row==1) p=0x80+column-1; else p=0xC0+column-1; write_cmd(p); }
display_char(uchar *s) { write_data(*s); }
display_string(uchar *n) { for(;*n!='\0';n++) write_data(*n); }
void Timer01Init(void) { TMOD=(TMOD&0xf0)|0x01; //T0工作于定时方式1 TMOD=(TMOD&0x0f)|0x51; //T1工作于记数方式1 TL1=0; TH1=0; TL0=-46080; //T0定时60ms TH0=-46080>>8; ET0=1; TR0=1; ET1=1; TR1=1; EA=1; }
void Timer0Interrupt(void) interrupt 1 { unsigned int count; EA=0; TR0=0; TR1=0; TL0=-46080; //T0定时50ms TH0=-46080>>8; count=65536*k+TH1*256+TL1; fre=count*20; k=0; start=1; //display_string(fre); TL0=-46080; //T0定时50ms TH0=-46080>>8; TL1=0; TH1=0; TR1=1; TR0=1; EA=1; }
void Timer1Interrupt(void) interrupt 3 { TH1=0; TL1=0; k++; }
main() { unsigned int *m; Timer01Init(); init_lcd(); position(1,3); display_char("x"); display_char("f"); position(2,3); display_string("11"); while(start==0); if(fre==2000) { cx=1; display_string("cx1"); } else { cx=0; display_string("cx0"); } while(fre/10>=1) { m="d"; fre/=10; display_char(m); } while(1); } |