lcd1602显示外部输入的脉冲频率
压缩包里有一个后缀为.pdsprj的文件 使用proteus打开 我的是8.6 这个就是仿真文件。
仿真图片有个叫仿真成功的.png的后缀文件。 所有proteus可keil工程文件都在这个压缩包里头。文件不多,一眼就看得出来 .uvproj后缀是keil工程文件
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg52.h>
- unsigned long int fre;
- unsigned char time;
- unsigned int count;
- unsigned int count1;
- sbit lcdrs=P2^0;
- sbit lcdrw=P2^1;
- sbit lcden=P2^2;
- #define lcddb P0
- unsigned char character[10]={0};
- unsigned char character_1[]={"fre= Hz"};
- unsigned char FLAG = 0;
- void LCD_init(void);
- void LCD_write_command(unsigned char command);
- void LCD_write_data(unsigned char dat);
- void LCD_disp_char(unsigned char x,unsigned char y,unsigned char dat);
- void delay_n40us(unsigned int n);
- void timer_init();
- void delay_n40us(unsigned int n)
- {
- unsigned int i;
- unsigned char j;
- for(i=n;i>0;i--)
- for(j=0;j<2;j++);
- }
- void delay_1s()
- {
- unsigned int i,j;
- for(i = 0;i<100;i++)
- for(j = 0;j<1000;j++);
- }
- void LCD_init(void)
- {
- LCD_write_command(0x38);
- LCD_write_command(0x38);
- LCD_write_command(0x38);
- LCD_write_command(0x0c);
- LCD_write_command(0x06);
- LCD_write_command(0x01);
- delay_n40us(100);
- }
- void LCD_write_command(unsigned char dat)
- {
- lcddb=dat;
- lcdrs=0;
- lcdrw=0;
- lcden=1;
- lcden=0;
- delay_n40us(1);
- }
- void LCD_write_data(unsigned char dat)
- {
- lcddb=dat;
- lcdrs=1;
- lcdrw=0;
- lcden=1;
- lcden=0;
- delay_n40us(1);
- }
- void LCD_disp_char(unsigned char x,unsigned char y,unsigned char dat)
- {
- unsigned char address;
- if(y==1)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- LCD_write_data(dat);
- }
- void LCD_disp_num(unsigned char x,unsigned char y,unsigned char dat)
- {
- unsigned char address;
- if(y==1)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- LCD_write_data(dat+48);
- }
- void dis_num(void)
- {
- unsigned char i=0,j=0,k=0;
- LCD_write_command(0x01);
- character[0] = fre/10000000;
- character[1] = fre/1000000%10;
- character[2] = fre/100000%10;
- character[3] = fre/10000%10;
- character[4] = fre/1000%10;
- character[5] = fre/100%10;
- character[6] = fre/10%10;
- character[7] = fre%10;
- character[8] = 'H';
- character[9] = 'z';
- for(i = 0;i<4;i++)
- {
- LCD_disp_char(i+0,1,character_1[i]);
- }
- for(i = 0;i<10;i++)
- {
- if(character[i]!=0)
- break;
- }
- k = 8-i;
- for(j = 0;j<k;j++)
- {
- LCD_disp_num(4+j,1,character[i++]);
- }
- for(i = 5;i<7;i++)
- {
- LCD_disp_char(j+4,1,character_1[i]);
- j++;
- }
- }
- void main()
- {
- unsigned char i;
- LCD_init();
- timer_init();
- for(i = 0;i<4;i++)
- {
- LCD_disp_char(i+0,1,character_1[i]);
- }
- while(1)
- {
- dis_num();
- delay_1s();
- }
- }
- void timer_init(void)
- {
- TMOD=0x66;
- TH0=0;
- TL0=0;
- TR0=1;
- ET0=1;
- TH1=0;
- TL1=0;
- TR1=1;
- ET1=1;
- RCAP2H=(65536-62500)/256;
- RCAP2L=(65536-62500)%256;
- TH2=RCAP2H;
- TL2=RCAP2L;
- ET2=1;
- TR2=1;
- EA=1;
- }
- void timer2(void) interrupt 5
- {
- time++;
- TF2=0;
- if (time==16)
- {
- time=0;
- EA=0;
- fre=(long)count1*256+TL1;
- FLAG = 0;
-
- if(fre<2000)
- {
- fre = (long)count*256+TL0;
- FLAG = 1;
- }
- if(!FLAG)
- {
- fre = fre *100;
- }
- TL0=0;
- TH0=0;
- TL1=0;
- TH1=0;
- count=0;
- count1=0;
- EA=1;
- }
- }
- void timer0(void) interrupt 1
- {
- count++;
- }
- void timer1(void) interrupt 3
- {
- count1++;
- }
复制代码
所有资料51hei提供下载:
数字频率计设计(余浩东1710720049).zip
(204.74 KB, 下载次数: 35)
|