標(biāo)題: 基于51單片機(jī)的頻率計(jì),親測能用 [打印本頁]

作者: 1508104726    時(shí)間: 2019-1-19 09:21
標(biāo)題: 基于51單片機(jī)的頻率計(jì),親測能用
#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int
sbit rw=P2^5;//一下三行是設(shè)置lcd1602的使能端
sbit rs=P2^6;
sbit ep=P2^7;
typedef bit BOOL;
uchar t,A1,A2,A3,A4,A5,A6,Flag=0,count,H,L;
void delay(uchar ms) //延時(shí)
{
  uchar i;
  while(ms--)                       
  for(i=0;i<100;i++);
}
BOOL lcd_bz()//測試lcd忙碌狀態(tài)返回值為布爾型數(shù)值真或假'1'.'0'  
{
  BOOL result;
  rs=0;           // 讀忙信號
  rw=1;
  ep=1;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  result=(BOOL)(P0&0x80);
  ep=0;
  return(result) ;
}     
void write_cmd(uchar cmd)//寫指令
{
  while (lcd_bz());
  rs=0;
  rw=0;
  ep=0;
  _nop_();
  _nop_();
  P0=cmd ;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  ep=1;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  ep=0;
}
void write_addr(uchar addr)//寫地址
{
  write_cmd(addr|0x80);//LCD第一行的首地址為0x80第二行的首地址為0x80+0x40=0xc0
}
void write_byte(uchar dat) //寫字節(jié)
{
   while (lcd_bz());
  rs=1;
  rw=0;
  ep=0;
  _nop_();
  _nop_();
  P0=dat ;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  ep=1;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  ep=0;
}
void lcd_init() //lcd初始化

{

  write_cmd(0x38);//設(shè)置LCD兩行顯示一個(gè)數(shù)據(jù)由5*7點(diǎn)陣表示,數(shù)據(jù)由8跟線傳輸

  write_cmd(0x0c);//清除屏幕顯示

  write_cmd(0x06);//設(shè)定輸入方式增量不移位

  write_cmd(0x01);//開整體顯示關(guān)光標(biāo)不閃爍

}

void display(uchar addr,uchar q)//在某一地址上顯示內(nèi)容adder表示的是地址偏移量q表示顯示的字符或數(shù)字
{

  write_addr(addr);

  write_byte(q);

  delay(1);//修改此時(shí)間?梢愿淖僉CD上數(shù)值跳變的數(shù)度

}
void init()
{
        TMOD = 0x51;
        TH0 = (65535-45872)/256;
        TL0 = (65535-45872)%256;
        TH1 = 0x00;
        TL1 = 0x00;
        ET0 = 1;
        ET1 = 1;
        EA = 1;
        TR0 = 1;
        TR1 = 1;
}
void Time0() interrupt 1
{
        TL0 = 0x00;
        TH0 = 0x4c;
        t++;
        if (t == 20)
        {
                TR0 = 0;
                TR1 = 0;
                t = 0;
                Flag = 1;
        }
}
void Time1() interrupt 3
{
        count++;
}
void main()
{
                unsigned long x;
                P3 = 0xFF;
                init();
                lcd_init();
                while (1)
                {
                        if (Flag)
                        {
                                H = TH1;
                                L = TL1;
                                x = ((count*65535)+(H*256)+L);
                                A1=x/100000;
                                A2=x%100000/10000;
                                A3=x%10000/1000;
                                A4=x%1000/100;
                                A5=x%100/10;
                                A6=x%10;
                                Flag = 0;
                                count = 0;
                                TH1 = 0x00;
                                TL1 = 0x00;
                                TH0 = (65535-45872)/256;
                                TL0 = (65535-45872)%256;
                                TR1 = 1;
                                TR0 = 1;
                        }
                        display(0x00,A1+0x30);
                        display(0x01,A2+0x30);
                        display(0x02,A3+0x30);
                        display(0x03,A4+0x30);
                        display(0x04,A5+0x30);
                        display(0x05,A6+0x30);
                }
}


作者: admin    時(shí)間: 2019-1-19 13:45
補(bǔ)全原理圖或者詳細(xì)說明一下電路連接即可獲得100+黑幣
作者: 王秋冬    時(shí)間: 2019-2-13 11:40
期待樓主補(bǔ)全資料,謝謝。




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