欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1581|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

簡(jiǎn)易直流電壓表程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:539093 發(fā)表于 2019-5-15 19:32 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar LCD[6];   //電壓數(shù)據(jù)轉(zhuǎn)換成LCD1602液晶字符顯示
uint Volt;
sbit DO  = P1^0;        //時(shí)鐘
sbit CS  = P1^1;        //片選
sbit CLK = P1^2;        //數(shù)據(jù)輸出
sbit RS = P2^0;                        //1602液晶數(shù)據(jù)/命令選擇端
sbit RW = P2^1;                        //1602液晶讀寫(xiě)端
sbit E  = P2^2;                        //1602液晶使能端

// Function Prototypes
void check_busy(void);
void write_command(uchar com);
void write_date(uchar date);
void LCD_init(void);
void string(uchar ad ,uchar *s);
//void lcd_test(void);
void delay(uint);
void Volt_To_LCD1602(void);
void delay_ms(uint xms);
void Data_Conversion(void);
uchar TLC549_ADC(void);
/*******************************************
    LCD1602 Driver mapped as IO peripheral
*******************************************/  
// Delay
// Delay
void delay(uint j)
{
        uchar i = 60;
  for(; j>0; j--)
  {
                while(--i);
    i = 59;
    while(--i);
    i = 60;
  }
}

// Test the Busy bit
void check_busy(void)
{
        do
  {
                P0 = 0xff;
    E = 0;
    RS = 0;
    RW = 1;
    E = 1;
    _nop_();
  } while(P0 & 0x80);
  E = 0;
}

// Write a command
void write_command(uchar com)
{
        check_busy();
  E = 0;
  RS = 0;
  RW = 0;
  P0 = com;
  E = 1;
  _nop_();
  E = 0;
  delay(1);
}

// Write Data
void write_date(uchar date)
{
        check_busy();
  E = 0;
  RS = 1;
  RW = 0;
  P0 = date;
  E = 1;
  _nop_();
  E = 0;
  delay(1);   
}

// Initialize LCD controller
void LCD_init(void)
{
        write_command(0x38); // 8-bits, 2 lines, 7x5 dots
  write_command(0x0C); // no cursor, no blink, enable display
  write_command(0x06); // auto-increment on
  write_command(0x01); // clear screen
  delay(1);
}

// Display a string
void string(uchar ad, uchar *s)
{
        write_command(ad);
  while(*s>0)
  {
                 write_date(*s++);
     delay(100);
  }
}
//****************************************************//
//函數(shù)名:delay_ms(uint xms)
//函數(shù)功能:ms級(jí)延時(shí)函數(shù)
//***************************************************//

void delay_ms(uint xms)
{
        uint x,y;
        for(x=xms;x>0;x--)
                for(y=110;y>0;y--);

}

//***************************************************//
//函數(shù)名稱(chēng):TLC549_ADC()
//函數(shù)功能:讀取上一次A/D轉(zhuǎn)換的數(shù)據(jù),啟動(dòng)下一次A/D轉(zhuǎn)換
//**************************************************//
uchar TLC549_ADC(void)
{
        uchar n, tmp;

        CS  = 1;                     //CS置高,片選無(wú)效
        CLK = 0;

        CS  = 0;                     //CS置低,片選有效,同時(shí)DO輸出高位
        _nop_();
        _nop_();                     //適當(dāng)延遲時(shí)間1.4us Setup Time

        for(n = 0; n < 8; n++) //串行數(shù)據(jù)移位輸入
        {
                tmp <<= 1;
                tmp |=  DO;

                CLK = 1;        //0.4us
                _nop_();          //CLK transition time Max 0.1us
                CLK = 0;        //0.4us
        }
        CS = 1;            //CS置高,片選無(wú)效
        for(n = 17; n != 0; n--) _nop_();  //Next Coversion需要延遲17us
        return (tmp);
}
//****************************************//
//函數(shù)名稱(chēng)ata_Conversion()
//函數(shù)功能:電壓換算
//*****************************************//
void Data_Conversion(void)
{
        uchar AD_Data;

        AD_Data = TLC549_ADC();
        delay_ms(1000);
        Volt = 5.0 / 256 * AD_Data*1000;
}

void Volt_To_LCD1602(void)
{
        Data_Conversion();                     //電壓換算并放大1000倍
        LCD[0] = Volt/1000;         //千位
        LCD[1] = '.';                                //小數(shù)點(diǎn)
        LCD[2] = Volt/100%10;  //百位
        LCD[3] = Volt/10%10;    //十位
        LCD[4] = Volt%10;           //個(gè)位
        LCD[5] = 'V';                              //字符V

        write_command(0x80+8);
        write_date(0x30+LCD[0]);
        write_date(LCD[1]);
        write_date(0x30+LCD[2]);
        write_date(0x30+LCD[3]);
        write_date(0x30+LCD[4]);
        write_date(LCD[5]);

}

int main()
{
        //uint m;
        LCD_init();

  delay(100);
  write_command(0x01);
        write_command(0x80);
        string(0x80,"Voltage:");
        delay_ms(2000);



        while(1)
        {
                Volt_To_LCD1602();

        }

}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:1 發(fā)表于 2019-5-15 23:09 | 只看該作者
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說(shuō)明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表