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

仿真图:

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. N - Aroma's Search CodeForces - 1293D math+greedy

    作为DIV2的D题来讲,这个题目不算难. 题目大意:再规定的时间内寻找宝藏,第i个宝藏的位置为a*x(i-1)+b,a*y(i-1)+b.然后给出初始位置xs,ys和时间t让求再时间t内能够寻找到多少 ...

  2. SpringCloud-Ribbon负载均衡机制、手写轮询算法

    Ribbon 内置的负载均衡规则 在 com.netflix.loadbalancer 包下有一个接口 IRule,它可以根据特定的算法从服务列表中选取一个要访问的服务,默认使用的是「轮询机制」 Ro ...

  3. PHP函数:memory_get_usage

    memory_get_usage()  -返回分配给 PHP 的内存量 说明: memory_get_usage ([ bool $real_usage = false ] ) : int 参数: r ...

  4. pytorch GPU训练好的模型使用CPU加载

    torch.load('tensors.pt') # 把所有的张量加载到CPU中 torch.load('tensors.pt', map_location=lambda storage, loc: ...

  5. Caused by: java.lang.NumberFormatException: For input string: " 60"

    原因 原原因:string转int 格式出错 解决:我的输入文件格式在根据“,”分割完之后多出了一个空格,我想要的是“60” 但是分割完之后是“ 60”所以导致格式转换不匹配.

  6. VideoView--简单的设置全屏幕播放

    我说的最主要的是要在布局哪里设置一下,如: <com.example.mypalyer.fullScreen          android:id="@+id/videoView1& ...

  7. 点击Qtableview表头,触发事件

    connect(horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onHeaderClicked(int))); refer to ...

  8. 日志分析工具ELK(三)

    目前官网更新特别快,不到半年时间就更新了好几个版本,目前最新的是5.1 以下安装配置使用4.5版本的 https://www.elastic.co/guide/en/kibana/4.5/index. ...

  9. Springboot以Tomcat为容器实现http重定向到https的两种方式

    1 简介 本文将介绍在Springboot中如何通过代码实现Http到Https的重定向,本文仅讲解Tomcat作为容器的情况,其它容器将在以后一一道来. 建议阅读之前的相关文章: (1) Sprin ...

  10. opencv-0-项目启程

    opencv-0-项目启程 opencvC++QT 开始 无数次说要开始 opencv 的系列, 但是都由于各种原因没有坚持下去, 这次我做最后一次尝试, 也做最后一次坚持, 如果不做下去, 我就再也 ...