其实这个程序总的来说是有问题的

仿真图:

MacroAndConst.h

#ifndef _MACRO_AND_CONST_H_
#define _MACRO_AND_CONST_H_

typedef unsigned int uint16;
typedef unsigned int UINT;
typedef unsigned int uint;
typedef unsigned int UINT16;
typedef unsigned int WORD;
typedef unsigned int word;
typedef int int16;
typedef int INT16;
typedef unsigned long uint32;

typedef unsigned long UINT32;
typedef unsigned long DWORD;
typedef unsigned long dword;
typedef long int32;
typedef long INT32;
typedef signed char int8;
typedef signed char INT8;
typedef unsigned char byte;
typedef unsigned char BYTE;
typedef unsigned char uchar;
typedef unsigned char UINT8;
typedef unsigned char uint8;
typedef unsigned char BOOL;

#endif

led.h

#ifndef _LED_H_
#define _LED_H_

//typedef P0 Seg;
//typedef P2 Bit;
extern void display(uint db);

#endif

led.c

#include <reg52.h>
#include "MacroAndConst.h"
//#include "delay.h"
#include "time.h"

/*---------共阴极0~f数码管编码 ----------*/
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/*****typedef int int16; 有符号的******/
static int16 LedTimeCount1=0; //LED计数器
static int16 LedTimeCount2=0;
static int16 LedTimeCount3=0;
static int16 LedTimeCount4=0;

void display(uint db) //数码管显示函数,用于显示模数转换后得到的数字量
{
uchar bw,sw,gw; //bw,sw,gw分别等于db百位,十位,个位上的数
db=db*100/51;
bw=db/100;
sw=db%100/10;
gw=db%10;

P2=0xfe; //点亮第一只数码管
P0=table[bw]|0x80; //最高位置0,点亮第一只数码管的小数点.

if(Time500us)
{
/*
Time500us=0;
LedTimeCount1++;
LedTimeCount2++;
LedTimeCount3++;
LedTimeCount4++;
if(LedTimeCount1>=4)
{
LedTimeCount1=-16;//LED计数器复位
//delay(5);
P2=0xfd; //点亮第二只数码管
P0=table[sw];
}
if(LedTimeCount2>=8)
{
LedTimeCount2=-16;
//delay(5);
P2=0xfb; //点亮第三只数码管
P0=table[gw];
}
if(LedTimeCount3>=12)
{
LedTimeCount3=-16;
//delay(5);
P2=0xf7; //点亮第四只数码管
P0=table[0]; //第四只数码管一直显示0
}
if(LedTimeCount4>=16)
{
LedTimeCount1=0;
LedTimeCount2=0;
LedTimeCount3=0;
LedTimeCount4=0;
//delay(5);
}
*/

Time500us=0;
LedTimeCount1++;
LedTimeCount2++;
LedTimeCount3++;
LedTimeCount4++;
if(LedTimeCount1>=4)
{
LedTimeCount1=0;//LED计数器复位
//delay(5);
P2=0xfd; //点亮第二只数码管
P0=table[sw];
if(LedTimeCount2>=8)
{
LedTimeCount2=0;
//delay(5);
P2=0xfb; //点亮第三只数码管
P0=table[gw];
if(LedTimeCount3>=12)
{
LedTimeCount3=0;
//delay(5);
P2=0xf7; //点亮第四只数码管
P0=table[0]; //第四只数码管一直显示0
if(LedTimeCount4>=16)
{
LedTimeCount4=0;
//delay(5);
}
}
}
}
}
}

time.h

#ifndef _TIME_H_
#define _TIME_H_

extern void Timer0Init(void);
extern bit Time500us;

#endif

time.c

#include <reg52.h>

bit Time500us = 0 ; // 500us时间片

/**********定时器初始化*******************/
void Timer0Init(void)
{
TMOD= 0x01;//定时器 0 工作方式 1
TH0 = 0xfe ; //定时器初始值500us
TL0 = 0x33 ;
TR0 = 1 ;
ET0 = 1 ;
EA = 1 ; //中断允许总控制位
}

void Time0Isr(void) interrupt 1
{
TH0 = 0xfe ; //500us
TL0 = 0x33 ;
Time500us = 1 ; //500uS 时标标志位置位
}

main.c

#include<reg52.h>
#include <intrins.h>
#include "macroandconst.h"
#include "led.h"
//#include "delay.h"
#include "time.h"

sbit wr=P3^6;
sbit rd=P3^7;
static uint16 TimeCount = 0 ; //计数器 typedef int int16; 有符号的

