找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1743|回复: 1
打印 上一主题 下一主题
收起左侧

简易的数字电压表 程序+仿真+hex

[复制链接]
跳转到指定楼层
楼主
ID:636516 发表于 2019-12-11 11:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<reg51.h>
unsigned char dispbuf[4];
unsigned int getdata;
unsigned long temp;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
sbit A0=P3^4;
sbit B0=P3^5;
sbit C0=P3^6;
sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_E=P1^2;
#define LCD_DATA P2
unsigned char LcdBuf1[]={"voltmeter"};
unsigned char LcdBuf2[]={"Voltage:0.00V"};
void delay(unsigned int time)
{
while(time--);
}
void LCD_EN(void)
{
LCD_E=1;
delay(100);
LCD_E=0;
}
void WriteCommandLcd(unsigned char command)
{
LCD_RS=0;
LCD_RW=0;
LCD_DATA=command;
LCD_EN();
}
void display_xy(unsigned char x,unsigned char y)
{
if(y==1)
x+=0x40;
x+=0x80;
WriteCommandLcd(x);
}
void lcd_init(void)
{
WriteCommandLcd(0x38);
WriteCommandLcd(0x08);
WriteCommandLcd(0x01);
WriteCommandLcd(0x06);
WriteCommandLcd(0x0c);
}
void WriteDataLcd(unsigned char wdata)
{
LCD_RS=1;
LCD_RW=0;
LCD_DATA=wdata;
LCD_EN();
}
void display_string(unsigned char x,unsigned char y,unsigned char *s)
{
display_xy(x,y);
while(*s)
{
  WriteDataLcd(*s);
  s++;
}
}
void display_char(unsigned char x,unsigned char y,unsigned char dat)
{
display_xy(x,y);
WriteDataLcd(dat);
}
void TimeInitial(void)
{
TMOD=0x10;
TH1=(65536-200)/256;
TL1=(65536-200)%256;
EA=1;
ET1=1;
TR1=1;
}
void passageway(void)
{
A0=1;
B0=1;
C0=0;
}
void start(void)
{
ST=0;
OE=0;
ST=1;
ST=0;
}
void read_dat(void)
{
OE=1;
getdata=P0;
OE=0;
}
void dat_change(void)
{
unsigned int voltage_val;
temp=getdata*1.0/255*500;
dispbuf[0]=temp%1000%100%10;
dispbuf[1]=temp%1000%100/10;
dispbuf[2]=temp%1000/100;
dispbuf[3]=temp/1000;
LcdBuf2[10]=dispbuf[2]+0x30;
LcdBuf2[11]='.';
LcdBuf2[12]=dispbuf[1]+0x30;
LcdBuf2[13]=dispbuf[0]+0x30;
}
main()
{
TimeInitial();
lcd_init();
display_string(3,0,LcdBuf1);
while(1)
{
  passageway();
  start();
  while(EOC==0);
  read_dat();
  dat_change();
  display_string(0,1,LcdBuf2);
}
}
void T1_int(void) interrupt 3 using 0
{
TH1=(65536-200)/256;
TL1=(65536-200)%256;
CLK=~CLK;
}
    数字电压表仿真+hex.zip (21.24 KB, 下载次数: 37)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:677031 发表于 2019-12-30 13:01 | 只看该作者
根本开不了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表