0804_serial port
其实这个程序总的来说是有问题的
仿真图:

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的更多相关文章
- 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 | ...
- 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 ...
- Altium Designer 的entry sheet ,offsheet和port作用(转载)
1.图纸结构 图纸包括两种结构关系: 一种是层次式图纸,该连接关系是纵向的,也就是某一层次的图纸只能和相邻的上级或下级有关系: 另一种是扁平式图纸,该连接关系是横向的,任何两张图纸之间都可以建立信号连 ...
- gen_server port 调用receive_match 问题
问题由来 前些天对系统做了一个优化,将原来从queue 轮询刷出数据后每条消息一个 spawn 进程单独处理,修改为批量刷出.一条一条刷轮询刷 queue 存在问题:刷queue 进程太多时,占用CP ...
- 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 ...
- Serial Port Programming using Win32 API(转载)
In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...
- 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 ...
- WCF service 获取 client 端的 IP 和 port (转)
转帖记录一下,以便日后使用. 主要使用是.NET3.5里的服务端上下文的消息实例的RemoteEndpointMessageProperty属性,获取客户端地址信息.但是限制 的绑定是HTTP.TCP ...
- Could not open Selected VM debug port (8700) (转)
Could not open Selected VM debug port (8700) 2014年11月14日 ⁄ 综合 ⁄ 共 446字 ⁄ 字号 小 中 大 ⁄ 评论关闭 在运行项目的时候, ...
随机推荐
- U - Obtain a Permutation CodeForces - 1294E 思维
题解: 注意每一列与每一列之间互不影响,所以贪心地求出没一列的最小操作值,然后累加起来. 怎么求没一列的最小值呢?维护一个数组same表示其中same[i]=j表示将该序列向上翻滚i次有j个元素归位, ...
- ExceptionInChainedOperatorException:flink写hbase对于null数据导致数据导致出现异常
使用的flink版本:1.9.1 异常描述 需求: 从kafka读取一条数据流 经过filter初次筛选符合要求的数据 然后通过map进行一次条件判断再解析.这个这个过程中可能返回null或目标输出o ...
- Laravel中使用JWT
Laravel 版本: Laravel Framework 6.18.3 查看版本命令: php artisan -V 1.安装JWT扩展包: composer require tymon/jwt-a ...
- 一口气带你踩完五个 List 的大坑,真的是处处坑啊!
List 可谓是我们经常使用的集合类之一,几乎所有业务代码都离不开 List.既然天天在用,那就没准就会踩中这几个 List 常见坑. 今天我们就来总结这些常见的坑在哪里,捞自己一手,防止后续同学再继 ...
- 详解JS闭包概念
闭包理解 1. 如何产生闭包? *当一个嵌套的内部(子)函数引用了嵌套的外部(父)函数的变量(函数)时,产生闭包 2. 闭包到底是什么? * 使用Chrome调试查看 * 理解一 ...
- bytectf2019 boring_code的知识学习&&无参数函数执行&&上海市大学生CTF_boring_code+
参赛感悟 第三次还是第二次参加这种CTF大赛了,感悟和学习也是蛮多的,越发感觉跟大佬的差距明显,但是还是要努力啊,都大三了,也希望出点成绩.比赛中一道WEB都没做出来,唯一有点思路的只有EZCMS,通 ...
- PHP文件包含漏洞(利用phpinfo)复现
0x01 简介 PHP文件包含漏洞中,如果找不到可以包含的文件,我们可以通过包含临时文件的方法来getshell.因为临时文件名是随机的,如果目标网站上存在phpinfo,则可以通过phpinfo来获 ...
- shiro:集成Spring(四)
基于[加密及密码比对器(三)]项目改造 引入相关依赖环境 shiro-spring已经包含 shiro-core和shiro-web 所以这两个依赖可以删掉 <!--shiro继承spring依 ...
- Springboot:属性常量赋值以及yml配置文件语法(四)
方式一: 注解赋值 构建javaBean:com\springboot\vo\Dog 1:@Component:注册bean到spring容器中 2:添加get set toString方法 3:使用 ...
- node 搭载本地代理,处理web本地开发跨域问题
var path = require('path') var httpProxy = require('http-proxy') var express = require('express') va ...