void main(void)
{
uchar i;
Timer0Init();
while(1)
{
wr=0; //在片选信号CS为低电平情况下(由于CS接地,所以始终为低电平),
_nop_(); //WR由低电平到高电平时,即上升沿时,AD开始采样转换
wr=1;
if(Time500us)
{ // delay(1); //延时1ms,等待采样转换结束,延时函数 delay(1)延时0.992ms,大约为1ms
// P1=0xff; //这条语句不能少,我也还不知道为什么
Time500us=0; //
TimeCount++;
if(TimeCount>=2)
{
TimeCount=0; //计数器复位

rd=0; //将RD脚置低电平后,再延时大于135ns左右(这里延时1us),
_nop_(); //即可从DB脚读出有效的采样结果,传送到P1口
for(i=0;i<10;i++) //刷新显示一段时间
display(P1); //显示从DB得到的数字量
}
}
}
}

0804_serial port的更多相关文章

  1. Exception thrown by the agent : java.rmi.server.ExportException: Port already in use

    今天有个应用一直起不来,感觉配置都对啊,奇了怪了.看日志发现如下: STATUS | wrapper | 2017/01/04 08:09:31 | Launching a JVM...INFO | ...

  2. IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551): java.net.SocketException

    学习Java Servlet时,从Wrox上下载了示例代码,准备run/debug时发现以下错误: Error running Tomcat 8.5.8: Unable to open debugge ...

  3. Altium Designer 的entry sheet ,offsheet和port作用(转载)

    1.图纸结构 图纸包括两种结构关系: 一种是层次式图纸,该连接关系是纵向的,也就是某一层次的图纸只能和相邻的上级或下级有关系: 另一种是扁平式图纸,该连接关系是横向的,任何两张图纸之间都可以建立信号连 ...

  4. gen_server port 调用receive_match 问题

    问题由来 前些天对系统做了一个优化,将原来从queue 轮询刷出数据后每条消息一个 spawn 进程单独处理,修改为批量刷出.一条一条刷轮询刷 queue 存在问题:刷queue 进程太多时,占用CP ...

  5. Serial Port Programming on Linux(转载)

    This is a tutorial on how to program the Serial Ports on your Linux box.Serial Ports are nice little ...

  6. Serial Port Programming using Win32 API(转载)

    In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...

  7. FTP Service mode : PORT & PASV

    PORT Mode: 1. FTP client use TCP port 1026 for command to FTP server command port 212. FTP server us ...

  8. WCF service 获取 client 端的 IP 和 port (转)

    转帖记录一下,以便日后使用. 主要使用是.NET3.5里的服务端上下文的消息实例的RemoteEndpointMessageProperty属性,获取客户端地址信息.但是限制 的绑定是HTTP.TCP ...

  9. Could not open Selected VM debug port (8700) (转)

    Could not open Selected VM debug port (8700) 2014年11月14日 ⁄ 综合 ⁄ 共 446字 ⁄ 字号 小 中 大 ⁄ 评论关闭   在运行项目的时候, ...

随机推荐

  1. E - Travel by Car

    连接https://atcoder.jp/contests/abc143/tasks/abc143_e 题目大意: 在一个无向图中,当前的油量为L,给出q个问题,判断从a到b需要多少加几次油,路上每个 ...

  2. [XML] XML格式【有道翻译】API 的数据转化输出

    <?php header("content-type:text/html;charset=utf-8"); //echo "飞飞仔超级智障"; $cont ...

  3. TensorFlow keras中一些著名的神经网络

  4. GraphicsLab Project 之 Curl Noise

    作者:i_dovelemon 日期:2020-04-25 主题:Perlin Noise, Curl Noise, Finite Difference Method 引言 最近在研究流体效果相关的模拟 ...

  5. ubuntu17.10安装lnmp安装包的核心问题-gcc版本、g++版本

    大致碰到的问题都是这样,不是php安装失败,就是MySQL安装失败,或者Nginx也安装失败 基本上是花式报错.后来在军哥的论坛中找到了这个帖子:https://bbs.vpser.net/viewt ...

  6. 手把手教你使用Python爬取西刺代理数据(下篇)

    /1 前言/ 前几天小编发布了手把手教你使用Python爬取西次代理数据(上篇),木有赶上车的小伙伴,可以戳进去看看.今天小编带大家进行网页结构的分析以及网页数据的提取,具体步骤如下. /2 首页分析 ...

  7. 理解分布式一致性:Paxos协议之Basic Paxos

    理解分布式一致性:Paxos协议之Basic Paxos 角色 Proposal Number & Agreed Value Basic Paxos Basic Paxos without f ...

  8. Shutdown SpringBoot App

    文章目录 Shutdown Endpoint close Application Context 退出SpringApplication 从外部程序kill App Shutdown SpringBo ...

  9. c语言-----劫持系统03

    1. 回顾 在前2节我们已经实现了劫持原理.函数指针等一些概念,下面进行系统劫持 2. 工具 vs2017 Detours 3. windows如何创建一个进程? (1)创建进程函数 CreatePr ...

  10. CloudCC CRM探讨:精细流程管理与员工悟性培养

    很多企业主招聘时更喜欢专业的销售,来给他们创造价值.老板不愿意花时间在"磨刀上",而喜欢员工一来就"砍柴".即使是建立培训机制,仍然很大程度依赖于员工自己的悟性 ...