收藏 分销(赏)

用0802液晶屏做頻率計.doc

上传人:pc****0 文档编号:7813242 上传时间:2025-01-18 格式:DOC 页数:5 大小:23KB 下载积分:10 金币
下载 相关 举报
用0802液晶屏做頻率計.doc_第1页
第1页 / 共5页
用0802液晶屏做頻率計.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
/* MCU Xtal Freq. 12.000MHz */ /* Contains 0802 LCM Driver */ /* 1 Second Gate */ #include #include #define LCD_RS P3_0 /* Switch Register: Command/Data */ #define LCD_RW P3_1 /* Switch Mode:!Write/Read */ #define LCD_EN P3_4 /* LCD Operation Enable */ #define LCD_DATA P1 #define LCD_CLEAR 0x01 #define MAX_X 0x10 /* Defines How Many LTR Can Be Disp.In a Row. */ #define MAX_Y 0x02 /* Defines How Many LTR Can Be Disp.In a Line. */ #define uchar unsigned char #define uint unsigned int /* The Declaration of Some Functions about LCD Driver */ void Delay5ms(void); void Delay400ms(void); void LCD_WrtCmd(uchar Command, Busy_C); void Init_LCD(void); uchar Get_LCD_Status(void); void LCD_WrtData(uchar Data); void Putcharxy(uchar x,uchar y,unsigned disp_data); void Outtextxy(uchar x,uchar y,uchar *disp_data); /* For Counter */ uchar timer0_count = 0, timer1_count = 0; uchar temp1, temp2, temp3; uchar tag = 0; /* Timer0 */ void timer0() interrupt 1 using 1 { timer0_count ++; if (timer0_count==16) { EA = 0; tag = 1; TR1 = 0; TR0 = 0; temp1=timer1_count; temp2=TH1; temp3=TL1; TH0=189; TL0=208; timer1_count=0; TH1=0; TL1=0; TR0=1; TR1=1; EA=1; timer0_count=0; } } void timer1() interrupt 3 using 2 { timer1_count ++; } /* Main Function */ void main(void) { unsigned long count; uchar freq[9]; unsigned long res; uchar i; Delay400ms(); Init_LCD(); Outtextxy(0,0,"HAM FREQ"); Outtextxy(0,1,"COUNTER!"); for(i=5;i>0;i--) Delay400ms(); TMOD = 0X51; //TMR1 external input: 0x51 IE = 0X8A; IP = 0X08; //Timer1 piority higher than timer0 TH0= 189; TL0= 208; TH1 = 0; TL1 = 0; TR0 = 1; //start TMR0 here TR1 = 1; while(1) { if(tag){ count = temp1 * 65536; count = count + temp2*256; count = count + temp3; res=100000; for(i=0;i<8;i++) { if(i==2) continue; if(i==6) continue; freq=count/res+'0'; count%=res; res/=10; } freq[2]=','; freq[6]='.'; freq[8]='\0'; Outtextxy(0,0,"Freq:kHz"); Outtextxy(0,1,freq); } } } void Init_LCD(void) { LCD_DATA=0; LCD_WrtCmd(0x38,0); /* Two Lines, 5x7 Font Style, No Cursors, No Blink */ Delay5ms(); LCD_WrtCmd(0x38,0); Delay5ms(); LCD_WrtCmd(0x38,0); Delay5ms(); LCD_WrtCmd(0x38,1); LCD_WrtCmd(0x80,1); LCD_WrtCmd(LCD_CLEAR,1); LCD_WrtCmd(0x06,1); LCD_WrtCmd(0x0c,1); } uchar Get_LCD_Status(void) { LCD_DATA=0xff; LCD_EN=0; LCD_EN=0; LCD_RW=1; LCD_RS=0; LCD_EN=1; while(LCD_DATA & 0x80); LCD_EN=0; return LCD_DATA; } void LCD_WrtData(uchar Data) { LCD_EN=0; Get_LCD_Status(); LCD_DATA=Data; LCD_RS=1; LCD_RW=0; LCD_EN=0; LCD_EN=0; LCD_EN=1; LCD_EN=1; LCD_EN=0; } void LCD_WrtCmd(uchar Command, Busy_C) { LCD_EN=0; if(Busy_C) Get_LCD_Status(); LCD_DATA=Command; LCD_RS=0; LCD_RW=0; LCD_EN=0; LCD_EN=0; LCD_EN=1; LCD_EN=1; LCD_EN=0; } void Putcharxy(uchar x,uchar y,unsigned disp_data) { y=y&(MAX_Y-1); x=x&(MAX_X-1); if(y) x+=0x40; x+=0x80; LCD_WrtCmd(x,1); LCD_WrtData(disp_data); } void Outtextxy(uchar x,uchar y,uchar *disp_data) { uchar char_length,j; char_length=strlen(disp_data); y=y&(MAX_Y-1); x=x&(MAX_X-1); for (j=0;j<CHAR_LENGTH;J++) { Putcharxy(x,y,disp_data[j]); x++; } } void Delay5ms(void) { uint i=6025;while(i--); } void Delay400ms(void) { uchar i=5; uint j; while(i--) { j=7888; while(j--); } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服